@antv/dumi-theme-antv 0.2.1 → 0.3.0-beta.1

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 (258) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -33
  3. package/dist/builtins/Playground/index.d.ts +24 -0
  4. package/{es/builtins/Example.js → dist/builtins/Playground/index.js} +40 -33
  5. package/dist/builtins/Playground/index.module.less +15 -0
  6. package/dist/context.d.ts +5 -0
  7. package/dist/context.js +2 -0
  8. package/dist/layouts/DocLayout.d.ts +7 -0
  9. package/dist/layouts/DocLayout.js +38 -0
  10. package/dist/layouts/entry/API.d.ts +10 -0
  11. package/dist/layouts/entry/API.js +12 -0
  12. package/dist/layouts/entry/Index.d.ts +7 -0
  13. package/dist/layouts/entry/Index.js +71 -0
  14. package/dist/layouts/entry/Manual.d.ts +8 -0
  15. package/dist/layouts/entry/Manual.js +14 -0
  16. package/dist/locales/en.json +98 -0
  17. package/dist/locales/zh.json +98 -0
  18. package/dist/pages/404.d.ts +6 -0
  19. package/dist/pages/404.js +14 -0
  20. package/dist/pages/Example/index.d.ts +6 -0
  21. package/dist/pages/Example/index.js +139 -0
  22. package/dist/pages/Example/index.module.less +40 -0
  23. package/dist/pages/Examples/components/Accouncement/index.d.ts +6 -0
  24. package/dist/pages/Examples/components/Accouncement/index.js +60 -0
  25. package/dist/pages/Examples/components/Accouncement/index.module.less +9 -0
  26. package/dist/pages/Examples/components/Article/index.d.ts +2 -0
  27. package/dist/pages/Examples/components/Article/index.js +8 -0
  28. package/dist/pages/Examples/components/Article/index.module.less +2 -0
  29. package/dist/pages/Examples/components/ExampleTopicMenu/components/LeftMenu/index.d.ts +10 -0
  30. package/dist/pages/Examples/components/ExampleTopicMenu/components/LeftMenu/index.js +74 -0
  31. package/dist/pages/Examples/components/ExampleTopicMenu/index.d.ts +9 -0
  32. package/{es/builtins/Table.js → dist/pages/Examples/components/ExampleTopicMenu/index.js} +47 -41
  33. package/dist/pages/Examples/components/GalleryPageContent/DemoCard/index.d.ts +10 -0
  34. package/dist/pages/Examples/components/GalleryPageContent/DemoCard/index.js +33 -0
  35. package/dist/pages/Examples/components/GalleryPageContent/index.d.ts +10 -0
  36. package/dist/pages/Examples/components/GalleryPageContent/index.js +81 -0
  37. package/dist/pages/Examples/index.d.ts +8 -0
  38. package/dist/pages/Examples/index.js +75 -0
  39. package/dist/pages/Examples/index.module.less +605 -0
  40. package/dist/pages/Examples/types.d.ts +33 -0
  41. package/dist/pages/Examples/types.js +1 -0
  42. package/dist/plugin/examples.d.ts +7 -0
  43. package/dist/plugin/examples.js +83 -0
  44. package/dist/plugin/index.d.ts +3 -0
  45. package/dist/plugin/index.js +103 -0
  46. package/dist/slots/404.d.ts +2 -0
  47. package/{es/antv/404/index.js → dist/slots/404.js} +4 -9
  48. package/{es/antv/Cases/Cases.d.ts → dist/slots/Cases/index.d.ts} +4 -4
  49. package/{es/antv/Cases/Cases.js → dist/slots/Cases/index.js} +25 -25
  50. package/{src/antv/Cases/Cases.module.less → dist/slots/Cases/index.module.less} +36 -5
  51. package/dist/slots/CodeEditor/Toolbar.d.ts +67 -0
  52. package/dist/slots/CodeEditor/Toolbar.js +152 -0
  53. package/dist/slots/CodeEditor/Toolbar.module.less +81 -0
  54. package/dist/slots/CodeEditor/index.d.ts +58 -0
  55. package/dist/slots/CodeEditor/index.js +200 -0
  56. package/dist/slots/CodeEditor/index.module.less +11 -0
  57. package/dist/slots/CodeEditor/utils.d.ts +42 -0
  58. package/dist/slots/CodeEditor/utils.js +157 -0
  59. package/dist/slots/CodePreview/CodeHeader.d.ts +19 -0
  60. package/dist/slots/CodePreview/CodeHeader.js +32 -0
  61. package/dist/slots/CodePreview/CodeHeader.module.less +0 -0
  62. package/dist/slots/CodePreview/index.d.ts +17 -0
  63. package/dist/slots/CodePreview/index.js +29 -0
  64. package/dist/slots/CodePreview/index.module.less +42 -0
  65. package/dist/slots/CodeRunner/index.d.ts +14 -0
  66. package/dist/slots/CodeRunner/index.js +76 -0
  67. package/dist/slots/CodeRunner/index.module.less +0 -0
  68. package/dist/slots/CodeRunner/utils.d.ts +10 -0
  69. package/dist/slots/CodeRunner/utils.js +36 -0
  70. package/dist/slots/Companies/index.d.ts +13 -0
  71. package/dist/slots/Companies/index.js +49 -0
  72. package/dist/slots/Companies/index.module.less +82 -0
  73. package/dist/slots/Detail/News.d.ts +9 -0
  74. package/{es/antv/Banner/Notification.js → dist/slots/Detail/News.js} +8 -11
  75. package/{src/antv/Banner/Notification.module.less → dist/slots/Detail/News.module.less} +15 -3
  76. package/dist/slots/Detail/index.d.ts +26 -0
  77. package/dist/slots/Detail/index.js +124 -0
  78. package/{src/antv/Banner/Banner.module.less → dist/slots/Detail/index.module.less} +42 -74
  79. package/dist/slots/ExampleSider/index.d.ts +55 -0
  80. package/dist/slots/ExampleSider/index.js +218 -0
  81. package/dist/slots/ExampleSider/index.module.less +141 -0
  82. package/{es/antv → dist/slots}/Features/FeatureCard.d.ts +1 -1
  83. package/{es/antv → dist/slots}/Features/FeatureCard.js +6 -6
  84. package/{src/antv → dist/slots}/Features/FeatureCard.module.less +8 -1
  85. package/{es/antv → dist/slots}/Features/index.d.ts +2 -2
  86. package/{es/antv → dist/slots}/Features/index.js +17 -25
  87. package/{src/antv/Features/Features.module.less → dist/slots/Features/index.module.less} +34 -3
  88. package/dist/slots/Footer/index.d.ts +18 -0
  89. package/dist/slots/Footer/index.js +187 -0
  90. package/dist/slots/Footer/index.module.less +85 -0
  91. package/dist/slots/Header/Logo.d.ts +7 -0
  92. package/{es/antv → dist/slots}/Header/Logo.js +6 -2
  93. package/dist/slots/Header/LogoWhite.d.ts +7 -0
  94. package/dist/slots/Header/LogoWhite.js +19 -0
  95. package/dist/slots/Header/Navs.d.ts +17 -0
  96. package/dist/slots/Header/Navs.js +46 -0
  97. package/dist/slots/Header/Products/NavigatorBanner.d.ts +10 -0
  98. package/dist/slots/Header/Products/NavigatorBanner.js +34 -0
  99. package/dist/slots/Header/Products/NavigatorBanner.module.less +39 -0
  100. package/{es/antv → dist/slots/Header}/Products/Product.d.ts +3 -3
  101. package/{es/antv → dist/slots/Header}/Products/Product.js +11 -16
  102. package/{src/antv → dist/slots/Header}/Products/Product.module.less +10 -8
  103. package/{es/antv → dist/slots/Header}/Products/getProducts.d.ts +2 -7
  104. package/dist/slots/Header/Products/getProducts.js +67 -0
  105. package/dist/slots/Header/Products/index.d.ts +9 -0
  106. package/{es/antv → dist/slots/Header}/Products/index.js +15 -22
  107. package/dist/slots/Header/Search.d.ts +12 -0
  108. package/dist/slots/Header/Search.js +90 -0
  109. package/dist/slots/Header/Search.module.less +39 -0
  110. package/dist/slots/Header/index.d.ts +66 -0
  111. package/dist/slots/Header/index.js +379 -0
  112. package/dist/slots/Header/index.module.less +382 -0
  113. package/dist/slots/Header/utils.d.ts +1 -0
  114. package/dist/slots/Header/utils.js +26 -0
  115. package/dist/slots/Loading/index.d.ts +2 -0
  116. package/dist/slots/Loading/index.js +65 -0
  117. package/dist/slots/Loading/index.module.less +12 -0
  118. package/dist/slots/Loading.d.ts +5 -0
  119. package/dist/slots/Loading.js +8 -0
  120. package/dist/slots/ManualContent/NavigatorBanner.d.ts +9 -0
  121. package/dist/slots/ManualContent/NavigatorBanner.js +36 -0
  122. package/dist/slots/ManualContent/NavigatorBanner.module.less +39 -0
  123. package/dist/slots/ManualContent/ReadingTime.d.ts +3 -0
  124. package/dist/slots/ManualContent/ReadingTime.js +10 -0
  125. package/dist/slots/ManualContent/index.d.ts +9 -0
  126. package/dist/slots/ManualContent/index.js +321 -0
  127. package/dist/slots/ManualContent/index.module.less +656 -0
  128. package/dist/slots/TOC.d.ts +5 -0
  129. package/dist/slots/TOC.js +6 -0
  130. package/dist/slots/_.less +83 -0
  131. package/dist/slots/global.d.ts +1 -0
  132. package/dist/slots/global.js +7 -0
  133. package/dist/slots/hooks.d.ts +16 -0
  134. package/{es/antv → dist/slots}/hooks.js +60 -37
  135. package/dist/slots/utils.d.ts +20 -0
  136. package/dist/slots/utils.js +154 -0
  137. package/dist/types.d.ts +3 -0
  138. package/dist/types.js +1 -0
  139. package/dist/typings.d.ts +137 -0
  140. package/package.json +108 -47
  141. package/es/antv/404/index.d.ts +0 -2
  142. package/es/antv/Banner/Banner.module.less +0 -412
  143. package/es/antv/Banner/Notification.d.ts +0 -10
  144. package/es/antv/Banner/Notification.module.less +0 -108
  145. package/es/antv/Banner/index.d.ts +0 -25
  146. package/es/antv/Banner/index.js +0 -104
  147. package/es/antv/Cases/Cases.module.less +0 -203
  148. package/es/antv/Features/FeatureCard.module.less +0 -51
  149. package/es/antv/Features/Features.module.less +0 -169
  150. package/es/antv/Footer/Footer.module.less +0 -36
  151. package/es/antv/Footer/index.d.ts +0 -12
  152. package/es/antv/Footer/index.js +0 -237
  153. package/es/antv/Header/Logo.d.ts +0 -4
  154. package/es/antv/Products/Product.module.less +0 -146
  155. package/es/antv/Products/getNewProducts.d.ts +0 -24
  156. package/es/antv/Products/getNewProducts.js +0 -35
  157. package/es/antv/Products/getProducts.js +0 -460
  158. package/es/antv/Products/index.d.ts +0 -9
  159. package/es/antv/hooks.d.ts +0 -14
  160. package/es/antv/mixins.less +0 -21
  161. package/es/antv/utils.d.ts +0 -5
  162. package/es/antv/utils.js +0 -49
  163. package/es/builtins/API.d.ts +0 -3
  164. package/es/builtins/API.js +0 -37
  165. package/es/builtins/Alert.d.ts +0 -3
  166. package/es/builtins/Alert.js +0 -7
  167. package/es/builtins/Alert.less +0 -62
  168. package/es/builtins/Badge.d.ts +0 -3
  169. package/es/builtins/Badge.js +0 -7
  170. package/es/builtins/Badge.less +0 -31
  171. package/es/builtins/Example.d.ts +0 -5
  172. package/es/builtins/Example.less +0 -47
  173. package/es/builtins/Previewer.d.ts +0 -39
  174. package/es/builtins/Previewer.js +0 -225
  175. package/es/builtins/Previewer.less +0 -406
  176. package/es/builtins/SourceCode.d.ts +0 -10
  177. package/es/builtins/SourceCode.js +0 -70
  178. package/es/builtins/SourceCode.less +0 -103
  179. package/es/builtins/Table.d.ts +0 -4
  180. package/es/builtins/Table.less +0 -43
  181. package/es/builtins/Tree.d.ts +0 -4
  182. package/es/builtins/Tree.js +0 -213
  183. package/es/builtins/Tree.less +0 -159
  184. package/es/components/Dark.d.ts +0 -9
  185. package/es/components/Dark.js +0 -125
  186. package/es/components/Dark.less +0 -121
  187. package/es/components/LocaleSelect.d.ts +0 -6
  188. package/es/components/LocaleSelect.js +0 -53
  189. package/es/components/LocaleSelect.less +0 -59
  190. package/es/components/Navbar.d.ts +0 -10
  191. package/es/components/Navbar.js +0 -155
  192. package/es/components/Navbar.less +0 -180
  193. package/es/components/SearchBar.d.ts +0 -4
  194. package/es/components/SearchBar.js +0 -81
  195. package/es/components/SearchBar.less +0 -165
  196. package/es/components/SideMenu.d.ts +0 -10
  197. package/es/components/SideMenu.js +0 -99
  198. package/es/components/SideMenu.less +0 -379
  199. package/es/components/SlugList.d.ts +0 -7
  200. package/es/components/SlugList.js +0 -38
  201. package/es/components/SlugList.less +0 -18
  202. package/es/declaration.d.ts +0 -1
  203. package/es/layout.d.ts +0 -5
  204. package/es/layout.js +0 -277
  205. package/es/style/layout.less +0 -402
  206. package/es/style/markdown.less +0 -240
  207. package/es/style/variables.less +0 -37
  208. package/src/antv/404/index.tsx +0 -25
  209. package/src/antv/Banner/Notification.tsx +0 -45
  210. package/src/antv/Banner/index.tsx +0 -139
  211. package/src/antv/Cases/Cases.tsx +0 -116
  212. package/src/antv/Features/FeatureCard.tsx +0 -24
  213. package/src/antv/Features/index.tsx +0 -86
  214. package/src/antv/Footer/Footer.module.less +0 -36
  215. package/src/antv/Footer/index.tsx +0 -272
  216. package/src/antv/Header/Logo.tsx +0 -85
  217. package/src/antv/Products/Product.tsx +0 -80
  218. package/src/antv/Products/getNewProducts.tsx +0 -53
  219. package/src/antv/Products/getProducts.tsx +0 -626
  220. package/src/antv/Products/index.tsx +0 -70
  221. package/src/antv/hooks.ts +0 -87
  222. package/src/antv/mixins.less +0 -21
  223. package/src/antv/utils.ts +0 -44
  224. package/src/builtins/API.tsx +0 -57
  225. package/src/builtins/Alert.less +0 -62
  226. package/src/builtins/Alert.tsx +0 -4
  227. package/src/builtins/Badge.less +0 -31
  228. package/src/builtins/Badge.tsx +0 -4
  229. package/src/builtins/Example.less +0 -47
  230. package/src/builtins/Example.tsx +0 -34
  231. package/src/builtins/Previewer.less +0 -406
  232. package/src/builtins/Previewer.tsx +0 -264
  233. package/src/builtins/SourceCode.less +0 -103
  234. package/src/builtins/SourceCode.tsx +0 -55
  235. package/src/builtins/Table.less +0 -43
  236. package/src/builtins/Table.tsx +0 -42
  237. package/src/builtins/Tree.less +0 -159
  238. package/src/builtins/Tree.tsx +0 -130
  239. package/src/components/Dark.less +0 -121
  240. package/src/components/Dark.tsx +0 -78
  241. package/src/components/LocaleSelect.less +0 -59
  242. package/src/components/LocaleSelect.tsx +0 -53
  243. package/src/components/Navbar.less +0 -180
  244. package/src/components/Navbar.tsx +0 -152
  245. package/src/components/SearchBar.less +0 -165
  246. package/src/components/SearchBar.tsx +0 -68
  247. package/src/components/SideMenu.less +0 -379
  248. package/src/components/SideMenu.tsx +0 -148
  249. package/src/components/SlugList.less +0 -18
  250. package/src/components/SlugList.tsx +0 -20
  251. package/src/declaration.d.ts +0 -1
  252. package/src/layout.tsx +0 -226
  253. package/src/style/layout.less +0 -402
  254. package/src/style/markdown.less +0 -240
  255. package/src/style/variables.less +0 -37
  256. package/src/test/SearchBar.test.ts +0 -32
  257. package/src/test/Table.test.tsx +0 -41
  258. package/src/test/index.test.tsx +0 -377
