@antv/dumi-theme-antv 0.3.5 → 0.3.6

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 (55) hide show
  1. package/dist/builtins/Playground/index.js +14 -26
  2. package/dist/layouts/DocLayout.js +17 -20
  3. package/dist/layouts/entry/API.js +0 -1
  4. package/dist/layouts/entry/Index.js +27 -31
  5. package/dist/layouts/entry/Manual.js +0 -1
  6. package/dist/pages/404.js +1 -2
  7. package/dist/pages/Example/index.js +19 -37
  8. package/dist/pages/Examples/components/Accouncement/index.js +9 -13
  9. package/dist/pages/Examples/components/ExampleTopicMenu/components/LeftMenu/index.js +9 -20
  10. package/dist/pages/Examples/components/ExampleTopicMenu/index.js +6 -14
  11. package/dist/pages/Examples/components/GalleryPageContent/DemoCard/index.js +3 -5
  12. package/dist/pages/Examples/components/GalleryPageContent/index.js +8 -6
  13. package/dist/pages/Examples/index.js +8 -19
  14. package/dist/plugin/examples.js +5 -0
  15. package/dist/plugin/index.js +6 -0
  16. package/dist/plugin/utils.js +4 -0
  17. package/dist/slots/Article/index.js +0 -2
  18. package/dist/slots/Banner/Notification.js +6 -10
  19. package/dist/slots/Banner/index.js +24 -46
  20. package/dist/slots/Cases/index.js +4 -13
  21. package/dist/slots/CodeEditor/Toolbar.js +26 -36
  22. package/dist/slots/CodeEditor/index.js +66 -76
  23. package/dist/slots/CodeEditor/utils.js +28 -43
  24. package/dist/slots/CodePreview/CodeHeader.js +4 -4
  25. package/dist/slots/CodePreview/index.js +4 -6
  26. package/dist/slots/CodeRunner/index.js +22 -33
  27. package/dist/slots/CodeRunner/utils.js +5 -6
  28. package/dist/slots/Companies/index.js +4 -4
  29. package/dist/slots/ContentTable/index.js +1 -1
  30. package/dist/slots/Detail/News.js +6 -8
  31. package/dist/slots/Detail/index.js +25 -34
  32. package/dist/slots/ExampleSider/index.js +36 -43
  33. package/dist/slots/Features/FeatureCard.js +2 -4
  34. package/dist/slots/Features/index.js +7 -11
  35. package/dist/slots/Footer/index.js +13 -19
  36. package/dist/slots/Header/Logo.js +1 -1
  37. package/dist/slots/Header/LogoWhite.js +1 -1
  38. package/dist/slots/Header/Navs.js +8 -11
  39. package/dist/slots/Header/Products/NavigatorBanner.js +2 -8
  40. package/dist/slots/Header/Products/Product.js +9 -13
  41. package/dist/slots/Header/Products/getProducts.js +5 -11
  42. package/dist/slots/Header/Products/index.js +14 -22
  43. package/dist/slots/Header/Search.js +15 -20
  44. package/dist/slots/Header/index.js +93 -130
  45. package/dist/slots/Header/utils.js +2 -3
  46. package/dist/slots/Loading/index.js +1 -3
  47. package/dist/slots/ManualContent/NavigatorBanner.js +2 -7
  48. package/dist/slots/ManualContent/ReadingTime.js +0 -2
  49. package/dist/slots/ManualContent/index.js +51 -86
  50. package/dist/slots/ManualContent/utils.js +7 -13
  51. package/dist/slots/SEO.js +8 -10
  52. package/dist/slots/global.js +2 -1
  53. package/dist/slots/hooks.js +17 -29
  54. package/dist/slots/utils.js +32 -57
  55. package/package.json +1 -1
@@ -1,15 +1,9 @@
1
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
-
3
2
  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."); }
4
-
5
3
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8
-
9
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
-
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
11
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
-
13
7
  import React, { useRef, useState, useCallback, useEffect } from 'react';
