@antv/dumi-theme-antv 0.3.0-beta.1 → 0.3.0-beta.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/builtins/Playground/index.d.ts +2 -5
- package/dist/builtins/Playground/index.js +25 -6
- package/dist/context.d.ts +2 -1
- package/dist/layouts/DocLayout.js +25 -16
- package/dist/layouts/entry/Index.js +10 -2
- package/dist/layouts/entry/Manual.js +3 -1
- 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 +8 -5
- 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 +31 -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/Cases/index.js +1 -1
- package/dist/slots/Cases/index.module.less +2 -1
- package/dist/slots/CodeEditor/Toolbar.js +4 -16
- package/dist/slots/CodeEditor/index.d.ts +4 -0
- package/dist/slots/CodeEditor/index.js +48 -16
- 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 +6 -4
- package/dist/slots/CodePreview/index.module.less +17 -7
- package/dist/slots/CodeRunner/index.d.ts +5 -2
- package/dist/slots/CodeRunner/index.js +18 -4
- 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/Header/Navs.d.ts +10 -1
- package/dist/slots/Header/Navs.js +36 -19
- 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 +138 -113
- package/dist/slots/ManualContent/index.module.less +40 -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/{TOC.d.ts → TOC/index.d.ts} +1 -0
- package/dist/slots/{TOC.js → TOC/index.js} +1 -0
- package/dist/slots/TOC/index.module.less +11 -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 +7 -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,52 @@ __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
|
+
memo.favicons = ["https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*7svFR6wkPMoAAAAAAAAAAAAADmJ7AQ/original"];
|
|
38
|
+
return memo;
|
|
39
|
+
});
|
|
37
40
|
const pages = [
|
|
41
|
+
{
|
|
42
|
+
id: "dumi-theme-antv-homepage",
|
|
43
|
+
absPath: "/"
|
|
44
|
+
},
|
|
38
45
|
{
|
|
39
46
|
id: "dumi-theme-antv-example-list-zh",
|
|
40
|
-
|
|
41
|
-
file:
|
|
47
|
+
absPath: "/examples",
|
|
48
|
+
file: (0, import_utils.myResolve)("../pages/Examples/index.tsx")
|
|
42
49
|
},
|
|
43
50
|
{
|
|
44
51
|
id: "dumi-theme-antv-example-list-lang",
|
|
45
|
-
|
|
46
|
-
file:
|
|
52
|
+
absPath: "/:language/examples",
|
|
53
|
+
file: (0, import_utils.myResolve)("../pages/Examples/index.tsx")
|
|
47
54
|
},
|
|
48
55
|
{
|
|
49
56
|
id: "dumi-theme-antv-single-example-zh",
|
|
50
|
-
|
|
51
|
-
file:
|
|
57
|
+
absPath: "/examples/:topic/:example",
|
|
58
|
+
file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
|
|
52
59
|
},
|
|
53
60
|
{
|
|
54
61
|
id: "dumi-theme-antv-single-example-lang",
|
|
55
|
-
|
|
56
|
-
file:
|
|
62
|
+
absPath: "/:language/examples/:topic/:example",
|
|
63
|
+
file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
|
|
57
64
|
}
|
|
58
65
|
];
|
|
59
|
-
const contextFilePath =
|
|
66
|
+
const contextFilePath = (0, import_utils.myResolve)("../context.ts");
|
|
60
67
|
api.onGenerateFiles(() => {
|
|
61
68
|
api.writeTmpFile({
|
|
62
69
|
noPluginDir: true,
|
|
63
70
|
path: "theme-antv/ContextWrapper.tsx",
|
|
64
71
|
content: `
|
|
65
|
-
import
|
|
72
|
+
import React from 'react';
|
|
73
|
+
import { useOutlet, useSiteData } from 'dumi';
|
|
66
74
|
import { ThemeAntVContext } from '${contextFilePath}';
|
|
67
75
|
|
|
68
76
|
export default function ThemeAntVContextWrapper() {
|
|
@@ -71,7 +79,9 @@ export default function ThemeAntVContextWrapper() {
|
|
|
71
79
|
return (
|
|
72
80
|
<ThemeAntVContext.Provider
|
|
73
81
|
value={{
|
|
74
|
-
meta: ${JSON.stringify(
|
|
82
|
+
meta: ${JSON.stringify({
|
|
83
|
+
exampleTopics: (0, import_examples.getExamplesPageTopics)(api.config.themeConfig.examples || [])
|
|
84
|
+
})}
|
|
75
85
|
}}
|
|
76
86
|
>
|
|
77
87
|
{outlet}
|
|
@@ -89,15 +99,16 @@ export default function ThemeAntVContextWrapper() {
|
|
|
89
99
|
pages.forEach((page) => {
|
|
90
100
|
routes[page.id] = {
|
|
91
101
|
id: page.id,
|
|
92
|
-
path: page.
|
|
93
|
-
absPath: page.
|
|
102
|
+
path: page.absPath.slice(1),
|
|
103
|
+
absPath: page.absPath,
|
|
94
104
|
file: page.file,
|
|
95
105
|
parentId: "DocLayout"
|
|
96
106
|
};
|
|
97
107
|
});
|
|
98
|
-
routes["404"].file =
|
|
108
|
+
routes["404"].file = (0, import_utils.myResolve)("../pages/404.tsx");
|
|
99
109
|
return routes;
|
|
100
110
|
});
|
|
111
|
+
api.addTmpGenerateWatcherPaths(() => [path.resolve(process.cwd(), "examples")]);
|
|
101
112
|
};
|
|
102
113
|
// Annotate the CommonJS export names for ESM import in node:
|
|
103
114
|
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
|
+
});
|
|
@@ -76,7 +76,7 @@ export var Cases = function Cases(_ref) {
|
|
|
76
76
|
className: styles.appWrapper,
|
|
77
77
|
key: ic(app.title)
|
|
78
78
|
}, /*#__PURE__*/React.createElement("img", {
|
|
79
|
-
className: styles.appTeaser,
|
|
79
|
+
className: cx(styles.appTeaser, 'index-cases-image'),
|
|
80
80
|
src: app.image,
|
|
81
81
|
alt: ic(app.title)
|
|
82
82
|
}), /*#__PURE__*/React.createElement("div", {
|
|
@@ -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': {
|
|
@@ -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,43 +80,58 @@ 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) {
|
|
100
121
|
if (!v) return; // 1. 先编译代码
|
|
101
122
|
|
|
102
123
|
var compiled;
|
|
103
124
|
|
|
104
125
|
try {
|
|
105
|
-
compiled = compile(replaceInsertCss(v, locale.id), relativePath);
|
|
106
|
-
|
|
107
|
-
onError(null);
|
|
126
|
+
compiled = compile(replaceInsertCss(v, locale.id), relativePath);
|
|
108
127
|
} catch (e) {
|
|
109
|
-
|
|
110
|
-
onError(e); // 执行出错,后面的步骤不用做了!
|
|
128
|
+
reportError(e); // 执行出错,后面的步骤不用做了!
|
|
111
129
|
|
|
112
130
|
return;
|
|
113
131
|
} // 2. 执行代码,try catch 在内部已经做了
|
|
114
132
|
|
|
115
133
|
|
|
116
|
-
execute(compiled,
|
|
134
|
+
execute(compiled, containerId, playground === null || playground === void 0 ? void 0 : playground.container, replaceId);
|
|
117
135
|
}, 300), []);
|
|
118
136
|
useEffect(function () {
|
|
119
137
|
setCode(source);
|
|
@@ -122,6 +140,14 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
122
140
|
executeCode(code);
|
|
123
141
|
}, [code]);
|
|
124
142
|
useEffect(function () {
|
|
143
|
+
var dom = document.getElementById('containerId');
|
|
144
|
+
|
|
145
|
+
if (dom) {
|
|
146
|
+
bind(dom, debounce(function () {
|
|
147
|
+
dispatchResizeEvent();
|
|
148
|
+
}, 100));
|
|
149
|
+
}
|
|
150
|
+
|
|
125
151
|
onReady();
|
|
126
152
|
|
|
127
153
|
if (playground !== null && playground !== void 0 && playground.playgroundDidMount) {
|
|
@@ -129,6 +155,7 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
129
155
|
}
|
|
130
156
|
|
|
131
157
|
return function () {
|
|
158
|
+
dom && clear(dom);
|
|
132
159
|
onDestroy();
|
|
133
160
|
|
|
134
161
|
if (playground !== null && playground !== void 0 && playground.playgroundWillUnmount) {
|
|
@@ -149,6 +176,11 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
149
176
|
});
|
|
150
177
|
}
|
|
151
178
|
}, []);
|
|
179
|
+
useEffect(function () {
|
|
180
|
+
if (monacoRef.current) {
|
|
181
|
+
monacoRef.current.setValue(currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2));
|
|
182
|
+
}
|
|
183
|
+
}, [currentEditorTab]);
|
|
152
184
|
var onCodeChange = useCallback(function (value) {
|
|
153
185
|
if (currentEditorTab === EDITOR_TABS.JAVASCRIPT) {
|
|
154
186
|
setCode(value);
|
|
@@ -177,9 +209,9 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
177
209
|
}
|
|
178
210
|
}, /*#__PURE__*/React.createElement(MonacoEditor, {
|
|
179
211
|
language: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? 'javascript' : 'json',
|
|
180
|
-
value:
|
|
212
|
+
value: code,
|
|
181
213
|
path: relativePath,
|
|
182
|
-
loading:
|
|
214
|
+
loading: /*#__PURE__*/React.createElement(Loading, null),
|
|
183
215
|
options: {
|
|
184
216
|
readOnly: currentEditorTab === EDITOR_TABS.DATA,
|
|
185
217
|
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={useT('在 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"
|
|
@@ -9,21 +9,23 @@ import styles from "./index.module.less";
|
|
|
9
9
|
* 2. 错误预览
|
|
10
10
|
*/
|
|
11
11
|
export var CodePreview = function CodePreview(_ref) {
|
|
12
|
-
var
|
|
12
|
+
var isPlayground = _ref.isPlayground,
|
|
13
|
+
exampleId = _ref.exampleId,
|
|
14
|
+
header = _ref.header,
|
|
13
15
|
error = _ref.error;
|
|
14
16
|
return /*#__PURE__*/React.createElement("div", {
|
|
15
17
|
className: styles.preview
|
|
16
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
18
|
+
}, isPlayground ? null : /*#__PURE__*/React.createElement("div", {
|
|
17
19
|
className: styles.header
|
|
18
20
|
}, header), /*#__PURE__*/React.createElement("div", {
|
|
19
21
|
className: styles.content
|
|
20
22
|
}, /*#__PURE__*/React.createElement("div", {
|
|
21
|
-
id: "
|
|
23
|
+
id: "playgroundScriptContainer_".concat(exampleId),
|
|
22
24
|
className: styles.playgroundScriptContainer
|
|
23
25
|
}), error ? /*#__PURE__*/React.createElement(Result, {
|
|
24
26
|
className: styles.result,
|
|
25
27
|
status: "error",
|
|
26
28
|
title: useT('演示代码报错,请检查'),
|
|
27
|
-
subTitle: /*#__PURE__*/React.createElement("pre", null, error && error.
|
|
29
|
+
subTitle: /*#__PURE__*/React.createElement("pre", null, error && error.toString())
|
|
28
30
|
}) : null));
|
|
29
31
|
};
|
|
@@ -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
|
/**
|
|
@@ -28,6 +28,9 @@ 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,
|
|
32
|
+
replaceId = _ref.replaceId,
|
|
33
|
+
isPlayground = _ref.isPlayground,
|
|
31
34
|
_ref$notFound = _ref.notFound,
|
|
32
35
|
notFound = _ref$notFound === void 0 ? /*#__PURE__*/React.createElement(NotFound, null) : _ref$notFound;
|
|
33
36
|
var demoInfo = getDemoInfo(exampleTopics, topic, example, demo); // 找不到,啥也别干了,404 页面
|
|
@@ -40,7 +43,8 @@ export var CodeRunner = function CodeRunner(_ref) {
|
|
|
40
43
|
var _useSiteData = useSiteData(),
|
|
41
44
|
themeConfig = _useSiteData.themeConfig;
|
|
42
45
|
|
|
43
|
-
var githubUrl = themeConfig.githubUrl
|
|
46
|
+
var githubUrl = themeConfig.githubUrl,
|
|
47
|
+
playground = themeConfig.playground;
|
|
44
48
|
|
|
45
49
|
var _useState = useState(),
|
|
46
50
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -58,19 +62,29 @@ export var CodeRunner = function CodeRunner(_ref) {
|
|
|
58
62
|
relativePath: relativePath,
|
|
59
63
|
githubUrl: githubUrl
|
|
60
64
|
});
|
|
65
|
+
|
|
66
|
+
function getExampleId() {
|
|
67
|
+
return "".concat(topic, "_").concat(example, "_").concat(demo);
|
|
68
|
+
}
|
|
69
|
+
|
|
61
70
|
return /*#__PURE__*/React.createElement(SplitPane, {
|
|
62
71
|
split: "vertical",
|
|
63
|
-
defaultSize: "
|
|
72
|
+
defaultSize: "".concat((1 - size) * 100, "%"),
|
|
64
73
|
minSize: 100
|
|
65
74
|
}, /*#__PURE__*/React.createElement(CodePreview, {
|
|
75
|
+
exampleId: getExampleId(),
|
|
66
76
|
error: error,
|
|
67
|
-
header: header
|
|
77
|
+
header: header,
|
|
78
|
+
isPlayground: isPlayground
|
|
68
79
|
}), /*#__PURE__*/React.createElement(CodeEditor, {
|
|
80
|
+
exampleId: getExampleId(),
|
|
69
81
|
source: source,
|
|
70
82
|
relativePath: relativePath,
|
|
83
|
+
replaceId: replaceId,
|
|
71
84
|
onError: setError,
|
|
72
85
|
onFullscreen: setFullscreen,
|
|
73
86
|
onDestroy: noop,
|
|
74
|
-
onReady: noop
|
|
87
|
+
onReady: noop,
|
|
88
|
+
playground: playground
|
|
75
89
|
}));
|
|
76
90
|
};
|
|
@@ -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'
|