@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.
Files changed (67) hide show
  1. package/dist/builtins/Playground/index.d.ts +2 -5
  2. package/dist/builtins/Playground/index.js +25 -6
  3. package/dist/context.d.ts +2 -1
  4. package/dist/layouts/DocLayout.js +25 -16
  5. package/dist/layouts/entry/Index.js +10 -2
  6. package/dist/layouts/entry/Manual.js +3 -1
  7. package/dist/pages/404.js +5 -1
  8. package/dist/pages/Example/index.js +28 -52
  9. package/dist/pages/Example/index.module.less +50 -8
  10. package/dist/pages/Example/utils.d.ts +1 -0
  11. package/dist/pages/Example/utils.js +9 -0
  12. package/dist/pages/Examples/components/GalleryPageContent/DemoCard/index.js +8 -5
  13. package/dist/pages/Examples/index.js +22 -2
  14. package/dist/pages/Examples/index.module.less +2 -0
  15. package/dist/pages/Examples/types.d.ts +7 -6
  16. package/dist/plugin/examples.d.ts +16 -2
  17. package/dist/plugin/examples.js +32 -10
  18. package/dist/plugin/index.js +31 -20
  19. package/dist/plugin/utils.d.ts +5 -0
  20. package/dist/plugin/utils.js +46 -0
  21. package/dist/slots/Cases/index.d.ts +1 -0
  22. package/dist/slots/Cases/index.js +1 -1
  23. package/dist/slots/Cases/index.module.less +2 -1
  24. package/dist/slots/CodeEditor/Toolbar.js +4 -16
  25. package/dist/slots/CodeEditor/index.d.ts +4 -0
  26. package/dist/slots/CodeEditor/index.js +48 -16
  27. package/dist/slots/CodeEditor/utils.js +2 -2
  28. package/dist/slots/CodePreview/CodeHeader.js +15 -14
  29. package/dist/slots/CodePreview/index.d.ts +8 -0
  30. package/dist/slots/CodePreview/index.js +6 -4
  31. package/dist/slots/CodePreview/index.module.less +17 -7
  32. package/dist/slots/CodeRunner/index.d.ts +5 -2
  33. package/dist/slots/CodeRunner/index.js +18 -4
  34. package/dist/slots/CodeRunner/utils.d.ts +3 -2
  35. package/dist/slots/CodeRunner/utils.js +1 -1
  36. package/dist/slots/Detail/News.d.ts +1 -0
  37. package/dist/slots/Detail/index.d.ts +1 -0
  38. package/dist/slots/Detail/index.js +1 -1
  39. package/dist/slots/ExampleSider/index.d.ts +4 -38
  40. package/dist/slots/ExampleSider/index.js +22 -44
  41. package/dist/slots/ExampleSider/index.module.less +1 -1
  42. package/dist/slots/Features/FeatureCard.d.ts +1 -0
  43. package/dist/slots/Features/index.js +2 -1
  44. package/dist/slots/Footer/index.js +3 -2
  45. package/dist/slots/Header/Navs.d.ts +10 -1
  46. package/dist/slots/Header/Navs.js +36 -19
  47. package/dist/slots/Header/index.js +8 -7
  48. package/dist/slots/Loading/index.d.ts +6 -1
  49. package/dist/slots/Loading/index.js +24 -10
  50. package/dist/slots/Loading/index.module.less +276 -9
  51. package/dist/slots/ManualContent/index.js +138 -113
  52. package/dist/slots/ManualContent/index.module.less +40 -33
  53. package/dist/slots/ManualContent/utils.d.ts +18 -0
  54. package/dist/slots/ManualContent/utils.js +64 -0
  55. package/dist/slots/SEO.d.ts +10 -0
  56. package/dist/slots/SEO.js +59 -0
  57. package/dist/slots/{TOC.d.ts → TOC/index.d.ts} +1 -0
  58. package/dist/slots/{TOC.js → TOC/index.js} +1 -0
  59. package/dist/slots/TOC/index.module.less +11 -0
  60. package/dist/slots/hooks.d.ts +3 -3
  61. package/dist/slots/utils.d.ts +4 -19
  62. package/dist/slots/utils.js +77 -119
  63. package/dist/types.d.ts +83 -0
  64. package/dist/typings.d.ts +0 -113
  65. package/package.json +7 -4
  66. package/dist/slots/Loading.d.ts +0 -5
  67. package/dist/slots/Loading.js +0 -8
@@ -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
- function generateMetaJSON() {
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
- path: "/examples/",
41
- file: require.resolve("../pages/Examples/index.tsx")
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
- path: "/:language/examples/",
46
- file: require.resolve("../pages/Examples/index.tsx")
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
- path: "/examples/:topic/:example",
51
- file: require.resolve("../pages/Example/index.tsx")
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
- path: "/:language/examples/:topic/:example",
56
- file: require.resolve("../pages/Example/index.tsx")
62
+ absPath: "/:language/examples/:topic/:example",
63
+ file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
57
64
  }