14
8
  import MonacoEditor, { loader } from '@monaco-editor/react';
15
9
  import { useSiteData, useLocale } from 'dumi';
@@ -29,66 +23,61 @@ loader.config({
29
23
  vs: 'https://gw.alipayobjects.com/os/lib/monaco-editor/0.34.0/min/vs'
30
24
  }
31
25
  });
32
-
33
26
  /**
34
27
  * 代码编辑器
35
28
  */
36
29
  export var CodeEditor = function CodeEditor(_ref) {
37
30
  var _ref$title = _ref.title,
38
- title = _ref$title === void 0 ? '' : _ref$title,
39
- source = _ref.source,
40
- _ref$relativePath = _ref.relativePath,
41
- relativePath = _ref$relativePath === void 0 ? '' : _ref$relativePath,
42
- playground = _ref.playground,
43
- _ref$replaceId = _ref.replaceId,
44
- replaceId = _ref$replaceId === void 0 ? 'container' : _ref$replaceId,
45
- isFullscreen = _ref.isFullscreen,
46
- exampleId = _ref.exampleId,
47
- _ref$onReady = _ref.onReady,
48
- onReady = _ref$onReady === void 0 ? noop : _ref$onReady,
49
- _ref$onDestroy = _ref.onDestroy,
50
- onDestroy = _ref$onDestroy === void 0 ? noop : _ref$onDestroy,
51
- _ref$onError = _ref.onError,
52
- onError = _ref$onError === void 0 ? noop : _ref$onError,
53
- _ref$onFullscreen = _ref.onFullscreen,
54
- onFullscreen = _ref$onFullscreen === void 0 ? noop : _ref$onFullscreen;
31
+ title = _ref$title === void 0 ? '' : _ref$title,
32
+ source = _ref.source,
33
+ _ref$relativePath = _ref.relativePath,
34
+ relativePath = _ref$relativePath === void 0 ? '' : _ref$relativePath,
35
+ playground = _ref.playground,
36
+ _ref$replaceId = _ref.replaceId,
37
+ replaceId = _ref$replaceId === void 0 ? 'container' : _ref$replaceId,
38
+ isFullscreen = _ref.isFullscreen,
39
+ exampleId = _ref.exampleId,
40
+ _ref$onReady = _ref.onReady,
41
+ onReady = _ref$onReady === void 0 ? noop : _ref$onReady,
42
+ _ref$onDestroy = _ref.onDestroy,
43
+ onDestroy = _ref$onDestroy === void 0 ? noop : _ref$onDestroy,
44
+ _ref$onError = _ref.onError,
45
+ onError = _ref$onError === void 0 ? noop : _ref$onError,
46
+ _ref$onFullscreen = _ref.onFullscreen,
47
+ onFullscreen = _ref$onFullscreen === void 0 ? noop : _ref$onFullscreen;
55
48
  var locale = useLocale();
56
49
  var _useSiteData$themeCon = useSiteData().themeConfig.playground.extraLib,
57
- extraLib = _useSiteData$themeCon === void 0 ? '' : _useSiteData$themeCon; // 编辑器两个 tab,分别是代码和数据
58
-
50
+ extraLib = _useSiteData$themeCon === void 0 ? '' : _useSiteData$themeCon;
51
+ // 编辑器两个 tab,分别是代码和数据
59
52
  var _useState = useState(null),
60
- _useState2 = _slicedToArray(_useState, 2),
61
- data = _useState2[0],
62
- setData = _useState2[1];
63
-
53
+ _useState2 = _slicedToArray(_useState, 2),
54
+ data = _useState2[0],
55
+ setData = _useState2[1];
64
56
  var _useState3 = useState(source),
65
- _useState4 = _slicedToArray(_useState3, 2),
66
- code = _useState4[0],
67
- setCode = _useState4[1]; // monaco instance
68
-
69
-
70
- var monacoRef = useRef(null); // 文件后缀
71
-
72
- var fileExtension = relativePath.split('.')[relativePath.split('.').length - 1] || 'js'; // 菜单栏
73
-
57
+ _useState4 = _slicedToArray(_useState3, 2),
58
+ code = _useState4[0],
59
+ setCode = _useState4[1];
60
+ // monaco instance
61
+ var monacoRef = useRef(null);
62
+ // 文件后缀
63
+ var fileExtension = relativePath.split('.')[relativePath.split('.').length - 1] || 'js';
64
+ // 菜单栏
74
65
  var _useState5 = useState([]),
75
- _useState6 = _slicedToArray(_useState5, 2),
76
- editorTabs = _useState6[0],
77
- setEditorTabs = _useState6[1]; // 当前选中菜单栏
78
-
79
-
66
+ _useState6 = _slicedToArray(_useState5, 2),
67
+ editorTabs = _useState6[0],
68
+ setEditorTabs = _useState6[1];
69
+ // 当前选中菜单栏
80
70
  var _useState7 = useState(EDITOR_TABS.JAVASCRIPT),
81
- _useState8 = _slicedToArray(_useState7, 2),
82
- currentEditorTab = _useState8[0],
83
- setCurrentEditorTab = _useState8[1];
84
-
85
- var containerId = "playgroundScriptContainer_".concat(exampleId); // 出发 auto resize
71
+ _useState8 = _slicedToArray(_useState7, 2),
72
+ currentEditorTab = _useState8[0],
73
+ setCurrentEditorTab = _useState8[1];
74
+ var containerId = "playgroundScriptContainer_".concat(exampleId);
86
75
 
76
+ // 出发 auto resize
87
77
  var dispatchResizeEvent = function dispatchResizeEvent() {
88
78
  var e = new Event('resize');
89
79
  window.dispatchEvent(e);
90
80
  };
91
-
92
81
  var reportError = useCallback(function (e) {
93
82
  if (e) {
94
83
  console.log(e);
@@ -102,13 +91,12 @@ export var CodeEditor = function CodeEditor(_ref) {
102
91
  // 用于上报错误信息,使用 script 执行代码
103
92
  if (typeof window !== 'undefined') {
104
93
  // Cath error of code.
105
- window.__reportErrorInPlayground = reportError; // Catch error of timeout/raf.
106
-
107
- window.onerror = reportError; // Catch error of promise.
108
-
94
+ window.__reportErrorInPlayground = reportError;
95
+ // Catch error of timeout/raf.
96
+ window.onerror = reportError;
97
+ // Catch error of promise.
109
98
  window.addEventListener('unhandledrejection', reportError);
110
99
  }
111
-
112
100
  return function () {
113
101
  if (window) {
114
102
  window.__reportErrorInPlayground = undefined;
@@ -119,62 +107,60 @@ export var CodeEditor = function CodeEditor(_ref) {
119
107
  }, []);
120
108
  var executeCode = useCallback(debounce(function (v) {
121
109
  if (currentEditorTab !== EDITOR_TABS.JAVASCRIPT) return;
122
- if (!v) return; // 1. 先编译代码
110
+ if (!v) return;
123
111
 
112
+ // 1. 先编译代码
124
113
  var compiled;
125
-
126
114
  try {
127
115
  compiled = compile(replaceInsertCss(v, locale.id), relativePath);
128
116
  } catch (e) {
129
- reportError(e); // 执行出错,后面的步骤不用做了!
130
-
117
+ reportError(e);
118
+ // 执行出错,后面的步骤不用做了!
131
119
  return;
132
- } // 2. 执行代码,try catch 在内部已经做了
133
-
120
+ }
134
121
 
122
+ // 2. 执行代码,try catch 在内部已经做了
135
123
  execute(compiled, containerId, playground === null || playground === void 0 ? void 0 : playground.container, replaceId);
136
- }, 300), [exampleId, currentEditorTab]); // 案例变化的时候,修改期待吗
124
+ }, 300), [exampleId, currentEditorTab]);
137
125
 
126
+ // 案例变化的时候,修改期待吗
138
127
  useEffect(function () {
139
128
  setCode(source);
140
- }, [exampleId]); // 代码变化的时候,运行代码
129
+ }, [exampleId]);
141
130
 
