@antv/dumi-theme-antv 0.4.6 → 0.5.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 (38) hide show
  1. package/README.md +4 -1
  2. package/dist/layouts/DocLayout.d.ts +2 -1
  3. package/dist/layouts/entry/Index.js +2 -2
  4. package/dist/model/index.d.ts +5 -0
  5. package/dist/model/index.js +6 -0
  6. package/dist/pages/Example/components/CollapsedIcon/index.d.ts +8 -0
  7. package/dist/pages/Example/components/CollapsedIcon/index.js +15 -0
  8. package/dist/pages/Example/components/CollapsedIcon/index.module.less +14 -0
  9. package/dist/pages/Example/index.js +28 -11
  10. package/dist/pages/Examples/components/Accouncement/index.js +2 -2
  11. package/dist/pages/Examples/components/GalleryPageContent/index.js +2 -2
  12. package/dist/plugin/api.d.ts +7 -0
  13. package/dist/plugin/api.js +82 -0
  14. package/dist/plugin/examples.d.ts +1 -1
  15. package/dist/plugin/examples.js +29 -22
  16. package/dist/plugin/index.js +2 -1
  17. package/dist/slots/API/index.d.ts +15 -0
  18. package/dist/slots/API/index.js +202 -0
  19. package/dist/slots/API/index.module.less +93 -0
  20. package/dist/slots/Banner/index.js +2 -2
  21. package/dist/slots/CodeEditor/Toolbar.js +2 -2
  22. package/dist/slots/CodeEditor/index.js +1 -1
  23. package/dist/slots/CodeEditor/utils.js +7 -9
  24. package/dist/slots/CodeRunner/utils.js +4 -3
  25. package/dist/slots/Detail/index.js +5 -3
  26. package/dist/slots/ExampleSider/index.js +2 -3
  27. package/dist/slots/Footer/index.js +14 -4
  28. package/dist/slots/Header/Navs.js +2 -2
  29. package/dist/slots/Header/Products/Product.module.less +9 -0
  30. package/dist/slots/Header/Products/getProducts.js +2 -2
  31. package/dist/slots/Header/Products/index.d.ts +1 -0
  32. package/dist/slots/Header/Products/index.js +5 -4
  33. package/dist/slots/Header/index.js +18 -18
  34. package/dist/slots/Loading/index.d.ts +2 -3
  35. package/dist/slots/Loading/index.js +1 -8
  36. package/dist/slots/ManualContent/index.js +2 -2
  37. package/dist/slots/ManualContent/index.module.less +2 -2
  38. package/package.json +37 -32
package/README.md CHANGED
@@ -34,7 +34,7 @@ TODO
34
34
  ## Development
35
35
 
36
36
  ```bash
37
- $ tnpm install
37
+ $ npm install
38
38
  ```
39
39
 
40
40
  After the dependencies are installed, a symlink from `example/.dumi/theme` to `../../src` will be created automatically, the symlink makes dumi load our theme package as a local theme, so we can start the example directly, HMR is also available:
@@ -43,6 +43,9 @@ After the dependencies are installed, a symlink from `example/.dumi/theme` to `.
43
43
  # switch to example directory
44
44
  $ cd example
45
45
 
46
+ # downloads the dependencies
47
+ npm install
48
+
46
49
  # start dev server to preview
47
50
  npm run dev
48
51
  ```
@@ -1,7 +1,8 @@
1
+ import React from 'react';
1
2
  import '../slots/global';
2
3
  import '../slots/_.less';
3
4
  /**
4
5
  * DocuLayout 是 dumi2 的内置 layout 入口,在这里使用页面路径进行区分成自己不同的 Layout。
5
6
  */
6
- declare const _default: () => any;
7
+ declare const _default: () => React.JSX.Element;
7
8
  export default _default;
@@ -2,8 +2,8 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
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); }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  import React from 'react';
8
8
  import { useLocale, useSiteData, FormattedMessage } from 'dumi';
