dumi 2.3.0-beta.8 → 2.3.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/compiled/crates/swc_plugin_react_demo.wasm +0 -0
- package/dist/assetParsers/block.d.ts +1 -0
- package/dist/assetParsers/block.js +7 -3
- package/dist/client/pages/Demo/index.js +12 -6
- package/dist/client/theme-api/DumiDemo/index.js +6 -3
- package/dist/client/theme-api/types.d.ts +14 -0
- package/dist/client/theme-api/useLiveDemo.js +94 -72
- package/dist/client/theme-api/useRenderer.d.ts +10 -3
- package/dist/client/theme-api/useRenderer.js +72 -39
- package/dist/client/theme-api/utils.d.ts +4 -3
- package/dist/client/theme-api/utils.js +36 -0
- package/dist/features/compile/index.js +3 -0
- package/dist/features/locales.js +4 -0
- package/dist/features/theme/index.js +22 -6
- package/dist/loaders/markdown/index.js +12 -3
- package/dist/loaders/markdown/transformer/index.d.ts +4 -1
- package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +1 -0
- package/dist/loaders/markdown/transformer/rehypeDemo.js +29 -10
- package/dist/loaders/markdown/transformer/rehypeEnhancedTag.js +12 -2
- package/dist/loaders/markdown/transformer/remarkContainer.js +37 -6
- package/dist/techStacks/utils.d.ts +22 -0
- package/dist/techStacks/utils.js +5 -0
- package/dist/types.d.ts +8 -1
- package/package.json +28 -25
- package/tech-stack-utils.d.ts +4 -2
- package/theme-default/builtins/API/index.d.ts +2 -1
- package/theme-default/builtins/API/index.js +173 -43
- package/theme-default/builtins/API/index.less +47 -0
- package/theme-default/builtins/CodeGroup/index.d.ts +3 -0
- package/theme-default/builtins/CodeGroup/index.js +29 -0
- package/theme-default/builtins/Previewer/index.js +1 -1
- package/theme-default/builtins/SourceCode/index.d.ts +3 -2
- package/theme-default/locales/en-US.json +4 -0
- package/theme-default/locales/zh-CN.json +4 -0
- package/theme-default/slots/ContentFooter/index.js +4 -2
- package/theme-default/slots/ContentFooter/index.less +5 -0
- package/theme-default/slots/PreviewerActions/index.d.ts +6 -1
- package/theme-default/slots/PreviewerActions/index.js +30 -13
- package/theme-default/slots/PreviewerActions/index.less +30 -140
- package/theme-default/slots/Tabs/index.d.ts +6 -0
- package/theme-default/slots/Tabs/index.js +11 -0
- package/theme-default/slots/Tabs/index.less +151 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ParserConfig } from '@swc/core';
|
|
2
|
+
import { IDumiTechStack } from '../types';
|
|
2
3
|
export { IDumiTechStack, IDumiTechStackOnBlockLoadArgs, IDumiTechStackOnBlockLoadResult, IDumiTechStackRuntimeOpts, } from '../types';
|
|
3
4
|
/**
|
|
4
5
|
* for frameworks like vue , we need to extract the JS fragments in their scripts
|
|
@@ -16,3 +17,24 @@ export interface IWrapDemoWithFnOptions {
|
|
|
16
17
|
* https://github.com/umijs/dumi/blob/master/crates/swc_plugin_react_demo/src/lib.rs#L126
|
|
17
18
|
*/
|
|
18
19
|
export declare function wrapDemoWithFn(code: string, opts: IWrapDemoWithFnOptions): string;
|
|
20
|
+
export type IDefineTechStackOptions = IDumiTechStack;
|
|
21
|
+
/**
|
|
22
|
+
* Define a tech stack
|
|
23
|
+
* @param options techstack options
|
|
24
|
+
* @returns function that returns {@link IDumiTechStack}, can be used to register a techstack
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const ReactTechStack = defineTechStack({
|
|
28
|
+
* name: 'jsx',
|
|
29
|
+
* isSupported(_, lang) {
|
|
30
|
+
* return ['jsx', 'tsx'].includes(lang);
|
|
31
|
+
* },
|
|
32
|
+
* transformCode() {
|
|
33
|
+
* // ...
|
|
34
|
+
* return '';
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* api.registerTechStack(() => ReactTechStack);
|
|
39
|
+
*/
|
|
40
|
+
export declare function defineTechStack(options: IDefineTechStackOptions): IDumiTechStack;
|
package/dist/techStacks/utils.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(utils_exports, {
|
|
|
33
33
|
IDumiTechStackOnBlockLoadArgs: () => import_types.IDumiTechStackOnBlockLoadArgs,
|
|
34
34
|
IDumiTechStackOnBlockLoadResult: () => import_types.IDumiTechStackOnBlockLoadResult,
|
|
35
35
|
IDumiTechStackRuntimeOpts: () => import_types.IDumiTechStackRuntimeOpts,
|
|
36
|
+
defineTechStack: () => defineTechStack,
|
|
36
37
|
extractScript: () => extractScript,
|
|
37
38
|
wrapDemoWithFn: () => wrapDemoWithFn
|
|
38
39
|
});
|
|
@@ -74,12 +75,16 @@ function wrapDemoWithFn(code, opts) {
|
|
|
74
75
|
${result.code}
|
|
75
76
|
}`;
|
|
76
77
|
}
|
|
78
|
+
function defineTechStack(options) {
|
|
79
|
+
return options;
|
|
80
|
+
}
|
|
77
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
78
82
|
0 && (module.exports = {
|
|
79
83
|
IDumiTechStack,
|
|
80
84
|
IDumiTechStackOnBlockLoadArgs,
|
|
81
85
|
IDumiTechStackOnBlockLoadResult,
|
|
82
86
|
IDumiTechStackRuntimeOpts,
|
|
87
|
+
defineTechStack,
|
|
83
88
|
extractScript,
|
|
84
89
|
wrapDemoWithFn
|
|
85
90
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -58,6 +58,11 @@ export type IDumiTechStackOnBlockLoadArgs = OnLoadArgs & {
|
|
|
58
58
|
filename: string;
|
|
59
59
|
};
|
|
60
60
|
export interface IDumiTechStackRuntimeOpts {
|
|
61
|
+
/**
|
|
62
|
+
* Component detection function path,
|
|
63
|
+
* used to detect errors that occur from application creation to component mounting.
|
|
64
|
+
*/
|
|
65
|
+
preflightPath?: string;
|
|
61
66
|
/**
|
|
62
67
|
* path of the cancelable{@link IDemoCancelableFn} function
|
|
63
68
|
* that manipulate(mount/unmount) third-party framework component
|
|
@@ -82,7 +87,9 @@ export declare abstract class IDumiTechStack {
|
|
|
82
87
|
*/
|
|
83
88
|
abstract runtimeOpts?: IDumiTechStackRuntimeOpts;
|
|
84
89
|
/**
|
|
85
|
-
*
|
|
90
|
+
* Is the lang supported by the current tech stack?
|
|
91
|
+
* @param lang
|
|
92
|
+
* @param node hast Element https://github.com/syntax-tree/hast?tab=readme-ov-file#element
|
|
86
93
|
*/
|
|
87
94
|
abstract isSupported(node: Element, lang: string): boolean;
|
|
88
95
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.3.0
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "📖 Documentation Generator of React Component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"generator",
|
|
@@ -36,25 +36,6 @@
|
|
|
36
36
|
"tech-stack-utils.js",
|
|
37
37
|
"tech-stack-utils.d.ts"
|
|
38
38
|
],
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "father build && npm run build:crates",
|
|
41
|
-
"build:crates": "cargo build --target wasm32-wasi -r --out-dir compiled/crates -Z unstable-options",
|
|
42
|
-
"build:deps": "node scripts/pre-bundle-worker.js && father prebundle",
|
|
43
|
-
"build:suites": "pnpm run --filter=\"./suites/**\" build",
|
|
44
|
-
"dev": "father dev",
|
|
45
|
-
"docs:build": "node ./bin/dumi.js build",
|
|
46
|
-
"docs:dev": "node ./bin/dumi.js dev",
|
|
47
|
-
"docs:sync": "node ./scripts/sync-from-umi.js",
|
|
48
|
-
"format": "prettier --cache --write .",
|
|
49
|
-
"lint": "npm run lint:es && npm run lint:css",
|
|
50
|
-
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
|
|
51
|
-
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
52
|
-
"prepare": "husky install && npm run build && npm run build:suites && node ./bin/dumi.js setup && npm run docs:sync",
|
|
53
|
-
"prepublishOnly": "npm run build",
|
|
54
|
-
"test": "vitest",
|
|
55
|
-
"vercel:build": "npm run docs:build",
|
|
56
|
-
"vercel:install": "./scripts/vercel-install.sh"
|
|
57
|
-
},
|
|
58
39
|
"commitlint": {
|
|
59
40
|
"extends": [
|
|
60
41
|
"@commitlint/config-conventional"
|
|
@@ -120,8 +101,9 @@
|
|
|
120
101
|
"raw-loader": "^4.0.2",
|
|
121
102
|
"rc-motion": "^2.7.3",
|
|
122
103
|
"rc-tabs": "^12.10.0",
|
|
104
|
+
"rc-tooltip": "^6.1.3",
|
|
123
105
|
"rc-tree": "^5.7.9",
|
|
124
|
-
"rc-util": "^5.
|
|
106
|
+
"rc-util": "^5.38.0",
|
|
125
107
|
"react-copy-to-clipboard": "^5.1.0",
|
|
126
108
|
"react-error-boundary": "^4.0.10",
|
|
127
109
|
"react-intl": "^6.4.4",
|
|
@@ -163,10 +145,11 @@
|
|
|
163
145
|
"@umijs/lint": "^4.0.84",
|
|
164
146
|
"@umijs/plugins": "4.0.32",
|
|
165
147
|
"codesandbox-import-utils": "^2.2.3",
|
|
166
|
-
"dumi-theme-mobile": "workspace:*",
|
|
167
148
|
"eslint": "^8.46.0",
|
|
149
|
+
"esno": "^4.7.0",
|
|
168
150
|
"fast-glob": "^3.3.1",
|
|
169
151
|
"father": "^4.3.0",
|
|
152
|
+
"git-repo-info": "^2.1.1",
|
|
170
153
|
"highlight-words-core": "^1.2.2",
|
|
171
154
|
"husky": "^8.0.3",
|
|
172
155
|
"lint-staged": "^13.2.3",
|
|
@@ -178,7 +161,9 @@
|
|
|
178
161
|
"stylelint": "^15.10.2",
|
|
179
162
|
"ts-node": "^10.9.1",
|
|
180
163
|
"typescript": "~5.0.4",
|
|
181
|
-
"vitest": "^0.33.0"
|
|
164
|
+
"vitest": "^0.33.0",
|
|
165
|
+
"zx": "^7.2.3",
|
|
166
|
+
"dumi-theme-mobile": "2.3.0"
|
|
182
167
|
},
|
|
183
168
|
"peerDependencies": {
|
|
184
169
|
"react": ">=16.8",
|
|
@@ -190,5 +175,23 @@
|
|
|
190
175
|
},
|
|
191
176
|
"authors": [
|
|
192
177
|
"Peach <scdzwyxst@gmail.com>"
|
|
193
|
-
]
|
|
194
|
-
|
|
178
|
+
],
|
|
179
|
+
"scripts": {
|
|
180
|
+
"build": "father build && npm run build:crates",
|
|
181
|
+
"build:crates": "cargo build --target wasm32-wasi -r --out-dir compiled/crates -Z unstable-options",
|
|
182
|
+
"build:deps": "node scripts/pre-bundle-worker.js && father prebundle",
|
|
183
|
+
"build:suites": "pnpm run --filter=\"./suites/**\" build",
|
|
184
|
+
"dev": "father dev",
|
|
185
|
+
"docs:build": "node ./bin/dumi.js build",
|
|
186
|
+
"docs:dev": "node ./bin/dumi.js dev",
|
|
187
|
+
"docs:sync": "node ./scripts/sync-from-umi.js",
|
|
188
|
+
"format": "prettier --cache --write .",
|
|
189
|
+
"lint": "npm run lint:es && npm run lint:css",
|
|
190
|
+
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
|
|
191
|
+
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
192
|
+
"release": "esno scripts/release.ts",
|
|
193
|
+
"test": "vitest",
|
|
194
|
+
"vercel:build": "npm run docs:build",
|
|
195
|
+
"vercel:install": "./scripts/vercel-install.sh"
|
|
196
|
+
}
|
|
197
|
+
}
|
package/tech-stack-utils.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type * as BabelCore from '@umijs/bundler-utils/compiled/@babel/core';
|
|
2
2
|
export {
|
|
3
|
-
IBaseApiParserOptions,
|
|
4
3
|
ILanguageMetaParser,
|
|
5
4
|
IPatchFile,
|
|
6
5
|
} from './dist/assetParsers/BaseParser';
|
|
7
|
-
export {
|
|
6
|
+
export {
|
|
7
|
+
IBaseApiParserOptions,
|
|
8
|
+
createApiParser,
|
|
9
|
+
} from './dist/assetParsers/utils';
|
|
8
10
|
export * from './dist/techStacks/utils';
|
|
9
11
|
export { BabelCore };
|
|
10
12
|
export const babelCore: () => typeof import('@umijs/bundler-utils/compiled/@babel/core');
|
|
@@ -1,115 +1,239 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
1
2
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
3
|
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."); }
|
|
3
4
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
5
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
6
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
7
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
+
import { useAtomAssets, useIntl, useRouteMeta, useSiteData } from 'dumi';
|
|
14
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
15
|
+
import Badge from "../Badge";
|
|
9
16
|
import Table from "../Table";
|
|
17
|
+
import "./index.less";
|
|
18
|
+
function Token(_ref) {
|
|
19
|
+
var children = _ref.children;
|
|
20
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
21
|
+
"data-token": children
|
|
22
|
+
}, children);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// https://github.com/umijs/dumi/issues/1957
|
|
26
|
+
function fixArg(arg) {
|
|
27
|
+
if (arg.hasQuestionToken && typeof arg.type === 'string') {
|
|
28
|
+
arg.type = arg.type.replace(/\s+\|\s+undefined\s*$/i, '');
|
|
29
|
+
}
|
|
30
|
+
return arg;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Usually handles types other than basic types, either interfaces or type aliases
|
|
34
|
+
var CompositeType = function CompositeType(prop) {
|
|
35
|
+
var _prop$source;
|
|
36
|
+
var intl = useIntl();
|
|
37
|
+
var _useSiteData = useSiteData(),
|
|
38
|
+
themeConfig = _useSiteData.themeConfig;
|
|
39
|
+
return (_prop$source = prop.source) !== null && _prop$source !== void 0 && _prop$source[0] && themeConfig.sourceLink ? /*#__PURE__*/React.createElement("a", {
|
|
40
|
+
className: "dumi-default-api-link",
|
|
41
|
+
href: intl.formatMessage({
|
|
42
|
+
id: '$internal.api.sourceLink'
|
|
43
|
+
}, _objectSpread({}, prop.source[0])),
|
|
44
|
+
target: "_blank",
|
|
45
|
+
rel: "noreferrer"
|
|
46
|
+
}, prop.className) : prop.className;
|
|
47
|
+
};
|
|
10
48
|
var HANDLERS = {
|
|
11
49
|
// entry method
|
|
12
|
-
|
|
50
|
+
toNode: function toNode(prop) {
|
|
13
51
|
if (typeof prop.type === 'string' && prop.type in this) {
|
|
14
52
|
// value from TypeMap
|
|
15
53
|
if ('enum' in prop) return this.enum(prop);
|
|
16
54
|
return this[prop.type](prop);
|
|
17
55
|
} else if (prop.type) {
|
|
18
56
|
// non-parsed type, such as ReactNode
|
|
19
|
-
return this.getValidClassName(prop) || prop.type;
|
|
57
|
+
return this.getValidClassName(prop) || /*#__PURE__*/React.createElement("span", null, prop.type);
|
|
20
58
|
} else if ('const' in prop) {
|
|
21
59
|
// const value
|
|
22
|
-
return ""
|
|
60
|
+
return /*#__PURE__*/React.createElement("span", null, prop.const);
|
|
23
61
|
} else if ('oneOf' in prop) {
|
|
24
62
|
// oneOf value
|
|
25
63
|
return this.oneOf(prop);
|
|
26
64
|
}
|
|
27
65
|
|
|
28
66
|
// unknown type
|
|
29
|
-
return "unknown";
|
|
67
|
+
return /*#__PURE__*/React.createElement("span", null, "unknown");
|
|
30
68
|
},
|
|
31
69
|
// type handlers
|
|
32
70
|
string: function string(prop) {
|
|
33
|
-
return prop.type;
|
|
71
|
+
return /*#__PURE__*/React.createElement("span", null, prop.type);
|
|
34
72
|
},
|
|
35
73
|
number: function number(prop) {
|
|
36
|
-
return prop.type;
|
|
74
|
+
return /*#__PURE__*/React.createElement("span", null, prop.type);
|
|
37
75
|
},
|
|
38
76
|
boolean: function boolean(prop) {
|
|
39
|
-
return prop.type;
|
|
77
|
+
return /*#__PURE__*/React.createElement("span", null, prop.type);
|
|
40
78
|
},
|
|
41
79
|
any: function any(prop) {
|
|
42
|
-
return prop.type;
|
|
80
|
+
return /*#__PURE__*/React.createElement("span", null, prop.type);
|
|
43
81
|
},
|
|
44
82
|
object: function object(prop) {
|
|
45
83
|
var _this = this;
|
|
46
|
-
var
|
|
47
|
-
|
|
84
|
+
var entries = Object.entries(prop.properties || {});
|
|
85
|
+
var props = entries.map(function (_ref2, index) {
|
|
48
86
|
var _prop$required;
|
|
49
|
-
var
|
|
50
|
-
key =
|
|
51
|
-
value =
|
|
87
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
88
|
+
key = _ref3[0],
|
|
89
|
+
value = _ref3[1];
|
|
52
90
|
// skip nested object type
|
|
53
|
-
|
|
91
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
92
|
+
key: key
|
|
93
|
+
}, /*#__PURE__*/React.createElement("span", null, key), !((_prop$required = prop.required) !== null && _prop$required !== void 0 && _prop$required.includes(key)) && /*#__PURE__*/React.createElement(Token, null, "?"), /*#__PURE__*/React.createElement(Token, null, ":"), value.type === 'object' ? /*#__PURE__*/React.createElement("span", null, "object") : _this.toNode(value), index < entries.length - 1 && /*#__PURE__*/React.createElement(Token, null, ";"));
|
|
54
94
|
});
|
|
55
|
-
return
|
|
95
|
+
return /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Token, null, '{'), props, /*#__PURE__*/React.createElement(Token, null, '}'));
|
|
56
96
|
},
|
|
57
97
|
array: function array(prop) {
|
|
98
|
+
var arrayType = /*#__PURE__*/React.createElement("span", null, "any");
|
|
58
99
|
if (prop.items) {
|
|
59
100
|
var className = this.getValidClassName(prop.items);
|
|
60
|
-
|
|
101
|
+
arrayType = className !== null && className !== void 0 ? className : this.toNode(prop.items);
|
|
61
102
|
}
|
|
62
|
-
return '
|
|
103
|
+
return /*#__PURE__*/React.createElement("span", null, arrayType, /*#__PURE__*/React.createElement(Token, null, '['), /*#__PURE__*/React.createElement(Token, null, ']'));
|
|
63
104
|
},
|
|
64
105
|
// FIXME: extract real type
|
|
65
106
|
element: function element(prop) {
|
|
66
|
-
return "<".
|
|
107
|
+
return /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Token, null, "<"), /*#__PURE__*/React.createElement("span", null, prop.componentName), /*#__PURE__*/React.createElement(Token, null, ">"));
|
|
67
108
|
},
|
|
68
109
|
// FIXME: extract real type
|
|
69
|
-
function: function _function(
|
|
110
|
+
function: function _function(_ref4) {
|
|
70
111
|
var _this2 = this;
|
|
71
|
-
var signature =
|
|
112
|
+
var signature = _ref4.signature;
|
|
72
113
|
// handle Function type without signature
|
|
73
|
-
if (!signature) return
|
|
114
|
+
if (!signature) return /*#__PURE__*/React.createElement("span", null, "Function");
|
|
74
115
|
var signatures = 'oneOf' in signature ? signature.oneOf : [signature];
|
|
75
|
-
return signatures.map(function (signature) {
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
116
|
+
return signatures.map(function (signature, si) {
|
|
117
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
118
|
+
key: "".concat(si)
|
|
119
|
+
}, signature.isAsync ? /*#__PURE__*/React.createElement(Token, null, "async") : '', /*#__PURE__*/React.createElement(Token, null, '('), signature.arguments.map(function (arg, ai) {
|
|
120
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
121
|
+
key: "".concat(si).concat(ai)
|
|
122
|
+
}, /*#__PURE__*/React.createElement("span", null, arg.key), arg.hasQuestionToken && /*#__PURE__*/React.createElement(Token, null, "?"), /*#__PURE__*/React.createElement(Token, null, ":"), _this2.toNode(!!arg.schema ? arg.schema : fixArg(arg)), ai < signature.arguments.length - 1 && /*#__PURE__*/React.createElement(Token, null, ","));
|
|
123
|
+
}), /*#__PURE__*/React.createElement(Token, null, ')'), /*#__PURE__*/React.createElement(Token, null, "=>"), _this2.toNode(signature.returnType), si < signatures.length - 1 && /*#__PURE__*/React.createElement(Token, null, "|"));
|
|
124
|
+
});
|
|
80
125
|
},
|
|
81
126
|
// FIXME: extract real type
|
|
82
127
|
dom: function dom(prop) {
|
|
83
|
-
return prop.className || 'DOM';
|
|
128
|
+
return /*#__PURE__*/React.createElement("span", null, prop.className || 'DOM');
|
|
84
129
|
},
|
|
85
130
|
// special handlers
|
|
86
131
|
enum: function _enum(prop) {
|
|
87
|
-
|
|
132
|
+
var enumStringArray = prop.enum.map(function (v) {
|
|
88
133
|
return JSON.stringify(v);
|
|
89
|
-
})
|
|
134
|
+
});
|
|
135
|
+
return /*#__PURE__*/React.createElement("span", null, enumStringArray.map(function (e, i) {
|
|
136
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
137
|
+
key: i
|
|
138
|
+
}, /*#__PURE__*/React.createElement("span", null, e), i < enumStringArray.length - 1 && /*#__PURE__*/React.createElement(Token, null, "|"));
|
|
139
|
+
}));
|
|
90
140
|
},
|
|
91
141
|
oneOf: function oneOf(prop) {
|
|
92
142
|
var _this3 = this;
|
|
93
|
-
return prop.oneOf.map(function (v) {
|
|
94
|
-
return
|
|
95
|
-
|
|
143
|
+
return prop.oneOf.map(function (v, i) {
|
|
144
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
145
|
+
key: i
|
|
146
|
+
}, _this3.getValidClassName(v) || _this3.toNode(v), i < prop.oneOf.length - 1 && /*#__PURE__*/React.createElement(Token, null, "|"));
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
reference: function reference(prop) {
|
|
150
|
+
var _this4 = this;
|
|
151
|
+
var typeParameters = prop.typeParameters || [];
|
|
152
|
+
var params = typeParameters.map(function (param, i) {
|
|
153
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
154
|
+
key: i
|
|
155
|
+
}, _this4.toNode(param), i < typeParameters.length - 1 && /*#__PURE__*/React.createElement(Token, null, ","));
|
|
156
|
+
});
|
|
157
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("a", {
|
|
158
|
+
className: "dumi-default-api-link",
|
|
159
|
+
href: prop.externalUrl,
|
|
160
|
+
target: "_blank",
|
|
161
|
+
rel: "noreferrer"
|
|
162
|
+
}, prop.name), params.length ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Token, null, "<"), params, /*#__PURE__*/React.createElement(Token, null, ">")) : '');
|
|
96
163
|
},
|
|
97
164
|
// utils
|
|
98
165
|
getValidClassName: function getValidClassName(prop) {
|
|
99
|
-
|
|
166
|
+
if ('className' in prop && typeof prop.className === 'string' && prop.className !== '__type') {
|
|
167
|
+
return /*#__PURE__*/React.createElement(CompositeType, prop);
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
100
170
|
}
|
|
101
171
|
};
|
|
102
172
|
var APIType = function APIType(prop) {
|
|
103
173
|
var _useState = useState(function () {
|
|
104
|
-
return HANDLERS.
|
|
174
|
+
return HANDLERS.toNode(prop);
|
|
105
175
|
}),
|
|
106
176
|
_useState2 = _slicedToArray(_useState, 2),
|
|
107
177
|
type = _useState2[0],
|
|
108
178
|
setType = _useState2[1];
|
|
109
179
|
useEffect(function () {
|
|
110
|
-
setType(HANDLERS.
|
|
180
|
+
setType(HANDLERS.toNode(prop));
|
|
111
181
|
}, [prop]);
|
|
112
|
-
return /*#__PURE__*/React.createElement("code",
|
|
182
|
+
return /*#__PURE__*/React.createElement("code", {
|
|
183
|
+
className: "dumi-default-api-type"
|
|
184
|
+
}, type);
|
|
185
|
+
};
|
|
186
|
+
function getReleaseAndVersionInfo(props) {
|
|
187
|
+
var releaseInfo = {};
|
|
188
|
+
Object.entries(props).forEach(function (_ref5) {
|
|
189
|
+
var _schema$tags, _schema$tags2;
|
|
190
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
191
|
+
prop = _ref6[0],
|
|
192
|
+
schema = _ref6[1];
|
|
193
|
+
var modiferTags = (_schema$tags = schema.tags) === null || _schema$tags === void 0 ? void 0 : _schema$tags.modifierTags;
|
|
194
|
+
var blockTags = (_schema$tags2 = schema.tags) === null || _schema$tags2 === void 0 ? void 0 : _schema$tags2.blockTags;
|
|
195
|
+
modiferTags === null || modiferTags === void 0 ? void 0 : modiferTags.forEach(function (tag) {
|
|
196
|
+
if (tag === 'alpha' || tag === 'beta' || tag === 'experimental') {
|
|
197
|
+
releaseInfo[prop] = [tag];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
blockTags === null || blockTags === void 0 ? void 0 : blockTags.forEach(function (_ref7) {
|
|
201
|
+
var tag = _ref7.tag,
|
|
202
|
+
content = _ref7.content;
|
|
203
|
+
if (tag === 'deprecated' || tag === 'since') {
|
|
204
|
+
var textContent = content.map(function (item) {
|
|
205
|
+
return item.text;
|
|
206
|
+
}).join('');
|
|
207
|
+
releaseInfo[prop] = [tag, textContent];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
return releaseInfo;
|
|
212
|
+
}
|
|
213
|
+
var APIRelease = function APIRelease(_ref8) {
|
|
214
|
+
var name = _ref8.name,
|
|
215
|
+
info = _ref8.info;
|
|
216
|
+
var intl = useIntl();
|
|
217
|
+
var _info = _slicedToArray(info, 2),
|
|
218
|
+
modifer = _info[0],
|
|
219
|
+
text = _info[1];
|
|
220
|
+
var modiferProps = _defineProperty({
|
|
221
|
+
className: 'dumi-default-api-release-modifer'
|
|
222
|
+
}, 'data-release', modifer);
|
|
223
|
+
if (text && modifer === 'deprecated') {
|
|
224
|
+
modiferProps['data-dumi-tooltip'] = text;
|
|
225
|
+
}
|
|
226
|
+
var modiferText = modifer === 'since' ? "".concat(text, "+") : intl.formatMessage({
|
|
227
|
+
id: "api.component.release.".concat(modifer)
|
|
228
|
+
});
|
|
229
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
230
|
+
className: "dumi-default-api-release"
|
|
231
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
232
|
+
className: "dumi-default-api-release-name",
|
|
233
|
+
"data-release": modifer
|
|
234
|
+
}, name), /*#__PURE__*/React.createElement("span", modiferProps, modifer === 'deprecated' ? modiferText : /*#__PURE__*/React.createElement(Badge, {
|
|
235
|
+
type: "info"
|
|
236
|
+
}, modiferText)));
|
|
113
237
|
};
|
|
114
238
|
var API = function API(props) {
|
|
115
239
|
var _useRouteMeta = useRouteMeta(),
|
|
@@ -127,6 +251,9 @@ var API = function API(props) {
|
|
|
127
251
|
var key = "".concat(type, "Config");
|
|
128
252
|
properties = ((_definition$key = definition[key]) === null || _definition$key === void 0 ? void 0 : _definition$key.properties) || {};
|
|
129
253
|
}
|
|
254
|
+
var releaseInfo = useMemo(function () {
|
|
255
|
+
return getReleaseAndVersionInfo(properties);
|
|
256
|
+
}, [properties]);
|
|
130
257
|
return /*#__PURE__*/React.createElement("div", {
|
|
131
258
|
className: "markdown"
|
|
132
259
|
}, /*#__PURE__*/React.createElement(Table, null, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
|
|
@@ -137,14 +264,17 @@ var API = function API(props) {
|
|
|
137
264
|
id: 'api.component.type'
|
|
138
265
|
})), props.type === 'props' && /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
|
|
139
266
|
id: 'api.component.default'
|
|
140
|
-
})))), /*#__PURE__*/React.createElement("tbody", null, Object.keys(properties).length ? Object.entries(properties).map(function (
|
|
267
|
+
})))), /*#__PURE__*/React.createElement("tbody", null, Object.keys(properties).length ? Object.entries(properties).map(function (_ref9) {
|
|
141
268
|
var _definition$propsConf;
|
|
142
|
-
var
|
|
143
|
-
name =
|
|
144
|
-
prop =
|
|
269
|
+
var _ref10 = _slicedToArray(_ref9, 2),
|
|
270
|
+
name = _ref10[0],
|
|
271
|
+
prop = _ref10[1];
|
|
145
272
|
return /*#__PURE__*/React.createElement("tr", {
|
|
146
273
|
key: name
|
|
147
|
-
}, /*#__PURE__*/React.createElement("td", null, name
|
|
274
|
+
}, /*#__PURE__*/React.createElement("td", null, releaseInfo[name] ? /*#__PURE__*/React.createElement(APIRelease, {
|
|
275
|
+
name: name,
|
|
276
|
+
info: releaseInfo[name]
|
|
277
|
+
}) : name), /*#__PURE__*/React.createElement("td", null, prop.description || '--'), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(APIType, prop)), props.type === 'props' && /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, (_definition$propsConf = definition.propsConfig.required) !== null && _definition$propsConf !== void 0 && _definition$propsConf.includes(name) ? intl.formatMessage({
|
|
148
278
|
id: 'api.component.required'
|
|
149
279
|
}) : JSON.stringify(prop.default) || '--')));
|
|
150
280
|
}) : /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
@import (reference) '../../styles/variables.less';
|
|
2
|
+
|
|
3
|
+
.@{prefix}-api {
|
|
4
|
+
&-type {
|
|
5
|
+
[data-token='|'],
|
|
6
|
+
[data-token='=>'] {
|
|
7
|
+
padding: 0 0.5em;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
[data-token=';'],
|
|
11
|
+
[data-token=':'],
|
|
12
|
+
[data-token=','],
|
|
13
|
+
[data-token='async'] {
|
|
14
|
+
padding-right: 0.5em;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
[data-token='{'] {
|
|
18
|
+
padding-right: 0.5em;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
[data-token='}'] {
|
|
22
|
+
padding-left: 0.5em;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
&-release {
|
|
27
|
+
[data-release] + [data-release] {
|
|
28
|
+
margin-left: 0.5em;
|
|
29
|
+
}
|
|
30
|
+
.@{prefix}-badge {
|
|
31
|
+
transform: scale(0.9);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&-release-name {
|
|
36
|
+
&[data-release='deprecated'] {
|
|
37
|
+
text-decoration: line-through;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&-release-modifer {
|
|
42
|
+
&[data-release='deprecated'] {
|
|
43
|
+
cursor: help;
|
|
44
|
+
border-bottom: 1px dotted @c-text-secondary;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
import Tabs from "../../slots/Tabs";
|
|
3
|
+
import SourceCode from 'dumi/theme/builtins/SourceCode';
|
|
4
|
+
import toArray from 'rc-util/lib/Children/toArray';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
function CodeGroup(props) {
|
|
7
|
+
var children = props.children;
|
|
8
|
+
var usefulChildren = toArray(children).filter(function (child) {
|
|
9
|
+
var _child$type;
|
|
10
|
+
return _typeof(child) === 'object' && typeof child.type === 'function' && ((_child$type = child.type) === null || _child$type === void 0 ? void 0 : _child$type.name) === SourceCode.name;
|
|
11
|
+
});
|
|
12
|
+
var items = usefulChildren.map(function (child, idx) {
|
|
13
|
+
var _child$props, _child$key;
|
|
14
|
+
var _ref = (_child$props = child.props) !== null && _child$props !== void 0 ? _child$props : {},
|
|
15
|
+
lang = _ref.lang,
|
|
16
|
+
title = _ref.title;
|
|
17
|
+
return {
|
|
18
|
+
key: String((_child$key = child.key) !== null && _child$key !== void 0 ? _child$key : idx),
|
|
19
|
+
label: title || lang || 'txt',
|
|
20
|
+
// fallback to txt if no lang and title
|
|
21
|
+
children: child
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
return /*#__PURE__*/React.createElement(Tabs, {
|
|
25
|
+
className: "dumi-default-code-group",
|
|
26
|
+
items: items
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export default CodeGroup;
|
|
@@ -13,7 +13,7 @@ var Previewer = function Previewer(props) {
|
|
|
13
13
|
hash = _useLocation.hash;
|
|
14
14
|
var link = "#".concat(props.asset.id);
|
|
15
15
|
var _useLiveDemo = useLiveDemo(props.asset.id, {
|
|
16
|
-
iframe: Boolean(props.iframe),
|
|
16
|
+
iframe: Boolean(props.iframe || props._live_in_iframe),
|
|
17
17
|
containerRef: demoContainer
|
|
18
18
|
}),
|
|
19
19
|
liveDemoNode = _useLiveDemo.node,
|
|
@@ -2,12 +2,13 @@ import { type Language } from 'prism-react-renderer';
|
|
|
2
2
|
import 'prism-themes/themes/prism-one-light.css';
|
|
3
3
|
import { type FC, type ReactNode } from 'react';
|
|
4
4
|
import './index.less';
|
|
5
|
-
interface
|
|
5
|
+
export interface ISourceCodeProps {
|
|
6
6
|
children: string;
|
|
7
7
|
lang: Language;
|
|
8
8
|
highlightLines?: number[];
|
|
9
9
|
extra?: ReactNode;
|
|
10
10
|
textarea?: ReactNode;
|
|
11
|
+
title?: string;
|
|
11
12
|
}
|
|
12
|
-
declare const SourceCode: FC<
|
|
13
|
+
declare const SourceCode: FC<ISourceCodeProps>;
|
|
13
14
|
export default SourceCode;
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
"api.component.type": "Type",
|
|
32
32
|
"api.component.default": "Default",
|
|
33
33
|
"api.component.required": "(required)",
|
|
34
|
+
"api.component.release.alpha": "Alpha",
|
|
35
|
+
"api.component.release.beta": "Beta",
|
|
36
|
+
"api.component.release.experimental": "Experimental",
|
|
37
|
+
"api.component.release.deprecated": "Deprecated",
|
|
34
38
|
"api.component.unavailable": "apiParser must be enabled to use auto-generated API",
|
|
35
39
|
"api.component.loading": "Properties definition is resolving, wait a moment...",
|
|
36
40
|
"api.component.not.found": "Properties definition not found for {id} component",
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"api.component.type": "类型",
|
|
31
31
|
"api.component.default": "默认值",
|
|
32
32
|
"api.component.required": "(必选)",
|
|
33
|
+
"api.component.release.alpha": "Alpha",
|
|
34
|
+
"api.component.release.beta": "Beta",
|
|
35
|
+
"api.component.release.experimental": "实验性",
|
|
36
|
+
"api.component.release.deprecated": "废弃",
|
|
33
37
|
"api.component.unavailable": "必须启用 apiParser 才能使用自动 API 特性",
|
|
34
38
|
"api.component.loading": "属性定义正在解析中,稍等片刻...",
|
|
35
39
|
"api.component.not.found": "未找到 {id} 组件的属性定义",
|