@antv/dumi-theme-antv 0.3.0-beta.1 → 0.3.0-beta.10
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/builtins/Playground/index.d.ts +2 -5
- package/dist/builtins/Playground/index.js +17 -3
- package/dist/context.d.ts +2 -1
- package/dist/layouts/DocLayout.js +26 -16
- package/dist/layouts/entry/Index.js +10 -2
- package/dist/layouts/entry/Manual.js +1 -2
- package/dist/pages/404.js +5 -1
- package/dist/pages/Example/index.js +28 -52
- package/dist/pages/Example/index.module.less +50 -8
- package/dist/pages/Example/utils.d.ts +1 -0
- package/dist/pages/Example/utils.js +9 -0
- package/dist/pages/Examples/components/GalleryPageContent/DemoCard/index.js +1 -1
- package/dist/pages/Examples/index.js +22 -2
- package/dist/pages/Examples/index.module.less +2 -0
- package/dist/pages/Examples/types.d.ts +7 -6
- package/dist/plugin/examples.d.ts +16 -2
- package/dist/plugin/examples.js +32 -10
- package/dist/plugin/index.js +30 -20
- package/dist/plugin/utils.d.ts +5 -0
- package/dist/plugin/utils.js +46 -0
- package/dist/slots/Cases/index.d.ts +1 -0
- package/dist/slots/CodeEditor/Toolbar.js +4 -16
- package/dist/slots/CodeEditor/index.js +40 -14
- package/dist/slots/CodeEditor/utils.js +1 -1
- package/dist/slots/CodePreview/CodeHeader.js +2 -2
- package/dist/slots/CodePreview/index.js +1 -1
- package/dist/slots/CodePreview/index.module.less +7 -6
- package/dist/slots/CodeRunner/index.d.ts +3 -2
- package/dist/slots/CodeRunner/index.js +6 -3
- package/dist/slots/CodeRunner/utils.d.ts +3 -2
- package/dist/slots/CodeRunner/utils.js +1 -1
- package/dist/slots/Detail/News.d.ts +1 -0
- package/dist/slots/Detail/index.d.ts +1 -0
- package/dist/slots/Detail/index.js +1 -1
- package/dist/slots/ExampleSider/index.d.ts +4 -38
- package/dist/slots/ExampleSider/index.js +22 -44
- package/dist/slots/ExampleSider/index.module.less +1 -1
- package/dist/slots/Features/FeatureCard.d.ts +1 -0
- package/dist/slots/Features/index.js +2 -1
- package/dist/slots/Footer/index.js +3 -2
- package/dist/slots/Footer/index.module.less +1 -0
- package/dist/slots/Header/Navs.d.ts +10 -1
- package/dist/slots/Header/Navs.js +35 -18
- package/dist/slots/Header/index.js +8 -7
- package/dist/slots/Loading/index.d.ts +6 -1
- package/dist/slots/Loading/index.js +24 -10
- package/dist/slots/Loading/index.module.less +276 -9
- package/dist/slots/ManualContent/index.js +136 -113
- package/dist/slots/ManualContent/index.module.less +43 -31
- package/dist/slots/ManualContent/utils.d.ts +3 -0
- package/dist/slots/ManualContent/utils.js +35 -0
- package/dist/slots/SEO.d.ts +10 -0
- package/dist/slots/SEO.js +59 -0
- package/dist/slots/hooks.d.ts +3 -3
- package/dist/slots/utils.d.ts +4 -19
- package/dist/slots/utils.js +77 -119
- package/dist/types.d.ts +83 -0
- package/dist/typings.d.ts +0 -113
- package/package.json +6 -4
- package/dist/slots/Loading.d.ts +0 -5
- package/dist/slots/Loading.js +0 -8
package/dist/plugin/index.js
CHANGED
|
@@ -25,44 +25,51 @@ __export(plugin_exports, {
|
|
|
25
25
|
default: () => plugin_default
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(plugin_exports);
|
|
28
|
+
var path = __toESM(require("path"));
|
|
28
29
|
var import_examples = require("./examples");
|
|
29
|
-
|
|
30
|
-
const res = (0, import_examples.getExamplesPageTopics)();
|
|
31
|
-
return {
|
|
32
|
-
exampleTopics: res
|
|
33
|
-
};
|
|
34
|
-
}
|
|
30
|
+
var import_utils = require("./utils");
|
|
35
31
|
var plugin_default = (api) => {
|
|
36
32
|
api.describe({ key: `dumi-theme:${require("../../package.json").name}` });
|
|
33
|
+
api.modifyDefaultConfig((memo) => {
|
|
34
|
+
memo.resolve.codeBlockMode = "passive";
|
|
35
|
+
memo.exportStatic.extraRoutePaths = (0, import_examples.getExamplePaths)();
|
|
36
|
+
memo.mfsu = false;
|
|
37
|
+
return memo;
|
|
38
|
+
});
|
|
37
39
|
const pages = [
|
|
40
|
+
{
|
|
41
|
+
id: "dumi-theme-antv-homepage",
|
|
42
|
+
absPath: "/"
|
|
43
|
+
},
|
|
38
44
|
{
|
|
39
45
|
id: "dumi-theme-antv-example-list-zh",
|
|
40
|
-
|
|
41
|
-
file:
|
|
46
|
+
absPath: "/examples",
|
|
47
|
+
file: (0, import_utils.myResolve)("../pages/Examples/index.tsx")
|
|
42
48
|
},
|
|
43
49
|
{
|
|
44
50
|
id: "dumi-theme-antv-example-list-lang",
|
|
45
|
-
|
|
46
|
-
file:
|
|
51
|
+
absPath: "/:language/examples",
|
|
52
|
+
file: (0, import_utils.myResolve)("../pages/Examples/index.tsx")
|
|
47
53
|
},
|
|
48
54
|
{
|
|
49
55
|
id: "dumi-theme-antv-single-example-zh",
|
|
50
|
-
|
|
51
|
-
file:
|
|
56
|
+
absPath: "/examples/:topic/:example",
|
|
57
|
+
file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
|
|
52
58
|
},
|
|
53
59
|
{
|
|
54
60
|
id: "dumi-theme-antv-single-example-lang",
|
|
55
|
-
|
|
56
|
-
file:
|
|
61
|
+
absPath: "/:language/examples/:topic/:example",
|
|
62
|
+
file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
|
|
57
63
|
}
|
|
58
64
|
];
|
|
59
|
-
const contextFilePath =
|
|
65
|
+
const contextFilePath = (0, import_utils.myResolve)("../context.ts");
|
|
60
66
|
api.onGenerateFiles(() => {
|
|
61
67
|
api.writeTmpFile({
|
|
62
68
|
noPluginDir: true,
|
|
63
69
|
path: "theme-antv/ContextWrapper.tsx",
|
|
64
70
|
content: `
|
|
65
|
-
import
|
|
71
|
+
import React from 'react';
|
|
72
|
+
import { useOutlet, useSiteData } from 'dumi';
|
|
66
73
|
import { ThemeAntVContext } from '${contextFilePath}';
|
|
67
74
|
|
|
68
75
|
export default function ThemeAntVContextWrapper() {
|
|
@@ -71,7 +78,9 @@ export default function ThemeAntVContextWrapper() {
|
|
|
71
78
|
return (
|
|
72
79
|
<ThemeAntVContext.Provider
|
|
73
80
|
value={{
|
|
74
|
-
meta: ${JSON.stringify(
|
|
81
|
+
meta: ${JSON.stringify({
|
|
82
|
+
exampleTopics: (0, import_examples.getExamplesPageTopics)(api.config.themeConfig.examples || [])
|
|
83
|
+
})}
|
|
75
84
|
}}
|
|
76
85
|
>
|
|
77
86
|
{outlet}
|
|
@@ -89,15 +98,16 @@ export default function ThemeAntVContextWrapper() {
|
|
|
89
98
|
pages.forEach((page) => {
|
|
90
99
|
routes[page.id] = {
|
|
91
100
|
id: page.id,
|
|
92
|
-
path: page.
|
|
93
|
-
absPath: page.
|
|
101
|
+
path: page.absPath.slice(1),
|
|
102
|
+
absPath: page.absPath,
|
|
94
103
|
file: page.file,
|
|
95
104
|
parentId: "DocLayout"
|
|
96
105
|
};
|
|
97
106
|
});
|
|
98
|
-
routes["404"].file =
|
|
107
|
+
routes["404"].file = (0, import_utils.myResolve)("../pages/404.tsx");
|
|
99
108
|
return routes;
|
|
100
109
|
});
|
|
110
|
+
api.addTmpGenerateWatcherPaths(() => [path.resolve(process.cwd(), "examples")]);
|
|
101
111
|
};
|
|
102
112
|
// Annotate the CommonJS export names for ESM import in node:
|
|
103
113
|
0 && (module.exports = {});
|
|
@@ -0,0 +1,46 @@
|
|
|
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/plugin/utils.ts
|
|
23
|
+
var utils_exports = {};
|
|
24
|
+
__export(utils_exports, {
|
|
25
|
+
myResolve: () => myResolve
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(utils_exports);
|
|
28
|
+
var path = __toESM(require("path"));
|
|
29
|
+
function myResolve(p, alternateExts = [".js"]) {
|
|
30
|
+
const extname2 = path.extname(p);
|
|
31
|
+
const pathname = p.slice(0, p.length - extname2.length);
|
|
32
|
+
const exts = [extname2, ...alternateExts];
|
|
33
|
+
for (let i = 0; i < exts.length; i++) {
|
|
34
|
+
const ext = exts[i];
|
|
35
|
+
const fullpath = `${pathname}${ext}`;
|
|
36
|
+
try {
|
|
37
|
+
return require.resolve(fullpath);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
myResolve
|
|
46
|
+
});
|
|
@@ -19,7 +19,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
19
19
|
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); }
|
|
20
20
|
|
|
21
21
|
import React, { useEffect, useState } from 'react';
|
|
22
|
-
import { CodeSandboxOutlined, PlayCircleOutlined, ThunderboltOutlined
|
|
22
|
+
import { CodeSandboxOutlined, PlayCircleOutlined, ThunderboltOutlined } from '@ant-design/icons';
|
|
23
23
|
import { Typography, Tooltip } from 'antd';
|
|
24
24
|
import { useLocale } from 'dumi';
|
|
25
25
|
import { getParameters } from 'codesandbox/lib/api/define';
|
|
@@ -68,8 +68,8 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
68
68
|
updateRiddleVisible = _useState2[1];
|
|
69
69
|
|
|
70
70
|
useEffect(function () {
|
|
71
|
-
ping(function (status) {
|
|
72
|
-
updateRiddleVisible(status === 'responded');
|
|
71
|
+
ping().then(function (status) {
|
|
72
|
+
return updateRiddleVisible(status === 'responded');
|
|
73
73
|
});
|
|
74
74
|
}, []);
|
|
75
75
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -129,19 +129,7 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
129
129
|
style: {
|
|
130
130
|
marginLeft: 6
|
|
131
131
|
}
|
|
132
|
-
}),
|
|
133
|
-
title: isFullScreen ? useT('离开全屏') : useT('进入全屏')
|
|
134
|
-
}, isFullScreen ? /*#__PURE__*/React.createElement(FullscreenExitOutlined, {
|
|
135
|
-
onClick: onToggleFullscreen,
|
|
136
|
-
style: {
|
|
137
|
-
marginLeft: 12
|
|
138
|
-
}
|
|
139
|
-
}) : /*#__PURE__*/React.createElement(FullscreenOutlined, {
|
|
140
|
-
onClick: onToggleFullscreen,
|
|
141
|
-
style: {
|
|
142
|
-
marginLeft: 12
|
|
143
|
-
}
|
|
144
|
-
})) : null, /*#__PURE__*/React.createElement(Tooltip, {
|
|
132
|
+
}), /*#__PURE__*/React.createElement(Tooltip, {
|
|
145
133
|
title: useT('执行代码')
|
|
146
134
|
}, /*#__PURE__*/React.createElement(PlayCircleOutlined, {
|
|
147
135
|
onClick: onExecuteCode,
|
|
@@ -14,8 +14,10 @@ import React, { useRef, useState, useCallback, useEffect } from 'react';
|
|
|
14
14
|
import MonacoEditor, { loader } from '@monaco-editor/react';
|
|
15
15
|
import { useSiteData, useLocale } from 'dumi';
|
|
16
16
|
import { debounce, noop } from 'lodash-es';
|
|
17
|
+
import { bind, clear } from 'size-sensor';
|
|
17
18
|
import { replaceInsertCss, execute, compile } from "./utils";
|
|
18
19
|
import { Toolbar, EDITOR_TABS } from "./Toolbar";
|
|
20
|
+
import { Loading } from "../Loading";
|
|
19
21
|
import styles from "./index.module.less";
|
|
20
22
|
loader.config({
|
|
21
23
|
'vs/nls': {
|
|
@@ -85,29 +87,43 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
85
87
|
window.dispatchEvent(e);
|
|
86
88
|
};
|
|
87
89
|
|
|
90
|
+
var reportError = useCallback(function (e) {
|
|
91
|
+
if (e) {
|
|
92
|
+
console.log(e);
|
|
93
|
+
onError(e);
|
|
94
|
+
e.preventDefault && e.preventDefault();
|
|
95
|
+
} else {
|
|
96
|
+
onError(null);
|
|
97
|
+
}
|
|
98
|
+
}, []);
|
|
88
99
|
useEffect(function () {
|
|
89
100
|
// 用于上报错误信息,使用 script 执行代码
|
|
90
101
|
if (typeof window !== 'undefined') {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
// Cath error of code.
|
|
103
|
+
window.__reportErrorInPlayground = reportError; // Catch error of timeout/raf.
|
|
104
|
+
|
|
105
|
+
window.onerror = reportError; // Catch error of promise.
|
|
106
|
+
|
|
107
|
+
window.addEventListener('unhandledrejection', reportError);
|
|
97
108
|
}
|
|
98
|
-
|
|
109
|
+
|
|
110
|
+
return function () {
|
|
111
|
+
if (window) {
|
|
112
|
+
window.__reportErrorInPlayground = undefined;
|
|
113
|
+
window.onerror = undefined;
|
|
114
|
+
window.removeEventListener('unhandledrejection', reportError);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}, []);
|
|
99
118
|
var executeCode = useCallback(debounce(function (v) {
|
|
100
119
|
if (!v) return; // 1. 先编译代码
|
|
101
120
|
|
|
102
121
|
var compiled;
|
|
103
122
|
|
|
104
123
|
try {
|
|
105
|
-
compiled = compile(replaceInsertCss(v, locale.id), relativePath);
|
|
106
|
-
|
|
107
|
-
onError(null);
|
|
124
|
+
compiled = compile(replaceInsertCss(v, locale.id), relativePath);
|
|
108
125
|
} catch (e) {
|
|
109
|
-
|
|
110
|
-
onError(e); // 执行出错,后面的步骤不用做了!
|
|
126
|
+
reportError(e); // 执行出错,后面的步骤不用做了!
|
|
111
127
|
|
|
112
128
|
return;
|
|
113
129
|
} // 2. 执行代码,try catch 在内部已经做了
|
|
@@ -122,6 +138,10 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
122
138
|
executeCode(code);
|
|
123
139
|
}, [code]);
|
|
124
140
|
useEffect(function () {
|
|
141
|
+
var dom = document.getElementById('playgroundScriptContainer');
|
|
142
|
+
bind(dom, debounce(function () {
|
|
143
|
+
dispatchResizeEvent();
|
|
144
|
+
}, 100));
|
|
125
145
|
onReady();
|
|
126
146
|
|
|
127
147
|
if (playground !== null && playground !== void 0 && playground.playgroundDidMount) {
|
|
@@ -129,6 +149,7 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
129
149
|
}
|
|
130
150
|
|
|
131
151
|
return function () {
|
|
152
|
+
clear(dom);
|
|
132
153
|
onDestroy();
|
|
133
154
|
|
|
134
155
|
if (playground !== null && playground !== void 0 && playground.playgroundWillUnmount) {
|
|
@@ -149,6 +170,11 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
149
170
|
});
|
|
150
171
|
}
|
|
151
172
|
}, []);
|
|
173
|
+
useEffect(function () {
|
|
174
|
+
if (monacoRef.current) {
|
|
175
|
+
monacoRef.current.setValue(currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2));
|
|
176
|
+
}
|
|
177
|
+
}, [currentEditorTab]);
|
|
152
178
|
var onCodeChange = useCallback(function (value) {
|
|
153
179
|
if (currentEditorTab === EDITOR_TABS.JAVASCRIPT) {
|
|
154
180
|
setCode(value);
|
|
@@ -177,9 +203,9 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
177
203
|
}
|
|
178
204
|
}, /*#__PURE__*/React.createElement(MonacoEditor, {
|
|
179
205
|
language: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? 'javascript' : 'json',
|
|
180
|
-
value:
|
|
206
|
+
value: code,
|
|
181
207
|
path: relativePath,
|
|
182
|
-
loading:
|
|
208
|
+
loading: /*#__PURE__*/React.createElement(Loading, null),
|
|
183
209
|
options: {
|
|
184
210
|
readOnly: currentEditorTab === EDITOR_TABS.DATA,
|
|
185
211
|
automaticLayout: true,
|
|
@@ -135,7 +135,7 @@ export function execute(code, playgroundScriptContainer, container) {
|
|
|
135
135
|
var script = document.createElement('script'); // replace container id in case of multi demos in document
|
|
136
136
|
|
|
137
137
|
var newCode = code.replace(/'container'|"container"/, "'".concat(replaceId, "'"));
|
|
138
|
-
script.innerHTML = "\n// Can only have one anonymous define call per script file\n// \u548C monaco loader \u52A0\u8F7D\u51B2\u7A81\nvar __runnerDefine = window['define'];\nwindow['define'] = null;\ntry {\n ".concat(newCode, "\n\n window.__reportErrorInPlayground && window.__reportErrorInPlayground(null);\n} catch(e) {\n window.__reportErrorInPlayground && window.__reportErrorInPlayground(e);\n} finally {\n window['define'] = __runnerDefine;\n}\n "); // 追加图表容器
|
|
138
|
+
script.innerHTML = "\n// Can only have one anonymous define call per script file\n// \u548C monaco loader \u52A0\u8F7D\u51B2\u7A81\nvar __runnerDefine = window['define'];\nwindow['define'] = null;\ntry {\n ".concat(newCode, "\n\n // \u6E05\u9664\u663E\u793A\u7684\u9519\u8BEF\n window.__reportErrorInPlayground && window.__reportErrorInPlayground(null);\n} catch(e) {\n window.__reportErrorInPlayground && window.__reportErrorInPlayground(e);\n} finally {\n window['define'] = __runnerDefine;\n}\n "); // 追加图表容器
|
|
139
139
|
|
|
140
140
|
node.innerHTML = container || "<div id=".concat(replaceId, " />"); // 运行 script
|
|
141
141
|
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { PageHeader, Tooltip, Space, Divider } from 'antd';
|
|
3
3
|
import { EditOutlined } from '@ant-design/icons';
|
|
4
4
|
import { useT } from "../hooks";
|
|
5
|
-
import {
|
|
5
|
+
import { getGithubSourceURL } from "../utils";
|
|
6
6
|
import styles from "./CodeHeader.module.less";
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -18,7 +18,7 @@ export var CodeHeader = function CodeHeader(_ref) {
|
|
|
18
18
|
subTitle: /*#__PURE__*/React.createElement(Tooltip, {
|
|
19
19
|
title: useT('在 GitHub 上编辑')
|
|
20
20
|
}, /*#__PURE__*/React.createElement("a", {
|
|
21
|
-
href:
|
|
21
|
+
href: getGithubSourceURL(githubUrl, relativePath, 'examples'),
|
|
22
22
|
target: "_blank",
|
|
23
23
|
rel: "noopener noreferrer",
|
|
24
24
|
className: styles.editOnGtiHubButton
|
|
@@ -24,6 +24,6 @@ export var CodePreview = function CodePreview(_ref) {
|
|
|
24
24
|
className: styles.result,
|
|
25
25
|
status: "error",
|
|
26
26
|
title: useT('演示代码报错,请检查'),
|
|
27
|
-
subTitle: /*#__PURE__*/React.createElement("pre", null, error && error.
|
|
27
|
+
subTitle: /*#__PURE__*/React.createElement("pre", null, error && error.toString())
|
|
28
28
|
}) : null));
|
|
29
29
|
};
|
|
@@ -10,21 +10,22 @@
|
|
|
10
10
|
flex-direction: column;
|
|
11
11
|
|
|
12
12
|
.header {
|
|
13
|
-
flex: 0
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
.content {
|
|
17
|
-
width: 100%;
|
|
18
|
-
height: 100%;
|
|
19
16
|
position: relative;
|
|
17
|
+
flex: 1;
|
|
18
|
+
min-height: 0;
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
flex: 1;
|
|
20
|
+
:global(#playgroundScriptContainer) {
|
|
23
21
|
position: relative;
|
|
22
|
+
width: 100%;
|
|
23
|
+
height: 100%;
|
|
24
|
+
|
|
24
25
|
:global(#container) {
|
|
26
|
+
position: relative;
|
|
25
27
|
width: 100%;
|
|
26
28
|
height: 100%;
|
|
27
|
-
position: relative;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ExampleTopic } from '../../types';
|
|
3
3
|
declare type CodeRunnerProps = {
|
|
4
4
|
topic: string;
|
|
5
5
|
example: string;
|
|
6
6
|
demo: string;
|
|
7
|
-
exampleTopics:
|
|
7
|
+
exampleTopics: ExampleTopic[];
|
|
8
|
+
size?: number;
|
|
8
9
|
notFound?: React.Element;
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
@@ -28,6 +28,7 @@ export var CodeRunner = function CodeRunner(_ref) {
|
|
|
28
28
|
topic = _ref.topic,
|
|
29
29
|
example = _ref.example,
|
|
30
30
|
demo = _ref.demo,
|
|
31
|
+
size = _ref.size,
|
|
31
32
|
_ref$notFound = _ref.notFound,
|
|
32
33
|
notFound = _ref$notFound === void 0 ? /*#__PURE__*/React.createElement(NotFound, null) : _ref$notFound;
|
|
33
34
|
var demoInfo = getDemoInfo(exampleTopics, topic, example, demo); // 找不到,啥也别干了,404 页面
|
|
@@ -40,7 +41,8 @@ export var CodeRunner = function CodeRunner(_ref) {
|
|
|
40
41
|
var _useSiteData = useSiteData(),
|
|
41
42
|
themeConfig = _useSiteData.themeConfig;
|
|
42
43
|
|
|
43
|
-
var githubUrl = themeConfig.githubUrl
|
|
44
|
+
var githubUrl = themeConfig.githubUrl,
|
|
45
|
+
playground = themeConfig.playground;
|
|
44
46
|
|
|
45
47
|
var _useState = useState(),
|
|
46
48
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -60,7 +62,7 @@ export var CodeRunner = function CodeRunner(_ref) {
|
|
|
60
62
|
});
|
|
61
63
|
return /*#__PURE__*/React.createElement(SplitPane, {
|
|
62
64
|
split: "vertical",
|
|
63
|
-
defaultSize: "
|
|
65
|
+
defaultSize: "".concat((1 - size) * 100, "%"),
|
|
64
66
|
minSize: 100
|
|
65
67
|
}, /*#__PURE__*/React.createElement(CodePreview, {
|
|
66
68
|
error: error,
|
|
@@ -71,6 +73,7 @@ export var CodeRunner = function CodeRunner(_ref) {
|
|
|
71
73
|
onError: setError,
|
|
72
74
|
onFullscreen: setFullscreen,
|
|
73
75
|
onDestroy: noop,
|
|
74
|
-
onReady: noop
|
|
76
|
+
onReady: noop,
|
|
77
|
+
playground: playground
|
|
75
78
|
}));
|
|
76
79
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Demo, ExampleTopic } from '../../types';
|
|
1
2
|
/**
|
|
2
3
|
* 将数据结构转化成 map,便于后续检索的速度
|
|
3
4
|
* @param exampleTopics
|
|
4
5
|
* @returns
|
|
5
6
|
*/
|
|
6
|
-
export declare function getExampleTopicMap(exampleTopics:
|
|
7
|
+
export declare function getExampleTopicMap(exampleTopics: ExampleTopic[]): Map<string, Demo>;
|
|
7
8
|
/**
|
|
8
9
|
* 从 Context 信息中,获取到 Example 相关的信息,用于页面渲染
|
|
9
10
|
*/
|
|
10
|
-
export declare function getDemoInfo(exampleTopics:
|
|
11
|
+
export declare function getDemoInfo(exampleTopics: ExampleTopic[], topic: string, example: string, demo: string): Demo;
|
|
@@ -5,12 +5,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
7
|
import { map } from 'lodash-es';
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* 将数据结构转化成 map,便于后续检索的速度
|
|
10
11
|
* @param exampleTopics
|
|
11
12
|
* @returns
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
export function getExampleTopicMap(exampleTopics) {
|
|
15
15
|
var exampleTopicMap = new Map();
|
|
16
16
|
map(exampleTopics, function (topic) {
|
|
@@ -81,7 +81,7 @@ export var Detail = function Detail(_ref) {
|
|
|
81
81
|
link = _ref2.link,
|
|
82
82
|
shape = _ref2.shape;
|
|
83
83
|
return /*#__PURE__*/React.createElement("a", {
|
|
84
|
-
key: text,
|
|
84
|
+
key: ic(text),
|
|
85
85
|
className: cx(styles.buttonLink, styles[type || ''], type === 'primary' ? 'primary-button' : 'common-button'),
|
|
86
86
|
style: _objectSpread({
|
|
87
87
|
borderRadius: shape === 'square' ? '4px' : '1000px'
|
|
@@ -1,52 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
source: string;
|
|
4
|
-
examples: PlayGroundItemProps[];
|
|
5
|
-
babeledSource: string;
|
|
6
|
-
absolutePath?: string;
|
|
7
|
-
relativePath?: string;
|
|
8
|
-
screenshot?: string;
|
|
9
|
-
recommended?: boolean;
|
|
10
|
-
filename: string;
|
|
11
|
-
title?: string;
|
|
12
|
-
location?: Location;
|
|
13
|
-
playground?: {
|
|
14
|
-
container?: string;
|
|
15
|
-
playgroundDidMount?: string;
|
|
16
|
-
playgroundWillUnmount?: string;
|
|
17
|
-
dependencies?: {
|
|
18
|
-
[key: string]: string;
|
|
19
|
-
};
|
|
20
|
-
devDependencies?: {
|
|
21
|
-
[key: string]: string;
|
|
22
|
-
};
|
|
23
|
-
htmlCodeTemplate?: string;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export interface TreeItem {
|
|
27
|
-
title?: string;
|
|
28
|
-
value?: string;
|
|
29
|
-
key?: string;
|
|
30
|
-
children?: any;
|
|
31
|
-
icon?: string;
|
|
32
|
-
relativePath?: string;
|
|
33
|
-
filename?: string;
|
|
34
|
-
screenshot?: string;
|
|
35
|
-
node?: any;
|
|
36
|
-
}
|
|
2
|
+
import { Demo, ExampleTopic } from '../../types';
|
|
37
3
|
export interface ExampleSiderProps {
|
|
38
4
|
/**
|
|
39
5
|
* 当前 Example (受控)
|
|
40
6
|
*/
|
|
41
|
-
currentDemo:
|
|
7
|
+
currentDemo: Demo;
|
|
42
8
|
/**
|
|
43
9
|
* 当选中的 Demo 被改变时做些什么
|
|
44
10
|
*/
|
|
45
|
-
onDemoClicked: (demo:
|
|
11
|
+
onDemoClicked: (demo: Demo) => void;
|
|
46
12
|
/**
|
|
47
13
|
* 所有的案例主题
|
|
48
14
|
*/
|
|
49
|
-
exampleTopics:
|
|
15
|
+
exampleTopics: ExampleTopic[];
|
|
50
16
|
showExampleDemoTitle: boolean;
|
|
51
17
|
}
|
|
52
18
|
/**
|
|
@@ -4,14 +4,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
-
|
|
9
|
-
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."); }
|
|
10
|
-
|
|
11
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
-
|
|
13
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
14
|
-
|
|
15
7
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
8
|
|
|
17
9
|
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."); }
|
|
@@ -24,15 +16,15 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
24
16
|
|
|
25
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
26
18
|
|
|
27
|
-
import { Input, Menu, Tooltip } from 'antd';
|
|
28
19
|
import React, { useEffect, useRef, useState } from 'react';
|
|
20
|
+
import { Input, Menu, Tooltip } from 'antd';
|
|
29
21
|
import { useLocale } from 'dumi';
|
|
30
22
|
import { createFromIconfontCN, SearchOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
|
|
31
23
|
import classNames from 'classnames';
|
|
32
|
-
import { reduce, size } from 'lodash-es';
|
|
33
24
|
import { useT } from "../hooks";
|
|
34
|
-
import
|
|
35
|
-
// menu icon
|
|
25
|
+
import { filterTreeNode } from "../utils";
|
|
26
|
+
import styles from "./index.module.less"; // menu icon
|
|
27
|
+
|
|
36
28
|
var MenuIcon = createFromIconfontCN({
|
|
37
29
|
scriptUrl: '//at.alicdn.com/t/font_470089_1lnym745udm.js' // generated by iconfont.cn
|
|
38
30
|
|
|
@@ -64,37 +56,23 @@ export var ExampleSider = function ExampleSider(props) {
|
|
|
64
56
|
searchValue = _useState6[0],
|
|
65
57
|
setSearchValue = _useState6[1];
|
|
66
58
|
|
|
67
|
-
var locale = useLocale();
|
|
68
|
-
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return value;
|
|
85
|
-
}, []);
|
|
86
|
-
}; // 获取默认展开的keys数组 传入treeData 和 底层的 key 返回符合条件的 keys
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var getDefaultOpenKeys = function getDefaultOpenKeys(data, key) {
|
|
90
|
-
return reduce(data, function (value, item) {
|
|
91
|
-
if (item.children) {
|
|
92
|
-
var keys = getDefaultOpenKeys(item.children, key);
|
|
93
|
-
return keys.length ? [].concat(_toConsumableArray(value), [item.value], _toConsumableArray(keys)) : value;
|
|
94
|
-
}
|
|
59
|
+
var locale = useLocale();
|
|
60
|
+
|
|
61
|
+
var getCurrentTopics = function getCurrentTopics() {
|
|
62
|
+
if (searchValue) {
|
|
63
|
+
var res = filterTreeNode({
|
|
64
|
+
id: 'FAKE_ID',
|
|
65
|
+
childrenKey: 'exampleTopics',
|
|
66
|
+
title: {
|
|
67
|
+
'zh': 'FAKE_TITLE',
|
|
68
|
+
'en': 'FAKE_TITLE'
|
|
69
|
+
},
|
|
70
|
+
exampleTopics: exampleTopics
|
|
71
|
+
}, searchValue, locale.id);
|
|
72
|
+
return (res === null || res === void 0 ? void 0 : res.exampleTopics) || [];
|
|
73
|
+
}
|
|
95
74
|
|
|
96
|
-
|
|
97
|
-
}, []);
|
|
75
|
+
return exampleTopics;
|
|
98
76
|
}; // 初始化菜单栏展开keys
|
|
99
77
|
|
|
100
78
|
|
|
@@ -142,7 +120,7 @@ export var ExampleSider = function ExampleSider(props) {
|
|
|
142
120
|
};
|
|
143
121
|
|
|
144
122
|
var renderSubMenu = function renderSubMenu() {
|
|
145
|
-
return
|
|
123
|
+
return getCurrentTopics().map(function (topic) {
|
|
146
124
|
return /*#__PURE__*/React.createElement(Menu.SubMenu, {
|
|
147
125
|
key: "TOPIC-".concat(topic.id),
|
|
148
126
|
title: /*#__PURE__*/React.createElement("div", null, topic.icon && /*#__PURE__*/React.createElement(MenuIcon, {
|
|
@@ -208,7 +186,7 @@ export var ExampleSider = function ExampleSider(props) {
|
|
|
208
186
|
style: {
|
|
209
187
|
width: '100%'
|
|
210
188
|
},
|
|
211
|
-
className: styles.
|
|
189
|
+
className: styles.sideBarMenu,
|
|
212
190
|
openKeys: openKeys,
|
|
213
191
|
selectedKeys: ["DEMO-".concat(currentDemo.id)],
|
|
214
192
|
onOpenChange: function onOpenChange(keys) {
|