131
+ // 代码变化的时候,运行代码
142
132
  useEffect(function () {
143
133
  executeCode(code);
144
134
  }, [code]);
145
135
  useEffect(function () {
146
136
  var dom = document.getElementById(containerId);
147
-
148
137
  if (dom) {
149
138
  bind(dom, debounce(function () {
150
139
  dispatchResizeEvent();
151
140
  }, 100));
152
141
  }
153
-
154
142
  return function () {
155
143
  dom && clear(dom);
156
144
  };
157
- }, []); // 生命周期
145
+ }, []);
158
146
 
147
+ // 生命周期
159
148
  useEffect(function () {
160
149
  onReady();
161
-
162
150
  if (playground !== null && playground !== void 0 && playground.playgroundDidMount) {
163
151
  new Function(playground.playgroundDidMount)();
164
152
  }
165
-
166
153
  return function () {
167
154
  onDestroy();
168
-
169
155
  if (playground !== null && playground !== void 0 && playground.playgroundWillUnmount) {
170
156
  new Function(playground.playgroundWillUnmount)();
171
157
  }
172
158
  };
173
- }, []); // hook 用户的数据
159
+ }, []);
174
160
 
161
+ // hook 用户的数据
175
162
  useEffect(function () {
176
163
  var dataFileMatch = source.match(/fetch\('(.*)'\)/);
177
-
178
164
  if (dataFileMatch && dataFileMatch.length > 0) {
179
165
  fetch(dataFileMatch[1]).then(function (response) {
180
166
  return response.json();
@@ -185,11 +171,14 @@ export var CodeEditor = function CodeEditor(_ref) {
185
171
  } else {
186
172
  setEditorTabs([EDITOR_TABS.JAVASCRIPT]);
187
173
  }
188
- }, [exampleId]); // 切换 tab
174
+ }, [exampleId]);
189
175
 
176
+ // 切换 tab
190
177
  var onTabChange = useCallback(function (tab) {
191
178
  setCurrentEditorTab(tab);
192
- }, [exampleId]); // useEffect(() => {
179
+ }, [exampleId]);
180
+
181
+ // useEffect(() => {
193
182
  // if (monacoRef.current) {