9
9
  import { SEO } from "dumi/theme/slots/SEO";
@@ -0,0 +1,5 @@
1
+ export declare const store: {
2
+ hideMenu: boolean;
3
+ showAPI: boolean;
4
+ apiContainerWidth: number;
5
+ };
@@ -0,0 +1,6 @@
1
+ import { proxy } from 'valtio';
2
+ export var store = proxy({
3
+ hideMenu: false,
4
+ showAPI: false,
5
+ apiContainerWidth: 420
6
+ });
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ interface CollapsedProps {
3
+ isCollapsed: boolean;
4
+ style?: React.CSSProperties;
5
+ onClick?: (isCollapsed: boolean) => void;
6
+ }
7
+ export declare const CollapsedIcon: React.FC<CollapsedProps>;
8
+ export {};
@@ -0,0 +1,15 @@
1
+ import { DoubleLeftOutlined, DoubleRightOutlined } from '@ant-design/icons';
2
+ import React from 'react';
3
+ import styles from "./index.module.less";
4
+ export var CollapsedIcon = function CollapsedIcon(props) {
5
+ var isCollapsed = props.isCollapsed,
6
+ _onClick = props.onClick,
7
+ style = props.style;
8
+ return /*#__PURE__*/React.createElement("div", {
9
+ className: styles.collapsed,
10
+ onClick: function onClick() {
11
+ _onClick(!isCollapsed);
12
+ },
13
+ style: style
14
+ }, isCollapsed ? /*#__PURE__*/React.createElement(DoubleRightOutlined, null) : /*#__PURE__*/React.createElement(DoubleLeftOutlined, null));
15
+ };
@@ -0,0 +1,14 @@
1
+ @collapsed-icon-size: 36px;
2
+
3
+ .collapsed {
4
+ position: absolute;
5
+ z-index: 3;
6
+ width: 24px;
7
+ height: @collapsed-icon-size;
8
+ line-height: @collapsed-icon-size;
9
+ font-size: 18px;
10
+ color: #777;
11
+ cursor: pointer;
12
+ background: #f8f9fc;
13
+ text-align: center;
14
+ }
@@ -6,15 +6,19 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { Layout } from 'antd';
8
8
  import { useLocale, useSiteData } from 'dumi';
9
- import { get, find } from 'lodash-es';
10
- import React, { useContext, useEffect, useState, useMemo } from 'react';
9
+ import { every, find, get } from 'lodash-es';
10
+ import React, { useContext, useEffect, useMemo, useState } from 'react';
11
11
  import { useLocation, useNavigate, useParams } from 'react-router-dom';
12
+ import { useSnapshot } from 'valtio';
12
13
  import { ThemeAntVContext } from "../../context";
14
+ import { store } from "../../model";
15
+ import { API } from "dumi/theme/slots/API";
13
16
  import { CodeRunner } from "dumi/theme/slots/CodeRunner";
14
17
  import { getDemoInfo } from "../../slots/CodeRunner/utils";
15
18
  import { ExampleSider } from "dumi/theme/slots/ExampleSider";
16
19
  import { Header } from "dumi/theme/slots/Header";
17
20
  import { SEO } from "dumi/theme/slots/SEO";
21
+ import { CollapsedIcon } from "./components/CollapsedIcon";
18
22
  import styles from "./index.module.less";
19
23
  import { getCurrentTitle } from "./utils";
20
24
  var Sider = Layout.Sider,
