@antv/dumi-theme-antv 0.3.0-beta.2 → 0.3.0-beta.22
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 +3 -6
- package/dist/builtins/Playground/index.js +27 -7
- package/dist/context.d.ts +2 -1
- package/dist/layouts/DocLayout.js +25 -16
- package/dist/layouts/entry/Index.js +21 -12
- package/dist/layouts/entry/Manual.js +6 -4
- package/dist/pages/404.js +7 -4
- package/dist/pages/Example/index.js +31 -55
- 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/ExampleTopicMenu/components/LeftMenu/index.js +6 -1
- package/dist/pages/Examples/components/GalleryPageContent/DemoCard/index.js +11 -6
- package/dist/pages/Examples/index.js +24 -4
- package/dist/pages/Examples/index.module.less +15 -0
- package/dist/pages/Examples/types.d.ts +7 -6
- package/dist/plugin/examples.d.ts +14 -5
- package/dist/plugin/examples.js +17 -3
- package/dist/plugin/index.js +31 -8
- package/dist/plugin/utils.js +3 -2
- package/dist/slots/Article/index.d.ts +3 -0
- package/dist/slots/Article/index.js +11 -0
- package/dist/slots/Article/index.module.less +8 -0
- package/dist/slots/Banner/Notification.d.ts +10 -0
- package/dist/slots/Banner/Notification.js +43 -0
- package/dist/slots/Banner/Notification.module.less +120 -0
- package/dist/slots/Banner/index.d.ts +26 -0
- package/dist/slots/Banner/index.js +184 -0
- package/dist/slots/Banner/index.module.less +449 -0
- package/dist/slots/Cases/index.d.ts +1 -0
- package/dist/slots/Cases/index.js +13 -7
- package/dist/slots/Cases/index.module.less +2 -1
- package/dist/slots/CodeEditor/Toolbar.js +17 -22
- package/dist/slots/CodeEditor/index.d.ts +4 -0
- package/dist/slots/CodeEditor/index.js +71 -23
- package/dist/slots/CodeEditor/utils.js +2 -2
- package/dist/slots/CodePreview/CodeHeader.js +15 -14
- package/dist/slots/CodePreview/index.d.ts +8 -0
- package/dist/slots/CodePreview/index.js +15 -6
- package/dist/slots/CodePreview/index.module.less +17 -7
- package/dist/slots/CodeRunner/index.d.ts +5 -2
- package/dist/slots/CodeRunner/index.js +19 -8
- package/dist/slots/CodeRunner/utils.d.ts +3 -2
- package/dist/slots/CodeRunner/utils.js +1 -1
- package/dist/slots/Companies/index.d.ts +1 -1
- package/dist/slots/{TOC.d.ts → ContentTable/index.d.ts} +2 -1
- package/dist/slots/{TOC.js → ContentTable/index.js} +2 -1
- package/dist/slots/ContentTable/index.module.less +11 -0
- package/dist/slots/Detail/News.d.ts +1 -0
- package/dist/slots/Detail/News.js +3 -2
- package/dist/slots/Detail/index.d.ts +1 -0
- package/dist/slots/Detail/index.js +4 -2
- package/dist/slots/ExampleSider/index.d.ts +4 -38
- package/dist/slots/ExampleSider/index.js +28 -49
- package/dist/slots/ExampleSider/index.module.less +1 -1
- package/dist/slots/Features/FeatureCard.d.ts +1 -0
- package/dist/slots/Features/index.js +7 -3
- package/dist/slots/Features/index.module.less +1 -1
- package/dist/slots/Footer/index.js +34 -14
- package/dist/slots/Header/LogoWhite.js +1 -2
- package/dist/slots/Header/Navs.d.ts +10 -1
- package/dist/slots/Header/Navs.js +36 -19
- package/dist/slots/Header/Products/NavigatorBanner.js +4 -3
- package/dist/slots/Header/Products/Product.js +7 -3
- package/dist/slots/Header/Products/index.js +5 -3
- package/dist/slots/Header/Search.js +5 -3
- package/dist/slots/Header/index.d.ts +7 -2
- package/dist/slots/Header/index.js +135 -30
- 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/NavigatorBanner.js +5 -3
- package/dist/slots/ManualContent/ReadingTime.js +6 -2
- package/dist/slots/ManualContent/index.js +143 -126
- package/dist/slots/ManualContent/index.module.less +52 -33
- package/dist/slots/ManualContent/utils.d.ts +18 -0
- package/dist/slots/ManualContent/utils.js +64 -0
- package/dist/slots/SEO.d.ts +10 -0
- package/dist/slots/SEO.js +59 -0
- package/dist/slots/_.less +1 -1
- package/dist/slots/hooks.d.ts +4 -4
- package/dist/slots/hooks.js +5 -8
- package/dist/slots/utils.d.ts +4 -19
- package/dist/slots/utils.js +82 -119
- package/dist/types.d.ts +83 -0
- package/dist/typings.d.ts +0 -116
- package/package.json +9 -5
- package/dist/slots/Loading.d.ts +0 -5
- package/dist/slots/Loading.js +0 -8
|
@@ -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 "dumi/theme/slots/Loading";
|
|
19
21
|
import styles from "./index.module.less";
|
|
20
22
|
loader.config({
|
|
21
23
|
'vs/nls': {
|
|
@@ -41,6 +43,7 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
41
43
|
_ref$replaceId = _ref.replaceId,
|
|
42
44
|
replaceId = _ref$replaceId === void 0 ? 'container' : _ref$replaceId,
|
|
43
45
|
isFullscreen = _ref.isFullscreen,
|
|
46
|
+
exampleId = _ref.exampleId,
|
|
44
47
|
_ref$onReady = _ref.onReady,
|
|
45
48
|
onReady = _ref$onReady === void 0 ? noop : _ref$onReady,
|
|
46
49
|
_ref$onDestroy = _ref.onDestroy,
|
|
@@ -77,50 +80,82 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
77
80
|
var _useState7 = useState(EDITOR_TABS.JAVASCRIPT),
|
|
78
81
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
79
82
|
currentEditorTab = _useState8[0],
|
|
80
|
-
setCurrentEditorTab = _useState8[1];
|
|
83
|
+
setCurrentEditorTab = _useState8[1];
|
|
81
84
|
|
|
85
|
+
var containerId = "playgroundScriptContainer_".concat(exampleId); // 出发 auto resize
|
|
82
86
|
|
|
83
87
|
var dispatchResizeEvent = function dispatchResizeEvent() {
|
|
84
88
|
var e = new Event('resize');
|
|
85
89
|
window.dispatchEvent(e);
|
|
86
90
|
};
|
|
87
91
|
|
|
92
|
+
var reportError = useCallback(function (e) {
|
|
93
|
+
if (e) {
|
|
94
|
+
console.log(e);
|
|
95
|
+
onError(e);
|
|
96
|
+
e.preventDefault && e.preventDefault();
|
|
97
|
+
} else {
|
|
98
|
+
onError(null);
|
|
99
|
+
}
|
|
100
|
+
}, []);
|
|
88
101
|
useEffect(function () {
|
|
89
102
|
// 用于上报错误信息,使用 script 执行代码
|
|
90
103
|
if (typeof window !== 'undefined') {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
// Cath error of code.
|
|
105
|
+
window.__reportErrorInPlayground = reportError; // Catch error of timeout/raf.
|
|
106
|
+
|
|
107
|
+
window.onerror = reportError; // Catch error of promise.
|
|
108
|
+
|
|
109
|
+
window.addEventListener('unhandledrejection', reportError);
|
|
97
110
|
}
|
|
98
|
-
|
|
111
|
+
|
|
112
|
+
return function () {
|
|
113
|
+
if (window) {
|
|
114
|
+
window.__reportErrorInPlayground = undefined;
|
|
115
|
+
window.onerror = undefined;
|
|
116
|
+
window.removeEventListener('unhandledrejection', reportError);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}, []);
|
|
99
120
|
var executeCode = useCallback(debounce(function (v) {
|
|
121
|
+
if (currentEditorTab !== EDITOR_TABS.JAVASCRIPT) return;
|
|
100
122
|
if (!v) return; // 1. 先编译代码
|
|
101
123
|
|
|
102
124
|
var compiled;
|
|
103
125
|
|
|
104
126
|
try {
|
|
105
|
-
compiled = compile(replaceInsertCss(v, locale.id), relativePath);
|
|
106
|
-
|
|
107
|
-
onError(null);
|
|
127
|
+
compiled = compile(replaceInsertCss(v, locale.id), relativePath);
|
|
108
128
|
} catch (e) {
|
|
109
|
-
|
|
110
|
-
onError(e); // 执行出错,后面的步骤不用做了!
|
|
129
|
+
reportError(e); // 执行出错,后面的步骤不用做了!
|
|
111
130
|
|
|
112
131
|
return;
|
|
113
132
|
} // 2. 执行代码,try catch 在内部已经做了
|
|
114
133
|
|
|
115
134
|
|
|
116
|
-
execute(compiled,
|
|
117
|
-
}, 300), []);
|
|
135
|
+
execute(compiled, containerId, playground === null || playground === void 0 ? void 0 : playground.container, replaceId);
|
|
136
|
+
}, 300), [exampleId, currentEditorTab]); // 案例变化的时候,修改期待吗
|
|
137
|
+
|
|
118
138
|
useEffect(function () {
|
|
119
139
|
setCode(source);
|
|
120
|
-
}, [
|
|
140
|
+
}, [exampleId]); // 代码变化的时候,运行代码
|
|
141
|
+
|
|
121
142
|
useEffect(function () {
|
|
122
143
|
executeCode(code);
|
|
123
144
|
}, [code]);
|
|
145
|
+
useEffect(function () {
|
|
146
|
+
var dom = document.getElementById(containerId);
|
|
147
|
+
|
|
148
|
+
if (dom) {
|
|
149
|
+
bind(dom, debounce(function () {
|
|
150
|
+
dispatchResizeEvent();
|
|
151
|
+
}, 100));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return function () {
|
|
155
|
+
dom && clear(dom);
|
|
156
|
+
};
|
|
157
|
+
}, []); // 生命周期
|
|
158
|
+
|
|
124
159
|
useEffect(function () {
|
|
125
160
|
onReady();
|
|
126
161
|
|
|
@@ -147,13 +182,25 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
147
182
|
setEditorTabs([EDITOR_TABS.JAVASCRIPT, EDITOR_TABS.DATA]);
|
|
148
183
|
setData(data);
|
|
149
184
|
});
|
|
185
|
+
} else {
|
|
186
|
+
setEditorTabs([EDITOR_TABS.JAVASCRIPT]);
|
|
150
187
|
}
|
|
151
|
-
}, []);
|
|
152
|
-
|
|
153
|
-
|
|
188
|
+
}, [exampleId]); // 切换 tab
|
|
189
|
+
|
|
190
|
+
var onTabChange = useCallback(function (tab) {
|
|
191
|
+
setCurrentEditorTab(tab);
|
|
192
|
+
}, [exampleId]); // useEffect(() => {
|
|
193
|
+
// if (monacoRef.current) {
|
|
194
|
+
// const v = currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2);
|
|
195
|
+
// monacoRef.current.setValue(v);
|
|
196
|
+
// }
|
|
197
|
+
// }, [currentEditorTab]);
|
|
198
|
+
|
|
199
|
+
var onCodeChange = useCallback(function (value, event) {
|
|
200
|
+
if (!event.isFlush && currentEditorTab === EDITOR_TABS.JAVASCRIPT) {
|
|
154
201
|
setCode(value);
|
|
155
202
|
}
|
|
156
|
-
}, []);
|
|
203
|
+
}, [currentEditorTab]);
|
|
157
204
|
return /*#__PURE__*/React.createElement("div", {
|
|
158
205
|
className: styles.editor
|
|
159
206
|
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
@@ -168,7 +215,7 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
168
215
|
onExecuteCode: function onExecuteCode() {
|
|
169
216
|
return executeCode(code);
|
|
170
217
|
},
|
|
171
|
-
onEditorTabChange:
|
|
218
|
+
onEditorTabChange: onTabChange,
|
|
172
219
|
onToggleFullscreen: onFullscreen
|
|
173
220
|
}), /*#__PURE__*/React.createElement("div", {
|
|
174
221
|
className: styles.monaco,
|
|
@@ -177,9 +224,10 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
177
224
|
}
|
|
178
225
|
}, /*#__PURE__*/React.createElement(MonacoEditor, {
|
|
179
226
|
language: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? 'javascript' : 'json',
|
|
180
|
-
value: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2)
|
|
227
|
+
value: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2) // defaultValue={code}
|
|
228
|
+
,
|
|
181
229
|
path: relativePath,
|
|
182
|
-
loading:
|
|
230
|
+
loading: /*#__PURE__*/React.createElement(Loading, null),
|
|
183
231
|
options: {
|
|
184
232
|
readOnly: currentEditorTab === EDITOR_TABS.DATA,
|
|
185
233
|
automaticLayout: true,
|
|
@@ -135,9 +135,9 @@ 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
|
-
node.innerHTML = container || "<div id=".concat(replaceId, " />"); // 运行 script
|
|
140
|
+
node.innerHTML = container || "<div id=".concat(replaceId, " class=\"playgroundCodeContainer\" />"); // 运行 script
|
|
141
141
|
|
|
142
142
|
node.appendChild(script);
|
|
143
143
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { PageHeader,
|
|
3
|
-
import { EditOutlined } from '@ant-design/icons';
|
|
4
|
-
import { useT } from "../hooks";
|
|
5
|
-
import { getGithubSourceUrl } from "../utils";
|
|
6
|
-
import styles from "./CodeHeader.module.less";
|
|
2
|
+
import { PageHeader, Space, Divider } from 'antd';
|
|
7
3
|
|
|
8
4
|
/**
|
|
9
5
|
* 组件的 header
|
|
@@ -14,15 +10,20 @@ export var CodeHeader = function CodeHeader(_ref) {
|
|
|
14
10
|
githubUrl = _ref.githubUrl;
|
|
15
11
|
return /*#__PURE__*/React.createElement(PageHeader, {
|
|
16
12
|
ghost: false,
|
|
17
|
-
title: title
|
|
18
|
-
subTitle
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
title: title // todo 编辑地址各种各样,需要有单独的配置,暂时关闭!
|
|
14
|
+
// subTitle={
|
|
15
|
+
// <Tooltip title={<FormattedMessage id="在 GitHub 上编辑" />}>
|
|
16
|
+
// <a
|
|
17
|
+
// href={getGithubSourceURL(githubUrl, relativePath, 'examples')}
|
|
18
|
+
// target="_blank"
|
|
19
|
+
// rel="noopener noreferrer"
|
|
20
|
+
// className={styles.editOnGtiHubButton}
|
|
21
|
+
// >
|
|
22
|
+
// <EditOutlined />
|
|
23
|
+
// </a>
|
|
24
|
+
// </Tooltip>
|
|
25
|
+
// }
|
|
26
|
+
,
|
|
26
27
|
extra: /*#__PURE__*/React.createElement(Space, {
|
|
27
28
|
split: /*#__PURE__*/React.createElement(Divider, {
|
|
28
29
|
type: "vertical"
|
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Result } from 'antd';
|
|
3
|
-
import {
|
|
3
|
+
import { FormattedMessage } from 'dumi';
|
|
4
4
|
import styles from "./index.module.less";
|
|
5
5
|
|
|
6
|
+
function getErrorMessage(e) {
|
|
7
|
+
return (e.reason ? e.reason : e.message ? e.message : e).toString();
|
|
8
|
+
}
|
|
6
9
|
/**
|
|
7
10
|
* DEMO 预览页面的预览,主要包含有:
|
|
8
11
|
* 1. 一些 header 菜单
|
|
9
12
|
* 2. 错误预览
|
|
10
13
|
*/
|
|
14
|
+
|
|
15
|
+
|
|
11
16
|
export var CodePreview = function CodePreview(_ref) {
|
|
12
|
-
var
|
|
17
|
+
var isPlayground = _ref.isPlayground,
|
|
18
|
+
exampleId = _ref.exampleId,
|
|
19
|
+
header = _ref.header,
|
|
13
20
|
error = _ref.error;
|
|
14
21
|
return /*#__PURE__*/React.createElement("div", {
|
|
15
22
|
className: styles.preview
|
|
16
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
23
|
+
}, isPlayground ? null : /*#__PURE__*/React.createElement("div", {
|
|
17
24
|
className: styles.header
|
|
18
25
|
}, header), /*#__PURE__*/React.createElement("div", {
|
|
19
26
|
className: styles.content
|
|
20
27
|
}, /*#__PURE__*/React.createElement("div", {
|
|
21
|
-
id: "
|
|
28
|
+
id: "playgroundScriptContainer_".concat(exampleId),
|
|
22
29
|
className: styles.playgroundScriptContainer
|
|
23
30
|
}), error ? /*#__PURE__*/React.createElement(Result, {
|
|
24
31
|
className: styles.result,
|
|
25
32
|
status: "error",
|
|
26
|
-
title:
|
|
27
|
-
|
|
33
|
+
title: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
34
|
+
id: "\u6F14\u793A\u4EE3\u7801\u62A5\u9519\uFF0C\u8BF7\u68C0\u67E5"
|
|
35
|
+
}),
|
|
36
|
+
subTitle: /*#__PURE__*/React.createElement("pre", null, getErrorMessage(error))
|
|
28
37
|
}) : null));
|
|
29
38
|
};
|
|
@@ -3,28 +3,38 @@
|
|
|
3
3
|
height: 100%;
|
|
4
4
|
position: relative;
|
|
5
5
|
|
|
6
|
-
padding:
|
|
6
|
+
padding: 24px;
|
|
7
7
|
overflow: auto;
|
|
8
8
|
|
|
9
9
|
display: flex;
|
|
10
10
|
flex-direction: column;
|
|
11
11
|
|
|
12
12
|
.header {
|
|
13
|
-
|
|
13
|
+
:global(.ant-page-header) {
|
|
14
|
+
padding-left: 0;
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
.content {
|
|
17
|
-
width: 100%;
|
|
18
|
-
height: 100%;
|
|
19
19
|
position: relative;
|
|
20
|
+
flex: 1;
|
|
21
|
+
min-height: 0;
|
|
20
22
|
|
|
21
|
-
.playgroundScriptContainer {
|
|
22
|
-
flex: 1;
|
|
23
|
+
.playgroundScriptContainer, .playgroundCodeContainer {
|
|
23
24
|
position: relative;
|
|
24
|
-
:
|
|
25
|
+
width: 100%;
|
|
26
|
+
height: 100%;
|
|
27
|
+
|
|
28
|
+
:global(.playgroundCodeContainer) {
|
|
29
|
+
position: relative;
|
|
25
30
|
width: 100%;
|
|
26
31
|
height: 100%;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
:global(#container) {
|
|
27
35
|
position: relative;
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 100%;
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ExampleTopic } from '../../types';
|
|
3
3
|
declare type CodeRunnerProps = {
|
|
4
|
+
isPlayground?: boolean;
|
|
4
5
|
topic: string;
|
|
5
6
|
example: string;
|
|
6
7
|
demo: string;
|
|
7
|
-
exampleTopics:
|
|
8
|
+
exampleTopics: ExampleTopic[];
|
|
9
|
+
size?: number;
|
|
10
|
+
replaceId?: string;
|
|
8
11
|
notFound?: React.Element;
|
|
9
12
|
};
|
|
10
13
|
/**
|
|
@@ -14,11 +14,12 @@ import React, { useState } from 'react';
|
|
|
14
14
|
import { useSiteData, useLocale } from 'dumi';
|
|
15
15
|
import { noop } from 'lodash-es';
|
|
16
16
|
import SplitPane from 'react-split-pane';
|
|
17
|
-
import { CodeEditor } from "
|
|
18
|
-
import { CodePreview } from "
|
|
17
|
+
import { CodeEditor } from "dumi/theme/slots/CodeEditor";
|
|
18
|
+
import { CodePreview } from "dumi/theme/slots/CodePreview";
|
|
19
19
|
import { CodeHeader } from "../CodePreview/CodeHeader";
|
|
20
20
|
import { getDemoInfo } from "./utils";
|
|
21
|
-
import { NotFound } from "
|
|
21
|
+
import { NotFound } from "dumi/theme/slots/404";
|
|
22
|
+
import { ic } from "../hooks";
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* 代码编辑器 + 代码预览区域
|
|
@@ -28,6 +29,9 @@ export var CodeRunner = function CodeRunner(_ref) {
|
|
|
28
29
|
topic = _ref.topic,
|
|
29
30
|
example = _ref.example,
|
|
30
31
|
demo = _ref.demo,
|
|
32
|
+
size = _ref.size,
|
|
33
|
+
replaceId = _ref.replaceId,
|
|
34
|
+
isPlayground = _ref.isPlayground,
|
|
31
35
|
_ref$notFound = _ref.notFound,
|
|
32
36
|
notFound = _ref$notFound === void 0 ? /*#__PURE__*/React.createElement(NotFound, null) : _ref$notFound;
|
|
33
37
|
var demoInfo = getDemoInfo(exampleTopics, topic, example, demo); // 找不到,啥也别干了,404 页面
|
|
@@ -40,7 +44,8 @@ export var CodeRunner = function CodeRunner(_ref) {
|
|
|
40
44
|
var _useSiteData = useSiteData(),
|
|
41
45
|
themeConfig = _useSiteData.themeConfig;
|
|
42
46
|
|
|
43
|
-
var githubUrl = themeConfig.githubUrl
|
|
47
|
+
var githubUrl = themeConfig.githubUrl,
|
|
48
|
+
playground = themeConfig.playground;
|
|
44
49
|
|
|
45
50
|
var _useState = useState(),
|
|
46
51
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -54,23 +59,29 @@ export var CodeRunner = function CodeRunner(_ref) {
|
|
|
54
59
|
|
|
55
60
|
var locale = useLocale();
|
|
56
61
|
var header = /*#__PURE__*/React.createElement(CodeHeader, {
|
|
57
|
-
title: title
|
|
62
|
+
title: ic(title),
|
|
58
63
|
relativePath: relativePath,
|
|
59
64
|
githubUrl: githubUrl
|
|
60
65
|
});
|
|
66
|
+
var exampleId = "".concat(topic, "_").concat(example, "_").concat(demo);
|
|
61
67
|
return /*#__PURE__*/React.createElement(SplitPane, {
|
|
62
68
|
split: "vertical",
|
|
63
|
-
defaultSize: "
|
|
69
|
+
defaultSize: "".concat((1 - size) * 100, "%"),
|
|
64
70
|
minSize: 100
|
|
65
71
|
}, /*#__PURE__*/React.createElement(CodePreview, {
|
|
72
|
+
exampleId: exampleId,
|
|
66
73
|
error: error,
|
|
67
|
-
header: header
|
|
74
|
+
header: header,
|
|
75
|
+
isPlayground: isPlayground
|
|
68
76
|
}), /*#__PURE__*/React.createElement(CodeEditor, {
|
|
77
|
+
exampleId: exampleId,
|
|
69
78
|
source: source,
|
|
70
79
|
relativePath: relativePath,
|
|
80
|
+
replaceId: replaceId,
|
|
71
81
|
onError: setError,
|
|
72
82
|
onFullscreen: setFullscreen,
|
|
73
83
|
onDestroy: noop,
|
|
74
|
-
onReady: noop
|
|
84
|
+
onReady: noop,
|
|
85
|
+
playground: playground
|
|
75
86
|
}));
|
|
76
87
|
};
|
|
@@ -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) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Link } from 'dumi';
|
|
2
|
+
import { Link, useLocale } from 'dumi';
|
|
3
3
|
import { ic } from "../hooks";
|
|
4
4
|
import styles from "./News.module.less";
|
|
5
5
|
var numberImages = ['https://gw.alipayobjects.com/zos/antfincdn/IqREAm36K7/1.png', 'https://gw.alipayobjects.com/zos/antfincdn/3fG1Iqjfnz/2.png'];
|
|
@@ -11,6 +11,7 @@ export var News = function News(_ref) {
|
|
|
11
11
|
date = _ref.date,
|
|
12
12
|
_ref$link = _ref.link,
|
|
13
13
|
link = _ref$link === void 0 ? '' : _ref$link;
|
|
14
|
+
var lang = useLocale().id;
|
|
14
15
|
var children = /*#__PURE__*/React.createElement("div", {
|
|
15
16
|
className: styles.container
|
|
16
17
|
}, /*#__PURE__*/React.createElement("img", {
|
|
@@ -35,7 +36,7 @@ export var News = function News(_ref) {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
return /*#__PURE__*/React.createElement(Link, {
|
|
38
|
-
to: link,
|
|
39
|
+
to: link[lang] ? link[lang] : link,
|
|
39
40
|
className: styles.news
|
|
40
41
|
}, children);
|
|
41
42
|
};
|
|
@@ -22,6 +22,7 @@ import React, { useState, useEffect } from 'react';
|
|
|
22
22
|
import cx from 'classnames';
|
|
23
23
|
import gh from 'parse-github-url';
|
|
24
24
|
import GitHubButton from 'react-github-button';
|
|
25
|
+
import { useLocale } from 'dumi/dist/client/theme-api';
|
|
25
26
|
import { ic } from "../hooks";
|
|
26
27
|
import { News } from "./News";
|
|
27
28
|
import styles from "./index.module.less";
|
|
@@ -50,6 +51,7 @@ export var Detail = function Detail(_ref) {
|
|
|
50
51
|
removeNews = _useState2[0],
|
|
51
52
|
setRemoteNews = _useState2[1];
|
|
52
53
|
|
|
54
|
+
var lang = useLocale().id;
|
|
53
55
|
useEffect(function () {
|
|
54
56
|
fetch(AssetsNewsURL).then(function (res) {
|
|
55
57
|
return res.json();
|
|
@@ -81,12 +83,12 @@ export var Detail = function Detail(_ref) {
|
|
|
81
83
|
link = _ref2.link,
|
|
82
84
|
shape = _ref2.shape;
|
|
83
85
|
return /*#__PURE__*/React.createElement("a", {
|
|
84
|
-
key: text,
|
|
86
|
+
key: ic(text),
|
|
85
87
|
className: cx(styles.buttonLink, styles[type || ''], type === 'primary' ? 'primary-button' : 'common-button'),
|
|
86
88
|
style: _objectSpread({
|
|
87
89
|
borderRadius: shape === 'square' ? '4px' : '1000px'
|
|
88
90
|
}, style),
|
|
89
|
-
href: link
|
|
91
|
+
href: link[lang] ? link[lang] : link
|
|
90
92
|
}, /*#__PURE__*/React.createElement("span", {
|
|
91
93
|
className: styles.button
|
|
92
94
|
}, ic(text)));
|
|
@@ -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
|
/**
|