194
183
  // const v = currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2);
195
184
  // monacoRef.current.setValue(v);
@@ -224,7 +213,8 @@ export var CodeEditor = function CodeEditor(_ref) {
224
213
  }
225
214
  }, /*#__PURE__*/React.createElement(MonacoEditor, {
226
215
  language: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? 'javascript' : 'json',
227
- value: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2) // defaultValue={code}
216
+ value: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2)
217
+ // defaultValue={code}
228
218
  ,
229
219
  path: relativePath,
230
220
  loading: /*#__PURE__*/React.createElement(Loading, null),
@@ -1,52 +1,41 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
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
-
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
7
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
-
9
8
  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
9
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
-
13
10
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
-
15
11
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
-
17
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
18
-
19
- import path from 'path'; // @ts-ignore
20
-
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
+ import path from 'path';
14
+ // @ts-ignore
21
15
  import { transform } from '@babel/standalone';
22
16
  import indentString from 'indent-string';
23
17
  export function replaceFetchUrl(sourceCode) {
24
18
  var dataFileMatch = sourceCode.match(/fetch\('(.*)'\)/);
25
-
26
19
  if (dataFileMatch && dataFileMatch.length > 0 && !dataFileMatch[1].startsWith('http')) {
27
20
  return sourceCode.replace(dataFileMatch[1], path.join(location.origin || '', location.pathname || '', '..', dataFileMatch[1]));
28
21
  }
29
-
30
22
  return sourceCode;
31
23
  }
24
+
32
25
  /**
33
26
  * 通过代码提取代码片段的 pkg 依赖
34
27
  * @param sourceCode
35
28
  */