@@ -48,14 +52,11 @@ var Example = function Example() {
48
52
  _useState2 = _slicedToArray(_useState, 2),
49
53
  currentDemo = _useState2[0],
50
54
  setCurrentDemo = _useState2[1];
51
- var _useState3 = useState(false),
55
+ var state = useSnapshot(store);
56
+ var _useState3 = useState({}),
52
57
  _useState4 = _slicedToArray(_useState3, 2),
53
- isCollapsed = _useState4[0],
54
- setIsCollapsed = _useState4[1];
55
- var _useState5 = useState({}),
56
- _useState6 = _slicedToArray(_useState5, 2),
57
- title = _useState6[0],
58
- setTitle = _useState6[1];
58
+ title = _useState4[0],
59
+ setTitle = _useState4[1];
59
60
  useEffect(function () {
60
61
  if (topic && example && demo) {
61
62
  var targetDemoInfo = getDemoInfo(exampleTopics, topic, example, demo);
@@ -63,6 +64,7 @@ var Example = function Example() {
63
64
  setTitle(getCurrentTitle(exampleTopics, topic, example));
64
65
  }
65
66
  }, [topic, example, hash]);
67
+ var showAPI = every([get(themeConfig, 'showAPIDoc'), topic, example], Boolean);
66
68
  return /*#__PURE__*/React.createElement("div", {
67
69
  className: styles.example
68
70
  }, /*#__PURE__*/React.createElement(SEO, {
@@ -77,7 +79,7 @@ var Example = function Example() {
77
79
  width: 250,
78
80
  trigger: null,
79
81
  collapsible: true,
80
- collapsed: isCollapsed,
82
+ collapsed: state.hideMenu,
81
83
  className: styles.menuSider,
82
84
  theme: "light"
83
85
  }, currentDemo && /*#__PURE__*/React.createElement(ExampleSider, {
@@ -92,6 +94,15 @@ var Example = function Example() {
92
94
  nav(newURL);
93
95
  },
94
96
  exampleTopics: exampleTopics
97
+ }), /*#__PURE__*/React.createElement(CollapsedIcon, {
98
+ isCollapsed: state.hideMenu,
99
+ onClick: function onClick(show) {
100
+ store.hideMenu = show;
101
+ },
102
+ style: {
103
+ bottom: 0,
104
+ right: state.hideMenu ? -24 : 0
105
+ }
95
106
  })), /*#__PURE__*/React.createElement(Content, {
96
107
  className: styles.content
97
108
  }, topic && example && /*#__PURE__*/React.createElement(CodeRunner, {
@@ -100,6 +111,12 @@ var Example = function Example() {
100
111
  example: example,
101
112
  demo: demo,
102
113
  size: get(themeConfig, 'editor.size', 0.38)
103
- }))));
114
+ })), showAPI && /*#__PURE__*/React.createElement(API, {
115
+ exampleTopics: exampleTopics,
116
+ topic: topic,
117
+ example: example,
118
+ demo: demo,
119
+ language: locale.id
120
+ })));
104
121
  };
105
122
  export default Example;
@@ -2,8 +2,8 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  var _excluded = ["message", "bannerId", "localStorageId"];
3
3
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
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); }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
8
8
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
9
9
  import React, { useEffect } from 'react';
@@ -2,8 +2,8 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
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); }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  import React from 'react';
8
8
  import { useLocale } from 'dumi';
9
9
  import { DemoCard } from "./DemoCard";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 获取API
