@antv/dumi-theme-antv 0.2.2 → 0.3.0-beta.10

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 (265) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -33
  3. package/dist/builtins/Playground/index.d.ts +21 -0
  4. package/dist/builtins/Playground/index.js +69 -0
  5. package/dist/builtins/Playground/index.module.less +15 -0
  6. package/dist/context.d.ts +6 -0
  7. package/dist/context.js +2 -0
  8. package/dist/layouts/DocLayout.d.ts +7 -0
  9. package/dist/layouts/DocLayout.js +48 -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 +79 -0
  14. package/dist/layouts/entry/Manual.d.ts +8 -0
  15. package/dist/layouts/entry/Manual.js +13 -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 +18 -0
  20. package/dist/pages/Example/index.d.ts +6 -0
  21. package/dist/pages/Example/index.js +115 -0
  22. package/dist/pages/Example/index.module.less +82 -0
  23. package/dist/pages/Example/utils.d.ts +1 -0
  24. package/dist/pages/Example/utils.js +9 -0
  25. package/dist/pages/Examples/components/Accouncement/index.d.ts +6 -0
  26. package/dist/pages/Examples/components/Accouncement/index.js +60 -0
  27. package/dist/pages/Examples/components/Accouncement/index.module.less +9 -0
  28. package/dist/pages/Examples/components/Article/index.d.ts +2 -0
  29. package/dist/pages/Examples/components/Article/index.js +8 -0
  30. package/dist/pages/Examples/components/Article/index.module.less +2 -0
  31. package/dist/pages/Examples/components/ExampleTopicMenu/components/LeftMenu/index.d.ts +10 -0
  32. package/dist/pages/Examples/components/ExampleTopicMenu/components/LeftMenu/index.js +74 -0
  33. package/dist/pages/Examples/components/ExampleTopicMenu/index.d.ts +9 -0
  34. package/{es/builtins/Example.js → dist/pages/Examples/components/ExampleTopicMenu/index.js} +47 -33
  35. package/dist/pages/Examples/components/GalleryPageContent/DemoCard/index.d.ts +10 -0
  36. package/dist/pages/Examples/components/GalleryPageContent/DemoCard/index.js +33 -0
  37. package/dist/pages/Examples/components/GalleryPageContent/index.d.ts +10 -0
  38. package/dist/pages/Examples/components/GalleryPageContent/index.js +81 -0
  39. package/dist/pages/Examples/index.d.ts +8 -0
  40. package/dist/pages/Examples/index.js +95 -0
  41. package/dist/pages/Examples/index.module.less +607 -0
  42. package/dist/pages/Examples/types.d.ts +34 -0
  43. package/dist/pages/Examples/types.js +1 -0
  44. package/dist/plugin/examples.d.ts +21 -0
  45. package/dist/plugin/examples.js +105 -0
  46. package/dist/plugin/index.d.ts +3 -0
  47. package/dist/plugin/index.js +113 -0
  48. package/dist/plugin/utils.d.ts +5 -0
  49. package/dist/plugin/utils.js +46 -0
  50. package/dist/slots/404.d.ts +2 -0
  51. package/{es/antv/404/index.js → dist/slots/404.js} +4 -9
  52. package/{es/antv/Cases/Cases.d.ts → dist/slots/Cases/index.d.ts} +5 -4
  53. package/{es/antv/Cases/Cases.js → dist/slots/Cases/index.js} +25 -25
  54. package/{src/antv/Cases/Cases.module.less → dist/slots/Cases/index.module.less} +36 -5
  55. package/dist/slots/CodeEditor/Toolbar.d.ts +67 -0
  56. package/dist/slots/CodeEditor/Toolbar.js +140 -0
  57. package/dist/slots/CodeEditor/Toolbar.module.less +81 -0
  58. package/dist/slots/CodeEditor/index.d.ts +58 -0
  59. package/dist/slots/CodeEditor/index.js +226 -0
  60. package/dist/slots/CodeEditor/index.module.less +11 -0
  61. package/dist/slots/CodeEditor/utils.d.ts +42 -0
  62. package/dist/slots/CodeEditor/utils.js +157 -0
  63. package/dist/slots/CodePreview/CodeHeader.d.ts +19 -0
  64. package/dist/slots/CodePreview/CodeHeader.js +32 -0
  65. package/dist/slots/CodePreview/CodeHeader.module.less +0 -0
  66. package/dist/slots/CodePreview/index.d.ts +17 -0
  67. package/dist/slots/CodePreview/index.js +29 -0
  68. package/dist/slots/CodePreview/index.module.less +43 -0
  69. package/dist/slots/CodeRunner/index.d.ts +15 -0
  70. package/dist/slots/CodeRunner/index.js +79 -0
  71. package/dist/slots/CodeRunner/index.module.less +0 -0
  72. package/dist/slots/CodeRunner/utils.d.ts +11 -0
  73. package/dist/slots/CodeRunner/utils.js +36 -0
  74. package/dist/slots/Companies/index.d.ts +13 -0
  75. package/dist/slots/Companies/index.js +49 -0
  76. package/dist/slots/Companies/index.module.less +82 -0
  77. package/dist/slots/Detail/News.d.ts +10 -0
  78. package/{es/antv/Banner/Notification.js → dist/slots/Detail/News.js} +8 -11
  79. package/{src/antv/Banner/Notification.module.less → dist/slots/Detail/News.module.less} +15 -3
  80. package/dist/slots/Detail/index.d.ts +27 -0
  81. package/dist/slots/Detail/index.js +124 -0
  82. package/{src/antv/Banner/Banner.module.less → dist/slots/Detail/index.module.less} +42 -74
  83. package/dist/slots/ExampleSider/index.d.ts +21 -0
  84. package/dist/slots/ExampleSider/index.js +196 -0
  85. package/dist/slots/ExampleSider/index.module.less +141 -0
  86. package/{es/antv → dist/slots}/Features/FeatureCard.d.ts +2 -1
  87. package/{es/antv → dist/slots}/Features/FeatureCard.js +6 -6
  88. package/{src/antv → dist/slots}/Features/FeatureCard.module.less +8 -1
  89. package/{es/antv → dist/slots}/Features/index.d.ts +2 -2
  90. package/{es/antv → dist/slots}/Features/index.js +19 -26
  91. package/{src/antv/Features/Features.module.less → dist/slots/Features/index.module.less} +34 -3
  92. package/dist/slots/Footer/index.d.ts +18 -0
  93. package/dist/slots/Footer/index.js +188 -0
  94. package/dist/slots/Footer/index.module.less +86 -0
  95. package/dist/slots/Header/Logo.d.ts +7 -0
  96. package/{es/antv → dist/slots}/Header/Logo.js +6 -2
  97. package/dist/slots/Header/LogoWhite.d.ts +7 -0
  98. package/dist/slots/Header/LogoWhite.js +19 -0
  99. package/dist/slots/Header/Navs.d.ts +26 -0
  100. package/dist/slots/Header/Navs.js +63 -0
  101. package/dist/slots/Header/Products/NavigatorBanner.d.ts +10 -0
  102. package/dist/slots/Header/Products/NavigatorBanner.js +34 -0
  103. package/dist/slots/Header/Products/NavigatorBanner.module.less +39 -0
  104. package/{es/antv → dist/slots/Header}/Products/Product.d.ts +3 -3
  105. package/{es/antv → dist/slots/Header}/Products/Product.js +11 -16
  106. package/{src/antv → dist/slots/Header}/Products/Product.module.less +10 -8
  107. package/{es/antv → dist/slots/Header}/Products/getProducts.d.ts +2 -7
  108. package/dist/slots/Header/Products/getProducts.js +67 -0
  109. package/dist/slots/Header/Products/index.d.ts +9 -0
  110. package/{es/antv → dist/slots/Header}/Products/index.js +15 -22
  111. package/dist/slots/Header/Search.d.ts +12 -0
  112. package/dist/slots/Header/Search.js +90 -0
  113. package/dist/slots/Header/Search.module.less +39 -0
  114. package/dist/slots/Header/index.d.ts +66 -0
  115. package/dist/slots/Header/index.js +380 -0
  116. package/dist/slots/Header/index.module.less +382 -0
  117. package/dist/slots/Header/utils.d.ts +1 -0
  118. package/dist/slots/Header/utils.js +26 -0
  119. package/dist/slots/Loading/index.d.ts +7 -0
  120. package/dist/slots/Loading/index.js +79 -0
  121. package/dist/slots/Loading/index.module.less +279 -0
  122. package/dist/slots/ManualContent/NavigatorBanner.d.ts +9 -0
  123. package/dist/slots/ManualContent/NavigatorBanner.js +36 -0
  124. package/dist/slots/ManualContent/NavigatorBanner.module.less +39 -0
  125. package/dist/slots/ManualContent/ReadingTime.d.ts +3 -0
  126. package/dist/slots/ManualContent/ReadingTime.js +10 -0
  127. package/dist/slots/ManualContent/index.d.ts +9 -0
  128. package/dist/slots/ManualContent/index.js +344 -0
  129. package/dist/slots/ManualContent/index.module.less +668 -0
  130. package/dist/slots/ManualContent/utils.d.ts +3 -0
  131. package/dist/slots/ManualContent/utils.js +35 -0
  132. package/dist/slots/SEO.d.ts +10 -0
  133. package/dist/slots/SEO.js +59 -0
  134. package/dist/slots/TOC.d.ts +5 -0
  135. package/dist/slots/TOC.js +6 -0
  136. package/dist/slots/_.less +83 -0
  137. package/dist/slots/global.d.ts +1 -0
  138. package/dist/slots/global.js +7 -0
  139. package/dist/slots/hooks.d.ts +16 -0
  140. package/{es/antv → dist/slots}/hooks.js +60 -37
  141. package/dist/slots/utils.d.ts +5 -0
  142. package/dist/slots/utils.js +112 -0
  143. package/dist/types.d.ts +86 -0
  144. package/dist/types.js +1 -0
  145. package/dist/typings.d.ts +24 -0
  146. package/package.json +110 -47
  147. package/es/antv/404/index.d.ts +0 -2
  148. package/es/antv/Banner/Banner.module.less +0 -412
  149. package/es/antv/Banner/Notification.d.ts +0 -10
  150. package/es/antv/Banner/Notification.module.less +0 -108
  151. package/es/antv/Banner/index.d.ts +0 -25
  152. package/es/antv/Banner/index.js +0 -104
  153. package/es/antv/Cases/Cases.module.less +0 -203
  154. package/es/antv/Features/FeatureCard.module.less +0 -51
  155. package/es/antv/Features/Features.module.less +0 -169
  156. package/es/antv/Footer/Footer.module.less +0 -36
  157. package/es/antv/Footer/index.d.ts +0 -12
  158. package/es/antv/Footer/index.js +0 -237
  159. package/es/antv/Header/Logo.d.ts +0 -4
  160. package/es/antv/Products/Product.module.less +0 -146
  161. package/es/antv/Products/getNewProducts.d.ts +0 -24
  162. package/es/antv/Products/getNewProducts.js +0 -35
  163. package/es/antv/Products/getProducts.js +0 -460
  164. package/es/antv/Products/index.d.ts +0 -9
  165. package/es/antv/hooks.d.ts +0 -14
  166. package/es/antv/mixins.less +0 -21
  167. package/es/antv/utils.d.ts +0 -5
  168. package/es/antv/utils.js +0 -49
  169. package/es/builtins/API.d.ts +0 -3
  170. package/es/builtins/API.js +0 -37
  171. package/es/builtins/Alert.d.ts +0 -3
  172. package/es/builtins/Alert.js +0 -7
  173. package/es/builtins/Alert.less +0 -62
  174. package/es/builtins/Badge.d.ts +0 -3
  175. package/es/builtins/Badge.js +0 -7
  176. package/es/builtins/Badge.less +0 -31
  177. package/es/builtins/Example.d.ts +0 -5
  178. package/es/builtins/Example.less +0 -47
  179. package/es/builtins/Previewer.d.ts +0 -39
  180. package/es/builtins/Previewer.js +0 -225
  181. package/es/builtins/Previewer.less +0 -406
  182. package/es/builtins/SourceCode.d.ts +0 -10
  183. package/es/builtins/SourceCode.js +0 -70
  184. package/es/builtins/SourceCode.less +0 -103
  185. package/es/builtins/Table.d.ts +0 -4
  186. package/es/builtins/Table.js +0 -56
  187. package/es/builtins/Table.less +0 -43
  188. package/es/builtins/Tree.d.ts +0 -4
  189. package/es/builtins/Tree.js +0 -213
  190. package/es/builtins/Tree.less +0 -159
  191. package/es/components/Dark.d.ts +0 -9
  192. package/es/components/Dark.js +0 -125
  193. package/es/components/Dark.less +0 -121
  194. package/es/components/LocaleSelect.d.ts +0 -6
  195. package/es/components/LocaleSelect.js +0 -53
  196. package/es/components/LocaleSelect.less +0 -59
  197. package/es/components/Navbar.d.ts +0 -10
  198. package/es/components/Navbar.js +0 -155
  199. package/es/components/Navbar.less +0 -180
  200. package/es/components/SearchBar.d.ts +0 -4
  201. package/es/components/SearchBar.js +0 -81
  202. package/es/components/SearchBar.less +0 -165
  203. package/es/components/SideMenu.d.ts +0 -10
  204. package/es/components/SideMenu.js +0 -99
  205. package/es/components/SideMenu.less +0 -379
  206. package/es/components/SlugList.d.ts +0 -7
  207. package/es/components/SlugList.js +0 -38
  208. package/es/components/SlugList.less +0 -18
  209. package/es/declaration.d.ts +0 -1
  210. package/es/layout.d.ts +0 -5
  211. package/es/layout.js +0 -276
  212. package/es/style/layout.less +0 -402
  213. package/es/style/markdown.less +0 -240
  214. package/es/style/variables.less +0 -37
  215. package/src/antv/404/index.tsx +0 -25
  216. package/src/antv/Banner/Notification.tsx +0 -45
  217. package/src/antv/Banner/index.tsx +0 -139
  218. package/src/antv/Cases/Cases.tsx +0 -116
  219. package/src/antv/Features/FeatureCard.tsx +0 -24
  220. package/src/antv/Features/index.tsx +0 -86
  221. package/src/antv/Footer/Footer.module.less +0 -36
  222. package/src/antv/Footer/index.tsx +0 -272
  223. package/src/antv/Header/Logo.tsx +0 -85
  224. package/src/antv/Products/Product.tsx +0 -80
  225. package/src/antv/Products/getNewProducts.tsx +0 -53
  226. package/src/antv/Products/getProducts.tsx +0 -626
  227. package/src/antv/Products/index.tsx +0 -70
  228. package/src/antv/hooks.ts +0 -87
  229. package/src/antv/mixins.less +0 -21
  230. package/src/antv/utils.ts +0 -44
  231. package/src/builtins/API.tsx +0 -57
  232. package/src/builtins/Alert.less +0 -62
  233. package/src/builtins/Alert.tsx +0 -4
  234. package/src/builtins/Badge.less +0 -31
  235. package/src/builtins/Badge.tsx +0 -4
  236. package/src/builtins/Example.less +0 -47
  237. package/src/builtins/Example.tsx +0 -34
  238. package/src/builtins/Previewer.less +0 -406
  239. package/src/builtins/Previewer.tsx +0 -264
  240. package/src/builtins/SourceCode.less +0 -103
  241. package/src/builtins/SourceCode.tsx +0 -55
  242. package/src/builtins/Table.less +0 -43
  243. package/src/builtins/Table.tsx +0 -42
  244. package/src/builtins/Tree.less +0 -159
  245. package/src/builtins/Tree.tsx +0 -130
  246. package/src/components/Dark.less +0 -121
  247. package/src/components/Dark.tsx +0 -78
  248. package/src/components/LocaleSelect.less +0 -59
  249. package/src/components/LocaleSelect.tsx +0 -53
  250. package/src/components/Navbar.less +0 -180
  251. package/src/components/Navbar.tsx +0 -152
  252. package/src/components/SearchBar.less +0 -165
  253. package/src/components/SearchBar.tsx +0 -68
  254. package/src/components/SideMenu.less +0 -379
  255. package/src/components/SideMenu.tsx +0 -148
  256. package/src/components/SlugList.less +0 -18
  257. package/src/components/SlugList.tsx +0 -20
  258. package/src/declaration.d.ts +0 -1
  259. package/src/layout.tsx +0 -225
  260. package/src/style/layout.less +0 -402
  261. package/src/style/markdown.less +0 -240
  262. package/src/style/variables.less +0 -37
  263. package/src/test/SearchBar.test.ts +0 -32
  264. package/src/test/Table.test.tsx +0 -41
  265. package/src/test/index.test.tsx +0 -377
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+ export declare enum EDITOR_TABS {
3
+ JAVASCRIPT = "JavaScript",
4
+ DATA = "Data"
5
+ }
6
+ declare type ToolbarProps = {
7
+ /**
8
+ * 源码文件,用于传入到三方代码平台
9
+ */
10
+ sourceCode: string;
11
+ /**
12
+ * 生成代码文件名后缀,用于传入到三方代码平台
13
+ */
14
+ fileExtension: string;
15
+ /**
16
+ * 项目标题,用于传入到三方代码平台
17
+ */
18
+ title: {
19
+ zh?: string;
20
+ en?: string;
21
+ } | string;
22
+ location?: Location;
23
+ /**
24
+ * playground 的一些配置项
25
+ */
26
+ playground: {
27
+ container?: string;
28
+ playgroundDidMount?: string;
29
+ playgroundWillUnmount?: string;
30
+ dependencies?: {
31
+ [key: string]: string;
32
+ };
33
+ devDependencies?: {
34
+ [key: string]: string;
35
+ };
36
+ htmlCodeTemplate?: string;
37
+ json?: {
38
+ [key: string]: any;
39
+ };
40
+ };
41
+ /**
42
+ * 全屏状态,用于显示不同的 icon
43
+ */
44
+ isFullScreen?: boolean;
45
+ /**
46
+ * Tabs 数据
47
+ */
48
+ editorTabs: EDITOR_TABS[];
49
+ /**
50
+ * 当前编辑哪个 tab
51
+ */
52
+ currentEditorTab: EDITOR_TABS;
53
+ /**
54
+ * 切换 tab
55
+ */
56
+ onEditorTabChange: (tab: EDITOR_TABS) => void;
57
+ /**
58
+ * 进入/退出全屏
59
+ */
60
+ onToggleFullscreen?: null | (() => void);
61
+ /**
62
+ * 执行代码
63
+ */
64
+ onExecuteCode: () => void;
65
+ };
66
+ export declare const Toolbar: React.FC<ToolbarProps>;
67
+ export {};
@@ -0,0 +1,140 @@
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 } 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().then(function (status) {
72
+ return 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
+ }), /*#__PURE__*/React.createElement(Tooltip, {
133
+ title: useT('执行代码')
134
+ }, /*#__PURE__*/React.createElement(PlayCircleOutlined, {
135
+ onClick: onExecuteCode,
136
+ style: {
137
+ marginLeft: 12
138
+ }
139
+ })));
140
+ };
@@ -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,226 @@
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 { bind, clear } from 'size-sensor';
18
+ import { replaceInsertCss, execute, compile } from "./utils";
19
+ import { Toolbar, EDITOR_TABS } from "./Toolbar";
20
+ import { Loading } from "../Loading";
21
+ import styles from "./index.module.less";
22
+ loader.config({
23
+ 'vs/nls': {
24
+ availableLanguages: {
25
+ '*': 'zh-cn'
26
+ }
27
+ },
28
+ paths: {
29
+ vs: 'https://gw.alipayobjects.com/os/lib/monaco-editor/0.34.0/min/vs'
30
+ }
31
+ });
32
+
33
+ /**
34
+ * 代码编辑器
35
+ */
36
+ export var CodeEditor = function CodeEditor(_ref) {
37
+ 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
+ _ref$onReady = _ref.onReady,
47
+ onReady = _ref$onReady === void 0 ? noop : _ref$onReady,
48
+ _ref$onDestroy = _ref.onDestroy,
49
+ onDestroy = _ref$onDestroy === void 0 ? noop : _ref$onDestroy,
50
+ _ref$onError = _ref.onError,
51
+ onError = _ref$onError === void 0 ? noop : _ref$onError,
52
+ _ref$onFullscreen = _ref.onFullscreen,
53
+ onFullscreen = _ref$onFullscreen === void 0 ? noop : _ref$onFullscreen;
54
+ var locale = useLocale();
55
+ var _useSiteData$themeCon = useSiteData().themeConfig.playground.extraLib,
56
+ extraLib = _useSiteData$themeCon === void 0 ? '' : _useSiteData$themeCon; // 编辑器两个 tab,分别是代码和数据
57
+
58
+ var _useState = useState(null),
59
+ _useState2 = _slicedToArray(_useState, 2),
60
+ data = _useState2[0],
61
+ setData = _useState2[1];
62
+
63
+ var _useState3 = useState(source),
64
+ _useState4 = _slicedToArray(_useState3, 2),
65
+ code = _useState4[0],
66
+ setCode = _useState4[1]; // monaco instance
67
+
68
+
69
+ var monacoRef = useRef(null); // 文件后缀
70
+
71
+ var fileExtension = relativePath.split('.')[relativePath.split('.').length - 1] || 'js'; // 菜单栏
72
+
73
+ var _useState5 = useState([]),
74
+ _useState6 = _slicedToArray(_useState5, 2),
75
+ editorTabs = _useState6[0],
76
+ setEditorTabs = _useState6[1]; // 当前选中菜单栏
77
+
78
+
79
+ var _useState7 = useState(EDITOR_TABS.JAVASCRIPT),
80
+ _useState8 = _slicedToArray(_useState7, 2),
81
+ currentEditorTab = _useState8[0],
82
+ setCurrentEditorTab = _useState8[1]; // 出发 auto resize
83
+
84
+
85
+ var dispatchResizeEvent = function dispatchResizeEvent() {
86
+ var e = new Event('resize');
87
+ window.dispatchEvent(e);
88
+ };
89
+
90
+ var reportError = useCallback(function (e) {
91
+ if (e) {
92
+ console.log(e);
93
+ onError(e);
94
+ e.preventDefault && e.preventDefault();
95
+ } else {
96
+ onError(null);
97
+ }
98
+ }, []);
99
+ useEffect(function () {
100
+ // 用于上报错误信息,使用 script 执行代码
101
+ if (typeof window !== 'undefined') {
102
+ // Cath error of code.
103
+ window.__reportErrorInPlayground = reportError; // Catch error of timeout/raf.
104
+
105
+ window.onerror = reportError; // Catch error of promise.
106
+
107
+ window.addEventListener('unhandledrejection', reportError);
108
+ }
109
+
110
+ return function () {
111
+ if (window) {
112
+ window.__reportErrorInPlayground = undefined;
113
+ window.onerror = undefined;
114
+ window.removeEventListener('unhandledrejection', reportError);
115
+ }
116
+ };
117
+ }, []);
118
+ var executeCode = useCallback(debounce(function (v) {
119
+ if (!v) return; // 1. 先编译代码
120
+
121
+ var compiled;
122
+
123
+ try {
124
+ compiled = compile(replaceInsertCss(v, locale.id), relativePath);
125
+ } catch (e) {
126
+ reportError(e); // 执行出错,后面的步骤不用做了!
127
+
128
+ return;
129
+ } // 2. 执行代码,try catch 在内部已经做了
130
+
131
+
132
+ execute(compiled, 'playgroundScriptContainer', playground === null || playground === void 0 ? void 0 : playground.container, replaceId);
133
+ }, 300), []);
134
+ useEffect(function () {
135
+ setCode(source);
136
+ }, [source]);
137
+ useEffect(function () {
138
+ executeCode(code);
139
+ }, [code]);
140
+ useEffect(function () {
141
+ var dom = document.getElementById('playgroundScriptContainer');
142
+ bind(dom, debounce(function () {
143
+ dispatchResizeEvent();
144
+ }, 100));
145
+ onReady();
146
+
147
+ if (playground !== null && playground !== void 0 && playground.playgroundDidMount) {
148
+ new Function(playground.playgroundDidMount)();
149
+ }
150
+
151
+ return function () {
152
+ clear(dom);
153
+ onDestroy();
154
+
155
+ if (playground !== null && playground !== void 0 && playground.playgroundWillUnmount) {
156
+ new Function(playground.playgroundWillUnmount)();
157
+ }
158
+ };
159
+ }, []); // hook 用户的数据
160
+
161
+ useEffect(function () {
162
+ var dataFileMatch = source.match(/fetch\('(.*)'\)/);
163
+
164
+ if (dataFileMatch && dataFileMatch.length > 0) {
165
+ fetch(dataFileMatch[1]).then(function (response) {
166
+ return response.json();
167
+ }).then(function (data) {
168
+ setEditorTabs([EDITOR_TABS.JAVASCRIPT, EDITOR_TABS.DATA]);
169
+ setData(data);
170
+ });
171
+ }
172
+ }, []);
173
+ useEffect(function () {
174
+ if (monacoRef.current) {
175
+ monacoRef.current.setValue(currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2));
176
+ }
177
+ }, [currentEditorTab]);
178
+ var onCodeChange = useCallback(function (value) {
179
+ if (currentEditorTab === EDITOR_TABS.JAVASCRIPT) {
180
+ setCode(value);
181
+ }
182
+ }, []);
183
+ return /*#__PURE__*/React.createElement("div", {
184
+ className: styles.editor
185
+ }, /*#__PURE__*/React.createElement(Toolbar, {
186
+ fileExtension: fileExtension,
187
+ sourceCode: code,
188
+ playground: playground,
189
+ location: location,
190
+ title: title,
191
+ isFullScreen: isFullscreen,
192
+ editorTabs: editorTabs,
193
+ currentEditorTab: currentEditorTab,
194
+ onExecuteCode: function onExecuteCode() {
195
+ return executeCode(code);
196
+ },
197
+ onEditorTabChange: setCurrentEditorTab,
198
+ onToggleFullscreen: onFullscreen
199
+ }), /*#__PURE__*/React.createElement("div", {
200
+ className: styles.monaco,
201
+ style: {
202
+ height: 'calc(100% - 36px)'
203
+ }
204
+ }, /*#__PURE__*/React.createElement(MonacoEditor, {
205
+ language: currentEditorTab === EDITOR_TABS.JAVASCRIPT ? 'javascript' : 'json',
206
+ value: code,
207
+ path: relativePath,
208
+ loading: /*#__PURE__*/React.createElement(Loading, null),
209
+ options: {
210
+ readOnly: currentEditorTab === EDITOR_TABS.DATA,
211
+ automaticLayout: true,
212
+ minimap: {
213
+ enabled: false
214
+ },
215
+ scrollBeyondLastLine: false,
216
+ fixedOverflowWidgets: true,
217
+ lineNumbersMinChars: 4,
218
+ showFoldingControls: 'always',
219
+ foldingHighlight: true
220
+ },
221
+ onChange: onCodeChange,
222
+ onMount: function onMount(editor) {
223
+ monacoRef.current = editor;
224
+ }
225
+ })));
226
+ };
@@ -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;