36
-
37
29
  export function extractImportDeps(sourceCode) {
38
30
  var requireMatches = sourceCode.match(/require\(['"](.*)['"]\)/g) || [];
39
31
  var importMatches = sourceCode.match(/from\s+['"](.*)['"]/g) || [];
40
32
  var deps = {};
41
33
  [].concat(_toConsumableArray(requireMatches), _toConsumableArray(importMatches)).forEach(function (match) {
42
34
  var requireMatch = match.match(/require\(['"](.*)['"]\)/);
43
-
44
35
  if (requireMatch && requireMatch[1]) {
45
36
  deps[requireMatch[1]] = 'latest';
46
37
  }
47
-
48
38
  var importMatch = match.match(/from\s+['"](.*)['"]/);
49
-
50
39
  if (importMatch && importMatch[1]) {
51
40
  deps[importMatch[1]] = 'latest';
52
41
  }
@@ -55,7 +44,6 @@ export function extractImportDeps(sourceCode) {
55
44
  }
56
45
  export function getCodeSandboxConfig(title, sourceCode, fileExtension, deps, devDependencies, playground) {
57
46
  var _files;
58
-
59
47
  return {
60
48
  files: (_files = {
61
49
  'package.json': {
@@ -86,7 +74,6 @@ export function getRiddleConfig(title, sourceCode, fileExtension, deps, devDepen
86
74
  }
87
75
  export function getStackblitzConfig(title, sourceCode, fileExtension, deps, devDependencies, playground) {
88
76
  var _files2;
89
-
90
77
  return {
91
78
  title: title || '',
92
79
  description: '',
@@ -97,29 +84,27 @@ export function getStackblitzConfig(title, sourceCode, fileExtension, deps, devD
97
84
  }
98
85
  export function getHtmlCodeTemplate(title, sourceCode, fileExtension, deps, devDependencies, playground) {
99
86
  var _playground$htmlCodeT = playground.htmlCodeTemplate,
100
- htmlCodeTemplate = _playground$htmlCodeT === void 0 ? '' : _playground$htmlCodeT,
101
- _playground$container = playground.container,
102
- container = _playground$container === void 0 ? '' : _playground$container;
87
+ htmlCodeTemplate = _playground$htmlCodeT === void 0 ? '' : _playground$htmlCodeT,
88
+ _playground$container = playground.container,
89
+ container = _playground$container === void 0 ? '' : _playground$container;
103
90
  var insertCssMatcher = /insertCss\(`\s*(.*)\s*`\);/;
104
91
  var code = replaceFetchUrl(sourceCode).replace(/import\s+.*\s+from\s+['"].*['"];?/g, '').replace(insertCssMatcher, '').replace(/^\s+|\s+$/g, '');
105
92
  var result = htmlCodeTemplate.replace('{{code}}', indentString(code, 4)).replace('{{title}}', title || 'example');
106
93
  var customStyles = sourceCode.match(insertCssMatcher);
107
-
108
94
  if (customStyles && customStyles[1]) {
109
95
  result = result.replace('</head>', " <style>\n".concat(indentString(customStyles[1], 4), "\n </style>\n </head>"));
110
96
  }
111
-
112
97
  if (container) {
113
98
  result = result.replace('<body>', "<body>\n".concat(indentString(container, 4)));
114
99
  }
115
-
116
100
  return result;
117
101
  }
118
102
  export function replaceInsertCss(str, lang) {
119
- var comment = lang === 'zh' ? "// \u6211\u4EEC\u7528 insert-css \u6F14\u793A\u5F15\u5165\u81EA\u5B9A\u4E49\u6837\u5F0F\n// \u63A8\u8350\u5C06\u6837\u5F0F\u6DFB\u52A0\u5230\u81EA\u5DF1\u7684\u6837\u5F0F\u6587\u4EF6\u4E2D\n// \u82E5\u62F7\u8D1D\u5B98\u65B9\u4EE3\u7801\uFF0C\u522B\u5FD8\u4E86 npm install insert-css\ninsertCss(" : "// We use 'insert-css' to insert custom styles\n// It is recommended to add the style to your own style sheet files\n// If you want to copy the code directly, please remember to install the npm package 'insert-css\ninsertCss("; // 统一增加对 insert-css 的使用注释
120
-
103
+ var comment = lang === 'zh' ? "// \u6211\u4EEC\u7528 insert-css \u6F14\u793A\u5F15\u5165\u81EA\u5B9A\u4E49\u6837\u5F0F\n// \u63A8\u8350\u5C06\u6837\u5F0F\u6DFB\u52A0\u5230\u81EA\u5DF1\u7684\u6837\u5F0F\u6587\u4EF6\u4E2D\n// \u82E5\u62F7\u8D1D\u5B98\u65B9\u4EE3\u7801\uFF0C\u522B\u5FD8\u4E86 npm install insert-css\ninsertCss(" : "// We use 'insert-css' to insert custom styles\n// It is recommended to add the style to your own style sheet files\n// If you want to copy the code directly, please remember to install the npm package 'insert-css\ninsertCss(";
104
+ // 统一增加对 insert-css 的使用注释
121
105
  return str.replace(/^insertCss\(/gm, comment);
122
106
  }
107
+
123
108
  /**
124
109
  * 执行代码
125
110
  * @param code 运行的代码
@@ -128,30 +113,30 @@ export function replaceInsertCss(str, lang) {
128
113
  * @param replaceId rid
129
114
  * @param cb 回调错误
130
115
  */
131
-
132
116
  export function execute(code, playgroundScriptContainer, container) {
133
117
  var replaceId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'container';
134
118
  var node = document.getElementById(playgroundScriptContainer);
135
- var script = document.createElement('script'); // replace container id in case of multi demos in document
136
-
119
+ var script = document.createElement('script');
120
+ // replace container id in case of multi demos in document
137
121
  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 // \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
-
140
- node.innerHTML = container || "<div id=".concat(replaceId, " class=\"playgroundCodeContainer\" />"); // 运行 script
141
-
122
+ 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 ");
123
+ // 追加图表容器
124
+ node.innerHTML = container || "<div id=".concat(replaceId, " class=\"playgroundCodeContainer\" />");
125
+ // 运行 script
142
126
  node.appendChild(script);
143
127
  }
128
+
144
129
  /**
145
130
  * 编译代码
146
131
  */
147
-
148
132
  export function compile(value, relativePath) {
149
133
  var _transform = transform(value, {
150
- filename: relativePath,
151
- presets: ['react', 'typescript', 'es2015', 'stage-3'],
152
- plugins: ['transform-modules-umd']
153
- }),
154
- code = _transform.code;
155
-
134
+ filename: relativePath,
135
+ presets: ['react', 'typescript', 'es2015', ['stage-3', {
136
+ decoratorsBeforeExport: true
137
+ }]],
138
+ plugins: ['transform-modules-umd']
139
+ }),
140
+ code = _transform.code;
156
141
  return code;
157
142
  }
@@ -1,16 +1,16 @@
1
1
  import React from 'react';
2
2
  import { PageHeader, Space, Divider } from 'antd';
3
-
4
3
  /**
5
4
  * 组件的 header
6
5
  */
7
6
  export var CodeHeader = function CodeHeader(_ref) {
8
7
  var title = _ref.title,
9
- relativePath = _ref.relativePath,
10
- githubUrl = _ref.githubUrl;
8
+ relativePath = _ref.relativePath,
9
+ githubUrl = _ref.githubUrl;
11
10
  return /*#__PURE__*/React.createElement(PageHeader, {
12
11
  ghost: false,
13
- title: title // todo 编辑地址各种各样,需要有单独的配置,暂时关闭!
12
+ title: title
13
+ // todo 编辑地址各种各样,需要有单独的配置,暂时关闭!
14
14
  // subTitle={
15
15
  // <Tooltip title={<FormattedMessage id="在 GitHub 上编辑" />}>
16
16
  // <a
@@ -2,22 +2,20 @@ import React from 'react';
2
2
  import { Result } from 'antd';
3
3
  import { FormattedMessage } from 'dumi';
4
4
  import styles from "./index.module.less";
5
-
6
5
  function getErrorMessage(e) {
7
6
  return (e.reason ? e.reason : e.message ? e.message : e).toString();
8
7
  }
8
+
9
9
  /**
10
10
  * DEMO 预览页面的预览,主要包含有:
11
11
  * 1. 一些 header 菜单
12
12
  * 2. 错误预览
13
13
  */
14
-
15
-
16
14
  export var CodePreview = function CodePreview(_ref) {
17
15
  var isPlayground = _ref.isPlayground,
18
- exampleId = _ref.exampleId,
19
- header = _ref.header,
20
- error = _ref.error;
16
+ exampleId = _ref.exampleId,
17
+ header = _ref.header,
18
+ error = _ref.error;
21
19
  return /*#__PURE__*/React.createElement("div", {
22
20
  className: styles.preview
23
21
  }, isPlayground ? null : /*#__PURE__*/React.createElement("div", {
@@ -1,15 +1,9 @@
1
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
-
3
2
  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."); }
4
-
5
3
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8
-
9
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
-
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
11
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
-
13
7
  import React, { useState } from 'react';
14
8
  import { useSiteData, useLocale } from 'dumi';
15
9
  import { noop } from 'lodash-es';
@@ -20,43 +14,38 @@ import { CodeHeader } from "../CodePreview/CodeHeader";
20
14
  import { getDemoInfo } from "./utils";
21
15
  import { NotFound } from "dumi/theme/slots/404";
22
16
  import { ic } from "../hooks";
23
-
24
17
  /**
25
18
  * 代码编辑器 + 代码预览区域
26
19
  */
27
20
  export var CodeRunner = function CodeRunner(_ref) {
28
21
  var exampleTopics = _ref.exampleTopics,
29
- topic = _ref.topic,
30
- example = _ref.example,
31
- demo = _ref.demo,
32
- size = _ref.size,
33
- replaceId = _ref.replaceId,
34
- isPlayground = _ref.isPlayground,
35
- _ref$notFound = _ref.notFound,
36
- notFound = _ref$notFound === void 0 ? /*#__PURE__*/React.createElement(NotFound, null) : _ref$notFound;
37
- var demoInfo = getDemoInfo(exampleTopics, topic, example, demo); // 找不到,啥也别干了,404 页面
22
+ topic = _ref.topic,
23
+ example = _ref.example,
24
+ demo = _ref.demo,
25
+ size = _ref.size,
26
+ replaceId = _ref.replaceId,
27
+ isPlayground = _ref.isPlayground,
28
+ _ref$notFound = _ref.notFound,
29
+ notFound = _ref$notFound === void 0 ? /*#__PURE__*/React.createElement(NotFound, null) : _ref$notFound;
30
+ var demoInfo = getDemoInfo(exampleTopics, topic, example, demo);
38
31
 
32
+ // 找不到,啥也别干了,404 页面
39
33
  if (!demoInfo) return notFound;
40
34
  var title = demoInfo.title,
41
- source = demoInfo.source,
42
- relativePath = demoInfo.relativePath;
43
-
35
+ source = demoInfo.source,
36
+ relativePath = demoInfo.relativePath;
44
37
  var _useSiteData = useSiteData(),
45
- themeConfig = _useSiteData.themeConfig;
46
-
38
+ themeConfig = _useSiteData.themeConfig;
47
39
  var githubUrl = themeConfig.githubUrl,
48
- playground = themeConfig.playground;
49
-
40
+ playground = themeConfig.playground;
50
41
  var _useState = useState(),
51
- _useState2 = _slicedToArray(_useState, 2),
52
- error = _useState2[0],
53
- setError = _useState2[1];
54
-
42
+ _useState2 = _slicedToArray(_useState, 2),
43
+ error = _useState2[0],
44
+ setError = _useState2[1];
55
45
  var _useState3 = useState(false),
56
- _useState4 = _slicedToArray(_useState3, 2),
57
- isFullScreen = _useState4[0],
58
- setFullscreen = _useState4[1];
59
-
46
+ _useState4 = _slicedToArray(_useState3, 2),
47
+ isFullScreen = _useState4[0],
48
+ setFullscreen = _useState4[1];
60
49
  var locale = useLocale();
61
50
  var header = /*#__PURE__*/React.createElement(CodeHeader, {
62
51
  title: ic(title),
@@ -1,11 +1,10 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
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
-
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
7
  import { map } from 'lodash-es';
8
-
9
8
  /**
10
9
  * 将数据结构转化成 map,便于后续检索的速度
11
10
  * @param exampleTopics
@@ -26,10 +25,10 @@ export function getExampleTopicMap(exampleTopics) {
26
25
  });
27
26
  return exampleTopicMap;
28
27
  }
28
+
29
29
  /**
30
30
  * 从 Context 信息中,获取到 Example 相关的信息,用于页面渲染
31
31
  */
32
-
33
32
  export function getDemoInfo(exampleTopics, topic, example, demo) {
34
33
  var m = getExampleTopicMap(exampleTopics);
35
34
  return m.get("".concat(topic, "-").concat(example, "-").concat(demo));
@@ -4,10 +4,10 @@ import cx from 'classnames';
4
4
  import styles from "./index.module.less";
5
5
  export var Companies = function Companies(_ref) {
6
6
  var title = _ref.title,
7
- _ref$companies = _ref.companies,
8
- companies = _ref$companies === void 0 ? [] : _ref$companies,
9
- className = _ref.className,
10
- style = _ref.style;
7
+ _ref$companies = _ref.companies,
8
+ companies = _ref$companies === void 0 ? [] : _ref$companies,
9
+ className = _ref.className,
10
+ style = _ref.style;
11
11
  return /*#__PURE__*/React.createElement("div", {
12
12
  className: cx(styles.wrapper, className),
13
13
  style: style
@@ -1,7 +1,7 @@
1
1
  import Toc from 'dumi/theme-default/slots/Toc';
2
2
  import "./index.module.less";
3
+
3
4
  /**
4
5
  * 文档右侧的指示器(table of content)
5
6
  */
6
-
7
7
  export var ContentTable = Toc;
@@ -5,12 +5,12 @@ 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'];
6
6
  export var News = function News(_ref) {
7
7
  var _ref$index = _ref.index,
8
- index = _ref$index === void 0 ? 0 : _ref$index,
9
- type = _ref.type,
10
- title = _ref.title,
11
- date = _ref.date,
12
- _ref$link = _ref.link,
13
- link = _ref$link === void 0 ? '' : _ref$link;
8
+ index = _ref$index === void 0 ? 0 : _ref$index,
9
+ type = _ref.type,
10
+ title = _ref.title,
11
+ date = _ref.date,
12
+ _ref$link = _ref.link,
13
+ link = _ref$link === void 0 ? '' : _ref$link;
14
14
  var lang = useLocale().id;
15
15
  var children = /*#__PURE__*/React.createElement("div", {
16
16
  className: styles.container
@@ -25,7 +25,6 @@ export var News = function News(_ref) {
25
25
  }, ic(type), " \u2027 ", ic(title)), /*#__PURE__*/React.createElement("p", {
26
26
  className: styles.date
27
27
  }, date)));
28
-
29
28
  if (link.startsWith('http')) {
30
29
  return /*#__PURE__*/React.createElement("a", {
31
30
  href: link,
@@ -34,7 +33,6 @@ export var News = function News(_ref) {
34
33
  className: styles.news
35
34
  }, children);
36
35
  }
37
-
38
36
  return /*#__PURE__*/React.createElement(Link, {
39
37
  to: link[lang] ? link[lang] : link,
40
38
  className: styles.news