3
+ *
4
+ * @param {string} apiPath API路径
5
+ * @returns {string} 文件内容
6
+ */
7
+ export declare const getExampleAPI: (apiPath: string) => string;
@@ -0,0 +1,82 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/plugin/api.ts
30
+ var api_exports = {};
31
+ __export(api_exports, {
32
+ getExampleAPI: () => getExampleAPI
33
+ });
34
+ module.exports = __toCommonJS(api_exports);
35
+ var fs = __toESM(require("fs-extra"));
36
+ var MARKDOWN_REG_SIGN = /`markdown:([^`]*)`/;
37
+ var EMBED_REG_SIGN = /<embed[^>]*src=["']([^"']*)["'][^>]*[>/>]/;
38
+ var getContent = (filePath) => {
39
+ let content = "";
40
+ try {
41
+ const currentContent = fs.readFileSync(filePath).toString();
42
+ const lines = currentContent.split("\n");
43
+ let isTitle = false;
44
+ lines.forEach((line) => {
45
+ if (line.startsWith("---")) {
46
+ isTitle = !isTitle;
47
+ } else {
48
+ if (!isTitle) {
49
+ let nestedPath = "";
50
+ const markdownMatch = MARKDOWN_REG_SIGN.exec(line);
51
+ const embedMatch = EMBED_REG_SIGN.exec(line);
52
+ if (markdownMatch) {
53
+ nestedPath = markdownMatch[1];
54
+ }
55
+ if (embedMatch) {
56
+ nestedPath = embedMatch[1].replace(/@\//g, "");
57
+ }
58
+ if (nestedPath) {
59
+ content += getContent(nestedPath);
60
+ } else {
61
+ content += `${line}
62
+ `;
63
+ }
64
+ }
65
+ }
66
+ });
67
+ } catch (e) {
68
+ console.error(e);
69
+ }
70
+ return content;
71
+ };
72
+ var getExampleAPI = (apiPath) => {
73
+ if (!fs.existsSync(apiPath)) {
74
+ console.error(`File does not exist: ${apiPath}`);
75
+ return "";
76
+ }
77
+ return getContent(apiPath);
78
+ };
79
+ // Annotate the CommonJS export names for ESM import in node:
80
+ 0 && (module.exports = {
81
+ getExampleAPI
82
+ });
@@ -5,7 +5,7 @@ import { Example, ExampleTopic } from '../types';
5
5
  * @returns {ExampleTopic[]} 案例主题列表
6
6
  * @author YuZhanglong <loveyzl1123@gmail.com>
7
7
  */
8
- export declare const getExamplesPageTopics: (exampleTopics: ExampleTopic[]) => {
8
+ export declare const getExamplesPageTopics: (exampleTopics: ExampleTopic[], showAPIDoc: boolean) => {
9
9
  id: string;
10
10
  title: {
11
11
  zh: string;
@@ -33,10 +33,11 @@ __export(examples_exports, {
33
33
  getExamplesPageTopics: () => getExamplesPageTopics
34
34
  });
35
35
  module.exports = __toCommonJS(examples_exports);
36
+ var import_front_matter = __toESM(require("front-matter"));
37
+ var fs = __toESM(require("fs-extra"));
36
38
  var glob = __toESM(require("glob"));
37
39
  var path = __toESM(require("path"));
38
- var fs = __toESM(require("fs-extra"));
39
- var import_front_matter = __toESM(require("front-matter"));
40
+ var import_api = require("./api");
40
41
  var examplesBaseDir = path.resolve(process.cwd(), "examples");
41
42
  var getExampleDemos = (exampleDir) => {
42
43
  const demoMetaJSON = fs.readFileSync(path.resolve(exampleDir, "demo", "meta.json")).toString();
@@ -55,13 +56,20 @@ var getExampleDemos = (exampleDir) => {
55
56
  });
56
57
  return demos;
57
58
  };
58
- var getTopicExamples = (topicPath) => {
59
- const examplePaths = glob.sync(`${topicPath}/*`).filter((item) => {
59
+ var getTopicExamples = (topicPath, showAPIDoc) => {
60
+ const examplePaths = glob.sync(`${topicPath.replace(/\\/g, "/")}/*`).filter((item) => {
60
61
  return !item.endsWith(".js");
61
62
  });
62
63
  return examplePaths.map((item) => {
63
64
  const exampleMetaZh = fs.readFileSync(path.resolve(item, "index.zh.md")).toString();
64
65
  const exampleMetaEn = fs.readFileSync(path.resolve(item, "index.en.md")).toString();
66
+ let api = null;
67
+ if (showAPIDoc) {
68
+ api = {
69
+ zh: (0, import_api.getExampleAPI)(path.resolve(item, "API.zh.md")),
70
+ en: (0, import_api.getExampleAPI)(path.resolve(item, "API.en.md"))
71
+ };
72
+ }
65
73
  const exampleMetaZhContent = (0, import_front_matter.default)(exampleMetaZh);
66
74
  const exampleMetaEnContent = (0, import_front_matter.default)(exampleMetaEn);
67
75
  const example = {
@@ -73,31 +81,30 @@ var getTopicExamples = (topicPath) => {
73
81
  en: exampleMetaEnContent.attributes.title,
74
82
  zh: exampleMetaZhContent.attributes.title
75
83
  },
84
+ api,
76
85
  childrenKey: "demos",
77
86
  order: exampleMetaZhContent.attributes.order || 0
78
87
  };
79
88
  return example;
80
89
  }).sort((a, b) => a.order - b.order);
81
90
  };
82
- var getExamplesPageTopics = (exampleTopics) => {
83
- return exampleTopics.map(
84
- ({ id, slug, title, icon }) => {
85
- const nid = id || slug;
86
- let examples = [];
87
- try {
88
- examples = getTopicExamples(path.join(examplesBaseDir, nid));
89
- } catch (e) {
90
- console.warn(e);
91
- }
92
- return {
93
- id: nid,
94
- title,
95
- icon,
96
- examples,
97
- childrenKey: "examples"
98
- };
91
+ var getExamplesPageTopics = (exampleTopics, showAPIDoc) => {
92
+ return exampleTopics.map(({ id, slug, title, icon }) => {
93
+ const nid = id || slug;
94
+ let examples = [];
95
+ try {
96
+ examples = getTopicExamples(path.join(examplesBaseDir, nid), showAPIDoc);
97
+ } catch (e) {
98
+ console.warn(e);
99
99
  }
100
- );
100
+ return {
101
+ id: nid,
102
+ title,
103
+ icon,
104
+ examples,
105
+ childrenKey: "examples"
106
+ };
107
+ });
101
108
  };
102
109
  function getExamplePaths() {
103
110
  const exampleTopicPaths = glob.sync(`${examplesBaseDir}/*/*`);
@@ -106,7 +106,8 @@ export default function ThemeAntVContextWrapper() {
106
106
  value={{
107
107
  meta: ${JSON.stringify({
108
108
  exampleTopics: (0, import_examples.getExamplesPageTopics)(
109
- api.config.themeConfig.examples || []
109
+ api.config.themeConfig.examples || [],
110
+ api.userConfig.themeConfig.showAPIDoc
110
111
  )
111
112
  })}
112
113
  }}
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { ExampleTopic } from '../../types';
3
+ type APIProps = {
4
+ isPlayground?: boolean;
5
+ topic: string;
6
+ example: string;
7
+ demo: string;
8
+ exampleTopics: ExampleTopic[];
9
+ language?: string;
10
+ };
11
+ /**
12
+ * API 预览
13
+ */
14
+ export declare const API: ({ exampleTopics, topic, example, demo, language, }: APIProps) => React.JSX.Element;
15
+ export {};
@@ -0,0 +1,202 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ 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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ import { ZoomInOutlined, ZoomOutOutlined } from '@ant-design/icons';
9
+ import { Collapse, Popover } from 'antd';
10
+ import { get, uniq, sortBy } from 'lodash-es';
11
+ import React from 'react';
12
+ import Markdown from 'react-markdown';
13
+ import remarkGfm from 'remark-gfm';
14
+ import rehypeRaw from 'rehype-raw';
15
+ import { useSnapshot } from 'valtio';
16
+ import { store } from "../../model";
17
+ import { CollapsedIcon } from "../../pages/Example/components/CollapsedIcon";
18
+ import { getDemoInfo } from "../CodeRunner/utils";
19
+ import styles from "./index.module.less";
20
+ var Panel = Collapse.Panel;
21
+ var EMPTY = /^\s*$/;
22
+ /**
23
+ * API 预览
24
+ */
25
+ export var API = function API(_ref) {
26
+ var exampleTopics = _ref.exampleTopics,
27
+ topic = _ref.topic,
28
+ example = _ref.example,
29
+ demo = _ref.demo,
30
+ _ref$language = _ref.language,
31
+ language = _ref$language === void 0 ? 'zh' : _ref$language;
32
+ var state = useSnapshot(store);
33
+ var demoInfo = getDemoInfo(exampleTopics, topic, example, demo);
34
+ var APIContent = get(demoInfo, ['api', language]);
35
+
36
+ /** 从 MD 中解析出层级数据(eg: #、##、###)作为折叠分组条件 */
37
+ var findHashTag = function findHashTag(lines) {
38
+ var tagLines = lines.filter(function (line) {
39
+ return line.startsWith('#');
40
+ });
41
+ var tagReg = /^#+/g;
42
+ var tagLengths = tagLines.map(function (line) {
43
+ return line.match(tagReg)[0].length;
44
+ });
45
+ return sortBy(uniq(tagLengths));
46
+ };
47
+ var getRegex = function getRegex(tagLength) {
48
+ return new RegExp("^".concat(new Array(tagLength).fill('#').join(''), "\\s+([^\\n]*)"));
49
+ };
50
+
51
+ /** 根据正则将内容切片 */
52
+ var setIndexTag = function setIndexTag(lines, regex) {
53
+ var start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
54
+ var result = [];
55
+ lines.forEach(function (line, index) {
56
+ if (regex.exec(line)) {
57
+ var header = regex.exec(line)[1];
58
+ result.push({
59
+ header: header,
60
+ start: index + start,
61
+ maxEndIndex: start + lines.length
62
+ });
63
+ }
64
+ });
65
+ return result;
66
+ };
67
+
68
+ /** 从 MD 中解析出嵌套结构, 最多支持 2 层 */
69
+ var getNestedDOM = function getNestedDOM(lines) {
70
+ var tags = findHashTag(lines);
71
+ var result = setIndexTag(lines, getRegex(tags[0]));
72
+ if (tags.length > 2) {
73
+ result = result.map(function (item, index) {
74
+ var _result;
75
+ var start = item.start;
76
+ return _objectSpread(_objectSpread({}, item), {}, {
77
+ children: setIndexTag(lines.slice(start + 1, (_result = result[index + 1]) === null || _result === void 0 ? void 0 : _result.start), getRegex(tags[1]), start + 1)
78
+ });
79
+ });
80
+ }
81
+ return result;
82
+ };
83
+ var MarkdownComponent = function MarkdownComponent(_ref2) {
84
+ var content = _ref2.content;
85
+ return /*#__PURE__*/React.createElement(Markdown, {
86
+ rehypePlugins: [rehypeRaw, remarkGfm],
87
+ components: {
88
+ // @ts-expect-error
89
+ description: function description(props) {
90
+ return /*#__PURE__*/React.createElement("span", _extends({
91
+ style: {
92
+ fontSize: 12,
93
+ color: '#777'
94
+ }
95
+ }, props));
96
+ }
97
+ }
98
+ }, content);
99
+ };
100
+
101
+ /** 将扁平状态的 MD 解析为嵌套结构 */
102
+ var renderNestedDom = function renderNestedDom(content) {
103
+ var _result$;
104
+ if (!content) {
105
+ return null;
106
+ }
107
+ var lines = content.split('\n');
108
+ var result = getNestedDOM(lines);
109
+
110
+ /** 避免无标题的情况内容丢失,内层嵌套的不做处理(不合理) */
111
+ var minStart = get(result, [0, 'start']);
112
+ return /*#__PURE__*/React.createElement(React.Fragment, null, minStart > 0 && /*#__PURE__*/React.createElement("div", {
113
+ className: styles.disorganized
114
+ }, /*#__PURE__*/React.createElement(MarkdownComponent, {
115
+ content: lines.slice(0, minStart).join('\n')
116
+ })), /*#__PURE__*/React.createElement(Collapse, {
117
+ bordered: false,
118
+ defaultActiveKey: [(_result$ = result[0]) === null || _result$ === void 0 ? void 0 : _result$.header],
119
+ ghost: true
120
+ }, result.map(function (item, index) {
121
+ var _children$;
122
+ var start = item.start,
123
+ header = item.header,
124
+ _item$children = item.children,
125
+ children = _item$children === void 0 ? [] : _item$children;
126
+ var end = index === result.length - 1 ? lines.length : result[index + 1].start;
127
+ return /*#__PURE__*/React.createElement(Panel, {
128
+ header: /*#__PURE__*/React.createElement("b", {
129
+ style: {
130
+ lineHeight: '22px',
131
+ fontSize: 16
132
+ }
133
+ }, header),
134
+ key: header
135
+ }, children.length > 0 ? /*#__PURE__*/React.createElement(Collapse, {
136
+ bordered: false,
137
+ defaultActiveKey: [(_children$ = children[0]) === null || _children$ === void 0 ? void 0 : _children$.header],
138
+ ghost: true
139
+ }, children.map(function (nestedItem, nestedIndex) {
140
+ var nestedStart = nestedItem.start,
141
+ nestedHeader = nestedItem.header,
142
+ maxEndIndex = nestedItem.maxEndIndex;
143
+ var nestEnd = nestedIndex === children.length - 1 ? maxEndIndex : children[nestedIndex + 1].start;
144
+ return /*#__PURE__*/React.createElement(Panel, {
145
+ header: /*#__PURE__*/React.createElement("b", {
146
+ style: {
147
+ lineHeight: '22px',
148
+ fontSize: 14
149
+ }
150
+ }, nestedHeader),
151
+ key: nestedHeader
152
+ }, /*#__PURE__*/React.createElement(MarkdownComponent, {
153
+ content: lines.slice(nestedStart + 1, nestEnd).join('\n')
154
+ }));
155
+ })) : /*#__PURE__*/React.createElement(MarkdownComponent, {
156
+ content: lines.slice(start + 1, end).join('\n')
157
+ }));
158
+ })));
159
+ };
160
+ return /*#__PURE__*/React.createElement("div", {
161
+ className: styles.api,
162
+ style: {
163
+ width: state.showAPI ? state.apiContainerWidth : 24
164
+ }
165
+ }, /*#__PURE__*/React.createElement("div", {
166
+ className: styles.header
167
+ }, /*#__PURE__*/React.createElement("p", null, "API"), /*#__PURE__*/React.createElement("div", {
168
+ className: styles.zoom
169
+ }, /*#__PURE__*/React.createElement(ZoomInOutlined, {
170
+ onClick: function onClick() {
171
+ store.apiContainerWidth += 100;
172
+ }
173
+ }), /*#__PURE__*/React.createElement(ZoomOutOutlined, {
174
+ style: {
175
+ marginLeft: 8
176
+ },
177
+ onClick: function onClick() {
178
+ if (state.apiContainerWidth > 150) {
179
+ store.apiContainerWidth -= 100;
180
+ }
181
+ }
182
+ })), /*#__PURE__*/React.createElement(Popover, {
183
+ content: language === 'zh' ? '展示文档' : 'Show docs',
184
+ placement: "right"
185
+ }, /*#__PURE__*/React.createElement(CollapsedIcon, {
186
+ isCollapsed: state.showAPI,
187
+ onClick: function onClick(show) {
188
+ store.showAPI = show;
189
+ },
190
+ style: {
191
+ left: 0,
192
+ top: 0
193
+ }
194
+ }))), /*#__PURE__*/React.createElement("div", {
195
+ className: styles.content
196
+ }, !EMPTY.test(APIContent) ? renderNestedDom(APIContent) : /*#__PURE__*/React.createElement("div", {
197
+ style: {
198
+ textAlign: 'center',
199
+ padding: 12
200
+ }
201
+ }, /*#__PURE__*/React.createElement("h1", null, "404"), /*#__PURE__*/React.createElement("p", null, "Sorry, the API you visited does not exist."))));
202
+ };