58
65
  ];
59
- const contextFilePath = require.resolve("../context.ts");
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 { useOutlet } from 'dumi';
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(generateMetaJSON())}
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.path,
93
- absPath: page.path,
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 = require.resolve("../pages/404.tsx");
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,5 @@
1
+ /**
2
+ * 自定义的 resolve 函数,优先找 tsx,如果找不到则找对应的 js 文件。
3
+ * 因为 dumi-theme-antv 编译之后,全部变成 js 文件
4
+ */
5
+ export declare function myResolve(p: string, alternateExts?: string[]): string;
@@ -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
+ });
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import 'slick-carousel/slick/slick.css';
3
3
  import 'slick-carousel/slick/slick-theme.css';
4
+ import { IC } from '../../types';
4
5
  interface Case {
5
6
  logo?: string;
6
7
  isAppLogo?: boolean;
@@ -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", {
@@ -18,7 +18,8 @@
18
18
  width: 83.88%;
19
19
  height: 100%;
20
20
  overflow-y: hidden;
21
- display: flex;
21
+ display: flex !important;
22
+ align-items: center;
22
23
 
23
24
  .appLeft {
24
25
  margin-left: 3.06%;
@@ -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, FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
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
- }), onToggleFullscreen ? /*#__PURE__*/React.createElement(Tooltip, {
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,
@@ -4,6 +4,10 @@ export declare type CodeEditorProps = {
4
4
  * 标题
5
5
  */
6
6
  title?: string;
7
+ /**
8
+ * 示例的 id
9
+ */
10
+ exampleId: string;
7
11
  /**
8
12
  * 输入的源码
9
13
  */
@@ -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]; // 出发 auto resize
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
- window.__reportErrorInPlayground = function (e) {
92
- if (e) {
93
- console.error(e);
94
- onError(e);
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
- console.error(e);
110
- onError(e); // 执行出错,后面的步骤不用做了!
128
+ reportError(e); // 执行出错,后面的步骤不用做了!
111
129
 
112
130
  return;
113
131
  } // 2. 执行代码,try catch 在内部已经做了
114
132
 
115
133
 
116
- execute(compiled, 'playgroundScriptContainer', playground === null || playground === void 0 ? void 0 : playground.container, replaceId);
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: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2),
212
+ value: code,
181
213
  path: relativePath,
182
- loading: "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, Tooltip, Space, Divider } from 'antd';
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: /*#__PURE__*/React.createElement(Tooltip, {
19
- title: useT('在 GitHub 上编辑')
20
- }, /*#__PURE__*/React.createElement("a", {
21
- href: getGithubSourceUrl(githubUrl, relativePath, 'examples'),
22
- target: "_blank",
23
- rel: "noopener noreferrer",
24
- className: styles.editOnGtiHubButton
25
- }, /*#__PURE__*/React.createElement(EditOutlined, null))),
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"
@@ -1,5 +1,13 @@
1
1
  import React from 'react';
2
2
  export declare type CodePreviewProps = {
3
+ /**
4
+ * 在文档中预览
5
+ */
6
+ isPlayground: boolean;
7
+ /**
8
+ * id
9
+ */
10
+ exampleId: string;
3
11
  /**
4
12
  * 预览页面头部组件,用于显示 demo 名称,一些操作栏等
5
13
  */
@@ -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 header = _ref.header,
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: "playgroundScriptContainer",
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.message)
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: 16px;
6
+ padding: 24px;
7
7
  overflow: auto;
8
8
 
9
9
  display: flex;
10
10
  flex-direction: column;
11
11
 
12
12
  .header {
13
- flex: 0
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
- :global(#container) {
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 { ExamplesPage } from '../../typings';
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: ExamplesPage.ExampleTopic[];
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: "50%",
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: ExamplesPage.ExampleTopic[]): Map<string, ExamplesPage.Demo>;
7
+ export declare function getExampleTopicMap(exampleTopics: ExampleTopic[]): Map<string, Demo>;
7
8
  /**
8
9
  * 从 Context 信息中,获取到 Example 相关的信息,用于页面渲染
9
10
  */
10
- export declare function getDemoInfo(exampleTopics: ExamplesPage.ExampleTopic[], topic: string, example: string, demo: string): ExamplesPage.Demo | undefined;
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,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { IC } from '../../types';
2
3
  export interface NewsProps {
3
4
  index?: number;
4
5
  type: IC;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { IC } from '../../types';
2
3
  import { NewsProps } from './News';
3
4
  declare type DetailButtonProps = {
4
5
  text: IC;
@@ -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'