@@ -0,0 +1,152 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+
3
+ 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
+ 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
+
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
+
13
+ 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; }
14
+
15
+ 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; }
16
+
17
+ 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; }
18
+
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
+
21
+ import React, { useEffect, useState } from 'react';
22
+ import { CodeSandboxOutlined, PlayCircleOutlined, ThunderboltOutlined, FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
23
+ import { Typography, Tooltip } from 'antd';
24
+ import { useLocale } from 'dumi';
25
+ import { getParameters } from 'codesandbox/lib/api/define';
26
+ import stackblitzSdk from '@stackblitz/sdk';
27
+ import { ping } from "../utils";
28
+ import { extractImportDeps, getCodeSandboxConfig, getStackblitzConfig, getRiddleConfig } from "./utils";
29
+ import { useT } from "../hooks";
30
+ import styles from "./Toolbar.module.less";
31
+ var Paragraph = Typography.Paragraph;
32
+ export var EDITOR_TABS;
33
+
34
+ (function (EDITOR_TABS) {
35
+ EDITOR_TABS["JAVASCRIPT"] = "JavaScript";
36
+ EDITOR_TABS["DATA"] = "Data";
37
+ })(EDITOR_TABS || (EDITOR_TABS = {}));
38
+
39
+ export var Toolbar = function Toolbar(_ref) {
40
+ var sourceCode = _ref.sourceCode,
41
+ fileExtension = _ref.fileExtension,
42
+ _ref$playground = _ref.playground,
43
+ playground = _ref$playground === void 0 ? {} : _ref$playground,
44
+ location = _ref.location,
45
+ _ref$title = _ref.title,
46
+ title = _ref$title === void 0 ? '' : _ref$title,
47
+ _ref$isFullScreen = _ref.isFullScreen,
48
+ isFullScreen = _ref$isFullScreen === void 0 ? false : _ref$isFullScreen,
49
+ editorTabs = _ref.editorTabs,
50
+ currentEditorTab = _ref.currentEditorTab,
51
+ onEditorTabChange = _ref.onEditorTabChange,
52
+ _ref$onToggleFullscre = _ref.onToggleFullscreen,
53
+ onToggleFullscreen = _ref$onToggleFullscre === void 0 ? null : _ref$onToggleFullscre,
54
+ onExecuteCode = _ref.onExecuteCode;
55
+ var locale = useLocale();
56
+ var exampleTitle = _typeof(title) === 'object' ? title[locale.id] : title; // 使用 playground.dependencies 定义的版本号
57
+
58
+ var dependencies = _objectSpread(_objectSpread({}, extractImportDeps(sourceCode)), playground.dependencies);
59
+
60
+ var devDependencies = playground.devDependencies || {};
61
+ var codeSandboxConfig = getCodeSandboxConfig(exampleTitle, sourceCode, fileExtension, dependencies, devDependencies, playground);
62
+ var riddlePrefillConfig = getRiddleConfig(exampleTitle, sourceCode, fileExtension, dependencies, devDependencies, playground);
63
+ var stackblitzPrefillConfig = getStackblitzConfig(exampleTitle, sourceCode, fileExtension, dependencies, devDependencies, playground); // const htmlCode = getHtmlCodeTemplate(exampleTitle, sourceCode, fileExtension, dependencies, devDependencies, playground);
64
+
65
+ var _useState = useState(false),
66
+ _useState2 = _slicedToArray(_useState, 2),
67
+ riddleVisible = _useState2[0],
68
+ updateRiddleVisible = _useState2[1];
69
+
70
+ useEffect(function () {
71
+ ping(function (status) {
72
+ updateRiddleVisible(status === 'responded');
73
+ });
74
+ }, []);
75
+ return /*#__PURE__*/React.createElement("div", {
76
+ className: styles.toolbar
77
+ }, /*#__PURE__*/React.createElement("div", {
78
+ className: styles.editortabs
79
+ }, editorTabs.map(function (tab, index) {
80
+ return /*#__PURE__*/React.createElement("span", {
81
+ key: index,
82
+ className: tab === currentEditorTab ? styles.current : '',
83
+ onClick: function onClick() {
84
+ return onEditorTabChange(tab);
85
+ }
86
+ }, tab);
87
+ })), riddleVisible ? /*#__PURE__*/React.createElement("form", {
88
+ action: "//riddle.alibaba-inc.com/riddles/define",
89
+ method: "POST",
90
+ target: "_blank"
91
+ }, /*#__PURE__*/React.createElement("input", {
92
+ type: "hidden",
93
+ name: "data",
94
+ value: JSON.stringify(riddlePrefillConfig)
95
+ }), /*#__PURE__*/React.createElement(Tooltip, {
96
+ title: useT('在 Riddle 中打开')
97
+ }, /*#__PURE__*/React.createElement("input", {
98
+ type: "submit",
99
+ value: "Create New Riddle with Prefilled Data",
100
+ className: styles.riddle
101
+ }))) : null, /*#__PURE__*/React.createElement(Tooltip, {
102
+ title: useT('在 StackBlitz 中打开')
103
+ }, /*#__PURE__*/React.createElement(ThunderboltOutlined, {
104
+ className: styles.stackblitz,
105
+ onClick: function onClick() {
106
+ stackblitzSdk.openProject(stackblitzPrefillConfig);
107
+ }
108
+ })), /*#__PURE__*/React.createElement(Tooltip, {
109
+ title: useT('在 CodeSandbox 中打开')
110
+ }, /*#__PURE__*/React.createElement("form", {
111
+ action: "https://codesandbox.io/api/v1/sandboxes/define",
112
+ method: "POST",
113
+ target: "_blank"
114
+ }, /*#__PURE__*/React.createElement("input", {
115
+ type: "hidden",
116
+ name: "parameters",
117
+ value: getParameters(codeSandboxConfig)
118
+ }), /*#__PURE__*/React.createElement("button", {
119
+ type: "submit",
120
+ className: styles.codesandbox
121
+ }, /*#__PURE__*/React.createElement(CodeSandboxOutlined, {
122
+ style: {
123
+ marginLeft: 8
124
+ }
125
+ })))), /*#__PURE__*/React.createElement(Paragraph, {
126
+ copyable: {
127
+ text: sourceCode
128
+ },
129
+ style: {
130
+ marginLeft: 6
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, {
145
+ title: useT('执行代码')
146
+ }, /*#__PURE__*/React.createElement(PlayCircleOutlined, {
147
+ onClick: onExecuteCode,
148
+ style: {
149
+ marginLeft: 12
150
+ }
151
+ })));
152
+ };
@@ -0,0 +1,81 @@
1
+ @import '~antd/es/style/themes/default.less';
2
+
3
+ .toolbar {
4
+ height: 36px;
5
+ line-height: 36px;
6
+ border-bottom: 1px solid #ececec;
7
+ width: 100%;
8
+ padding: 0 16px;
9
+ text-align: right;
10
+ color: #777;
11
+ background: #f8f9fc;
12
+
13
+ >* {
14
+ display: inline-block;
15
+ transition: all 0.3s;
16
+
17
+ &:hover {
18
+ color: #222;
19
+ }
20
+ }
21
+
22
+ .codesandbox {
23
+ border: 0;
24
+ background: none;
25
+ padding: 0;
26
+ cursor: pointer;
27
+ }
28
+
29
+ .riddle {
30
+ width: 16px;
31
+ height: 16px;
32
+ overflow: hidden;
33
+ text-indent: -9999px;
34
+ background: transparent url('https://gw.alipayobjects.com/zos/rmsportal/DlHbxMCyeuyOrqOdbgik.svg') center / 12px no-repeat;
35
+ border: 0;
36
+ cursor: pointer;
37
+ transition: all 0.3s;
38
+ position: relative;
39
+ top: .5px;
40
+ line-height: 1;
41
+ }
42
+
43
+ .stackblitz {
44
+ position: relative;
45
+ top: 1px;
46
+ margin-left: 8px;
47
+ }
48
+
49
+ .html {
50
+ margin-left: 10px;
51
+ position: relative;
52
+ top: 0.5px;
53
+ }
54
+
55
+ :global(.ant-typography-copy:not(.ant-typography-copy-success)) {
56
+ color: #777;
57
+
58
+ &:hover {
59
+ color: #222;
60
+ }
61
+ }
62
+ }
63
+
64
+ .editortabs {
65
+ position: absolute;
66
+ left: -3px;
67
+
68
+ span {
69
+ display: inline-block;
70
+ border-top: none;
71
+ padding: 0 24px;
72
+ cursor: pointer;
73
+
74
+ &.current {
75
+ background: #fff;
76
+ color: #000;
77
+ border-right: #ececec solid 1px;
78
+ border-left: #ececec solid 1px;
79
+ }
80
+ }
81
+ }
@@ -0,0 +1,58 @@
1
+ import React from 'react';
2
+ export declare type CodeEditorProps = {
3
+ /**
4
+ * 标题
5
+ */
6
+ title?: string;
7
+ /**
8
+ * 输入的源码
9
+ */
10
+ source: string;
11
+ /**
12
+ * 相对地址
13
+ */
14
+ relativePath?: string;
15
+ /**
16
+ * 是否全屏状态
17
+ */
18
+ isFullscreen?: boolean;
19
+ /**
20
+ * 在一个文档中有多个 DEMO 的时候,需要有不同的 dom id
21
+ */
22
+ replaceId?: string;
23
+ /**
24
+ * 点击全屏按钮
25
+ */
26
+ onFullscreen: (isFullScreen: boolean) => void;
27
+ /**
28
+ * 初始化
29
+ */
30
+ onReady: () => void;
31
+ /**
32
+ * 销毁
33
+ */
34
+ onDestroy: () => void;
35
+ /**
36
+ * 执行出错的时候,回调,方便上层做显示
37
+ */
38
+ onError: (e: any) => void;
39
+ /**
40
+ * playground 的一些配置
41
+ */
42
+ playground: {
43
+ container?: string;
44
+ playgroundDidMount?: string;
45
+ playgroundWillUnmount?: string;
46
+ dependencies?: {
47
+ [key: string]: string;
48
+ };
49
+ devDependencies?: {
50
+ [key: string]: string;
51
+ };
52
+ htmlCodeTemplate?: string;
53
+ };
54
+ };
55
+ /**
56
+ * 代码编辑器
57
+ */
58
+ export declare const CodeEditor: React.FC<CodeEditorProps>;
@@ -0,0 +1,200 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+
3
+ 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
+ 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
+
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
+
13
+ import React, { useRef, useState, useCallback, useEffect } from 'react';
14
+ import MonacoEditor, { loader } from '@monaco-editor/react';
15
+ import { useSiteData, useLocale } from 'dumi';
16
+ import { debounce, noop } from 'lodash-es';
17
+ import { replaceInsertCss, execute, compile } from "./utils";
18
+ import { Toolbar, EDITOR_TABS } from "./Toolbar";
19
+ import styles from "./index.module.less";
20
+ loader.config({
21
+ 'vs/nls': {
22
+ availableLanguages: {
23
+ '*': 'zh-cn'
24
+ }
25
+ },
26
+ paths: {
27
+ vs: 'https://gw.alipayobjects.com/os/lib/monaco-editor/0.34.0/min/vs'
28
+ }
29
+ });
30
+
31
+ /**
32
+ * 代码编辑器
33
+ */
34
+ export var CodeEditor = function CodeEditor(_ref) {
35
+ var _ref$title = _ref.title,
36
+ title = _ref$title === void 0 ? '' : _ref$title,
37
+ source = _ref.source,
38
+ _ref$relativePath = _ref.relativePath,
39
+ relativePath = _ref$relativePath === void 0 ? '' : _ref$relativePath,
40
+ playground = _ref.playground,
41
+ _ref$replaceId = _ref.replaceId,
42
+ replaceId = _ref$replaceId === void 0 ? 'container' : _ref$replaceId,
43
+ isFullscreen = _ref.isFullscreen,
44
+ _ref$onReady = _ref.onReady,
45
+ onReady = _ref$onReady === void 0 ? noop : _ref$onReady,
46
+ _ref$onDestroy = _ref.onDestroy,
47
+ onDestroy = _ref$onDestroy === void 0 ? noop : _ref$onDestroy,
48
+ _ref$onError = _ref.onError,
49
+ onError = _ref$onError === void 0 ? noop : _ref$onError,
50
+ _ref$onFullscreen = _ref.onFullscreen,
51
+ onFullscreen = _ref$onFullscreen === void 0 ? noop : _ref$onFullscreen;
52
+ var locale = useLocale();
53
+ var _useSiteData$themeCon = useSiteData().themeConfig.playground.extraLib,
54
+ extraLib = _useSiteData$themeCon === void 0 ? '' : _useSiteData$themeCon; // 编辑器两个 tab,分别是代码和数据
55
+
56
+ var _useState = useState(null),
57
+ _useState2 = _slicedToArray(_useState, 2),
58
+ data = _useState2[0],
59
+ setData = _useState2[1];
60
+
61
+ var _useState3 = useState(source),
62
+ _useState4 = _slicedToArray(_useState3, 2),
63
+ code = _useState4[0],
64
+ setCode = _useState4[1]; // monaco instance
65
+
66
+
67
+ var monacoRef = useRef(null); // 文件后缀
68
+
69
+ var fileExtension = relativePath.split('.')[relativePath.split('.').length - 1] || 'js'; // 菜单栏
70
+
71
+ var _useState5 = useState([]),
72
+ _useState6 = _slicedToArray(_useState5, 2),
73
+ editorTabs = _useState6[0],
74
+ setEditorTabs = _useState6[1]; // 当前选中菜单栏
75
+
76
+
77
+ var _useState7 = useState(EDITOR_TABS.JAVASCRIPT),
78
+ _useState8 = _slicedToArray(_useState7, 2),
79
+ currentEditorTab = _useState8[0],
80
+ setCurrentEditorTab = _useState8[1]; // 出发 auto resize
81
+
82
+
83
+ var dispatchResizeEvent = function dispatchResizeEvent() {
84
+ var e = new Event('resize');
85
+ window.dispatchEvent(e);
86
+ };
87
+
88
+ useEffect(function () {
89
+ // 用于上报错误信息,使用 script 执行代码
90
+ if (typeof window !== 'undefined') {
91
+ window.__reportErrorInPlayground = function (e) {
92
+ if (e) {
93
+ console.error(e);
94
+ onError(e);
95
+ }
96
+ };
97
+ }
98
+ });
99
+ var executeCode = useCallback(debounce(function (v) {
100
+ if (!v) return; // 1. 先编译代码
101
+
102
+ var compiled;
103
+
104
+ try {
105
+ compiled = compile(replaceInsertCss(v, locale.id), relativePath); // 清除错误
106
+
107
+ onError(null);
108
+ } catch (e) {
109
+ console.error(e);
110
+ onError(e); // 执行出错,后面的步骤不用做了!
111
+
112
+ return;
113
+ } // 2. 执行代码,try catch 在内部已经做了
114
+
115
+
116
+ execute(compiled, 'playgroundScriptContainer', playground === null || playground === void 0 ? void 0 : playground.container, replaceId);
117
+ }, 300), []);
118
+ useEffect(function () {
119
+ setCode(source);
120
+ }, [source]);
121
+ useEffect(function () {
122
+ executeCode(code);
123
+ }, [code]);
124
+ useEffect(function () {
125
+ onReady();
126
+
127
+ if (playground !== null && playground !== void 0 && playground.playgroundDidMount) {
128
+ new Function(playground.playgroundDidMount)();
129
+ }
130
+
131
+ return function () {
132
+ onDestroy();
133
+
134
+ if (playground !== null && playground !== void 0 && playground.playgroundWillUnmount) {
135
+ new Function(playground.playgroundWillUnmount)();
136
+ }
137
+ };
138
+ }, []); // hook 用户的数据
139
+
140
+ useEffect(function () {
141
+ var dataFileMatch = source.match(/fetch\('(.*)'\)/);
142
+
143
+ if (dataFileMatch && dataFileMatch.length > 0) {
144
+ fetch(dataFileMatch[1]).then(function (response) {
145
+ return response.json();
146
+ }).then(function (data) {
147
+ setEditorTabs([EDITOR_TABS.JAVASCRIPT, EDITOR_TABS.DATA]);
148
+ setData(data);
149
+ });
150
+ }
151
+ }, []);
152
+ var onCodeChange = useCallback(function (value) {
153
+ if (currentEditorTab === EDITOR_TABS.JAVASCRIPT) {
154
+ setCode(value);
155
+ }
156
+ }, []);
157
+ return /*#__PURE__*/React.createElement("div", {
158
+ className: styles.editor
159
+ }, /*#__PURE__*/React.createElement(Toolbar, {
160
+ fileExtension: fileExtension,
161
+ sourceCode: code,
162
+ playground: playground,
163
+ location: location,
164
+ title: title,
165
+ isFullScreen: isFullscreen,
166
+ editorTabs: editorTabs,
167
+ currentEditorTab: currentEditorTab,
168
+ onExecuteCode: function onExecuteCode() {
169
+ return executeCode(code);
170
+ },
171
+ onEditorTabChange: setCurrentEditorTab,
172
+ onToggleFullscreen: onFullscreen
173
+ }), /*#__PURE__*/React.createElement("div", {
174
+ className: styles.monaco,
175
+ style: {
176
+ height: 'calc(100% - 36px)'
177
+ }
178
+ }, /*#__PURE__*/React.createElement(MonacoEditor, {
179
+ language: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? 'javascript' : 'json',
180
+ value: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2),
181
+ path: relativePath,
182
+ loading: "Loading...",
183
+ options: {
184
+ readOnly: currentEditorTab === EDITOR_TABS.DATA,
185
+ automaticLayout: true,
186
+ minimap: {
187
+ enabled: false
188
+ },
189
+ scrollBeyondLastLine: false,
190
+ fixedOverflowWidgets: true,
191
+ lineNumbersMinChars: 4,
192
+ showFoldingControls: 'always',
193
+ foldingHighlight: true
194
+ },
195
+ onChange: onCodeChange,
196
+ onMount: function onMount(editor) {
197
+ monacoRef.current = editor;
198
+ }
199
+ })));
200
+ };
@@ -0,0 +1,11 @@
1
+ .editor {
2
+ overflow: hidden;
3
+ height: 100%;
4
+ width: 100%;
5
+
6
+ .monaco {
7
+ overflow: hidden;
8
+ height: 100%;
9
+ width: 100%;
10
+ }
11
+ }
@@ -0,0 +1,42 @@
1
+ export declare function replaceFetchUrl(sourceCode: string): string;
2
+ /**
3
+ * 通过代码提取代码片段的 pkg 依赖
4
+ * @param sourceCode
5
+ */
6
+ export declare function extractImportDeps(sourceCode: string): any;
7
+ export declare function getCodeSandboxConfig(title: string, sourceCode: string, fileExtension: string, deps: any, devDependencies: any, playground: any): {
8
+ files: {
9
+ [key: string]: any;
10
+ };
11
+ };
12
+ export declare function getRiddleConfig(title: string, sourceCode: string, fileExtension: string, deps: any, devDependencies: any, playground: any): {
13
+ title: string;
14
+ js: string;
15
+ html: any;
16
+ json: string;
17
+ };
18
+ export declare function getStackblitzConfig(title: string, sourceCode: string, fileExtension: string, deps: any, devDependencies: any, playground: any): {
19
+ title: string;
20
+ description: string;
21
+ template: any;
22
+ dependencies: any;
23
+ files: {
24
+ [x: string]: any;
25
+ 'index.html': any;
26
+ };
27
+ };
28
+ export declare function getHtmlCodeTemplate(title: string, sourceCode: string, fileExtension: string, deps: any, devDependencies: any, playground: any): any;
29
+ export declare function replaceInsertCss(str: string, lang: string): string;
30
+ /**
31
+ * 执行代码
32
+ * @param code 运行的代码
33
+ * @param playgroundScriptContainer 运行的节点
34
+ * @param container 代码中 container dom
35
+ * @param replaceId rid
36
+ * @param cb 回调错误
37
+ */
38
+ export declare function execute(code: string, playgroundScriptContainer: string, container: string, replaceId?: string): void;
39
+ /**
40
+ * 编译代码
41
+ */
42
+ export declare function compile(value: string, relativePath: string): any;