@antv/dumi-theme-antv 0.3.0-beta.5 → 0.3.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/context.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
+ import { ExampleTopic } from './types';
2
3
  export declare type IThemeAntVContext = {
3
- exampleTopics?: ExamplesPage.ExampleTopic[];
4
+ exampleTopics?: ExampleTopic[];
4
5
  };
5
6
  export declare const ThemeAntVContext: import("react").Context<IThemeAntVContext>;
@@ -1,7 +1,6 @@
1
1
  import React, { useEffect } from 'react';
2
- import { useOutlet, useLocation } from 'dumi';
2
+ import { useOutlet, useLocation, useSiteData } from 'dumi';
3
3
  import { Index } from "./entry/Index";
4
- import { API } from "./entry/API";
5
4
  import { Manual } from "./entry/Manual"; // 用户手动添加自己的
6
5
 
7
6
  import "../slots/global";
@@ -11,7 +10,11 @@ import "../slots/_.less";
11
10
  */
12
11
 
13
12
  export default (function () {
14
- // 打印控制台文案
13
+ var _useSiteData = useSiteData(),
14
+ themeConfig = _useSiteData.themeConfig;
15
+
16
+ var navs = themeConfig.navs; // 打印控制台文案
17
+
15
18
  useEffect(function () {
16
19
  console.log("%cAntV 让数据栩栩如生", "color:#5B7102; font-size: 20px;"), console.log("%c新一代数据可视化解决方案", "color:#5B7102;"), console.log("--------------------------"), console.log("%c关注我们的微信公众号 %c“数据可视化 AntV”%c,获取我们团队最新的进展、动态、分享,也欢迎加入我们!", "color: red", "color: pink", "color: red");
17
20
  }, []);
@@ -20,23 +23,26 @@ export default (function () {
20
23
  var _useLocation = useLocation(),
21
24
  pathname = _useLocation.pathname;
22
25
 
23
- var path = pathname.toLowerCase(); // 统一去掉中英文前缀
26
+ var path = pathname; // 统一去掉中英文前缀
24
27
 
25
28
  var p = path.replace('/zh/', '/').replace('/en/', '/'); // 首页
26
29
 
27
- if (p === '/' || p === '/zh' || p === '/en' || p === '/en/') return /*#__PURE__*/React.createElement(Index, null); // API 页面
28
-
29
- if (p.startsWith('/api') || // 这两个是兼容之前的
30
- p.startsWith('/docs/api')) {
31
- return /*#__PURE__*/React.createElement(API, null, " ", outlet, " ");
32
- } // 教程页面
33
-
34
-
35
- if (p.startsWith('/manual') || // 这两个是兼容之前的
36
- p.startsWith('/docs/manual')) {
37
- return /*#__PURE__*/React.createElement(Manual, null, " ", outlet, " ");
38
- } // More router, add here...
39
-
30
+ if (p === '/' || p === '/zh' || p === '/en' || p === '/en/') return /*#__PURE__*/React.createElement(Index, null); // 匹配 navs 中的 docs 路由
31
+
32
+ var hasDocsRoutes = navs.filter(function (nav) {
33
+ return nav.slug.startsWith('docs/');
34
+ });
35
+ var docsRoutes = hasDocsRoutes.map(function (nav) {
36
+ return nav.slug.split('/').find(function (item) {
37
+ return item !== 'docs';
38
+ });
39
+ });
40
+
41
+ if (docsRoutes.some(function (route) {
42
+ return p.startsWith("/".concat(route)) || p.startsWith("/docs/".concat(route));
43
+ })) {
44
+ return /*#__PURE__*/React.createElement(Manual, null, outlet);
45
+ }
40
46
 
41
47
  return outlet;
42
48
  });
@@ -12,8 +12,9 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
13
  import React, { useContext, useEffect, useState } from 'react';
14
14
  import { useParams, useLocation, useNavigate } from 'react-router-dom';
15
+ import { get } from 'lodash-es';
15
16
  import { Layout } from 'antd';
16
- import { useLocale } from 'dumi';
17
+ import { useLocale, useSiteData } from 'dumi';
17
18
  import { Header } from "../../slots/Header";
18
19
  import { ExampleSider } from "../../slots/ExampleSider";
19
20
  import { CodeRunner } from "../../slots/CodeRunner";
@@ -40,6 +41,10 @@ var Example = function Example() {
40
41
 
41
42
  var metaData = useContext(ThemeAntVContext);
42
43
  var locale = useLocale();
44
+
45
+ var _useSiteData = useSiteData(),
46
+ themeConfig = _useSiteData.themeConfig;
47
+
43
48
  var exampleTopics = metaData.meta.exampleTopics;
44
49
  var demo = hash.slice(1);
45
50
 
@@ -91,7 +96,8 @@ var Example = function Example() {
91
96
  exampleTopics: exampleTopics,
92
97
  topic: topic,
93
98
  example: example,
94
- demo: demo
99
+ demo: demo,
100
+ size: get(themeConfig, 'editor.size', 0.4)
95
101
  }))));
96
102
  };
97
103
 
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { ExampleTopic, Example, Demo } from '../../types';
2
3
  export interface AnnouncementProps {
3
4
  message: React.ReactNode;
4
5
  localStorageId: string;
@@ -9,19 +10,19 @@ export interface GalleryPageContentProps {
9
10
  /**
10
11
  * 案例主题列表
11
12
  */
12
- exampleTopics: ExamplesPage.ExampleTopic[];
13
+ exampleTopics: ExampleTopic[];
13
14
  }
14
15
  export interface LeftMenuProps {
15
16
  /**
16
17
  * 案例主题列表
17
18
  */
18
- exampleTopics: ExamplesPage.ExampleTopic[];
19
+ exampleTopics: ExampleTopic[];
19
20
  }
20
- export interface ExampleWithTopic extends ExamplesPage.Example {
21
- targetTopic: ExamplesPage.ExampleTopic;
21
+ export interface ExampleWithTopic extends Example {
22
+ targetTopic: ExampleTopic;
22
23
  }
23
24
  export interface DemoCardProps {
24
- demo: ExamplesPage.Demo;
25
+ demo: Demo;
25
26
  topicId: string;
26
27
  exampleId: string;
27
28
  }
@@ -29,5 +30,5 @@ export interface LeftMenuProps {
29
30
  /**
30
31
  * 案例主题列表
31
32
  */
32
- exampleTopics: ExamplesPage.ExampleTopic[];
33
+ exampleTopics: ExampleTopic[];
33
34
  }
@@ -15,3 +15,7 @@ export declare const getExamplesPageTopics: (exampleTopics: ExampleTopic[]) => {
15
15
  examples: Example[];
16
16
  childrenKey: string;
17
17
  }[];
18
+ /**
19
+ * 根据目录结构返回,所有的 example 页面,用于 buiild static
20
+ */
21
+ export declare function getExamplePaths(): string[];
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/plugin/examples.ts
23
23
  var examples_exports = {};
24
24
  __export(examples_exports, {
25
+ getExamplePaths: () => getExamplePaths,
25
26
  getExamplesPageTopics: () => getExamplesPageTopics
26
27
  });
27
28
  module.exports = __toCommonJS(examples_exports);
@@ -88,7 +89,17 @@ var getExamplesPageTopics = (exampleTopics) => {
88
89
  };
89
90
  });
90
91
  };
92
+ function getExamplePaths() {
93
+ const exampleTopicPaths = glob.sync(`${examplesBaseDir}/*/*`);
94
+ const paths = exampleTopicPaths.map((p) => p.replace(process.cwd(), ""));
95
+ return [
96
+ ...paths,
97
+ ...paths.map((p) => `/zh${p}`),
98
+ ...paths.map((p) => `/en${p}`)
99
+ ];
100
+ }
91
101
  // Annotate the CommonJS export names for ESM import in node:
92
102
  0 && (module.exports = {
103
+ getExamplePaths,
93
104
  getExamplesPageTopics
94
105
  });
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,7 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
17
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
21
 
19
22
  // src/plugin/index.ts
@@ -22,33 +25,39 @@ __export(plugin_exports, {
22
25
  default: () => plugin_default
23
26
  });
24
27
  module.exports = __toCommonJS(plugin_exports);
28
+ var path = __toESM(require("path"));
25
29
  var import_examples = require("./examples");
26
30
  var import_utils = require("./utils");
27
31
  var plugin_default = (api) => {
28
32
  api.describe({ key: `dumi-theme:${require("../../package.json").name}` });
29
33
  api.modifyDefaultConfig((memo) => {
30
34
  memo.resolve.codeBlockMode = "passive";
35
+ memo.exportStatic.extraRoutePaths = (0, import_examples.getExamplePaths)();
31
36
  return memo;
32
37
  });
33
38
  const pages = [
39
+ {
40
+ id: "dumi-theme-antv-homepage",
41
+ absPath: "/"
42
+ },
34
43
  {
35
44
  id: "dumi-theme-antv-example-list-zh",
36
- path: "/examples/",
45
+ absPath: "/examples",
37
46
  file: (0, import_utils.myResolve)("../pages/Examples/index.tsx")
38
47
  },
39
48
  {
40
49
  id: "dumi-theme-antv-example-list-lang",
41
- path: "/:language/examples/",
50
+ absPath: "/:language/examples",
42
51
  file: (0, import_utils.myResolve)("../pages/Examples/index.tsx")
43
52
  },
44
53
  {
45
54
  id: "dumi-theme-antv-single-example-zh",
46
- path: "/examples/:topic/:example",
55
+ absPath: "/examples/:topic/:example",
47
56
  file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
48
57
  },
49
58
  {
50
59
  id: "dumi-theme-antv-single-example-lang",
51
- path: "/:language/examples/:topic/:example",
60
+ absPath: "/:language/examples/:topic/:example",
52
61
  file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
53
62
  }
54
63
  ];
@@ -64,8 +73,6 @@ import { ThemeAntVContext } from '${contextFilePath}';
64
73
 
65
74
  export default function ThemeAntVContextWrapper() {
66
75
  const outlet = useOutlet();
67
- // const { themeConfig } = useSiteData();
68
- // const exampleTopics = themeConfig?.examples || [];
69
76
 
70
77
  return (
71
78
  <ThemeAntVContext.Provider
@@ -90,8 +97,8 @@ export default function ThemeAntVContextWrapper() {
90
97
  pages.forEach((page) => {
91
98
  routes[page.id] = {
92
99
  id: page.id,
93
- path: page.path,
94
- absPath: page.path,
100
+ path: page.absPath.slice(1),
101
+ absPath: page.absPath,
95
102
  file: page.file,
96
103
  parentId: "DocLayout"
97
104
  };
@@ -99,6 +106,7 @@ export default function ThemeAntVContextWrapper() {
99
106
  routes["404"].file = (0, import_utils.myResolve)("../pages/404.tsx");
100
107
  return routes;
101
108
  });
109
+ api.addTmpGenerateWatcherPaths(() => [path.resolve(process.cwd(), "examples")]);
102
110
  };
103
111
  // Annotate the CommonJS export names for ESM import in node:
104
112
  0 && (module.exports = {});
@@ -86,16 +86,30 @@ export var CodeEditor = function CodeEditor(_ref) {
86
86
  window.dispatchEvent(e);
87
87
  };
88
88
 
89
+ var reportError = useCallback(function (e) {
90
+ if (e) {
91
+ console.error(e);
92
+ onError(e);
93
+ }
94
+ }, []);
89
95
  useEffect(function () {
90
96
  // 用于上报错误信息,使用 script 执行代码
91
97
  if (typeof window !== 'undefined') {
92
- window.__reportErrorInPlayground = function (e) {
93
- if (e) {
94
- console.error(e);
95
- onError(e);
96
- }
97
- };
98
+ // Cath error of code.
99
+ window.__reportErrorInPlayground = reportError; // Catch error of timeout/raf.
100
+
101
+ window.onerror = reportError; // Catch error of promise.
102
+
103
+ window.addEventListener('unhandledrejection', reportError);
98
104
  }
105
+
106
+ return function () {
107
+ if (window) {
108
+ window.__reportErrorInPlayground = undefined;
109
+ window.onerror = undefined;
110
+ window.removeEventListener('unhandledrejection', reportError);
111
+ }
112
+ };
99
113
  });
100
114
  var executeCode = useCallback(debounce(function (v) {
101
115
  if (!v) return; // 1. 先编译代码
@@ -24,6 +24,6 @@ export var CodePreview = function CodePreview(_ref) {
24
24
  className: styles.result,
25
25
  status: "error",
26
26
  title: useT('演示代码报错,请检查'),
27
- subTitle: /*#__PURE__*/React.createElement("pre", null, error && error.message)
27
+ subTitle: /*#__PURE__*/React.createElement("pre", null, error && error.toString())
28
28
  }) : null));
29
29
  };
@@ -5,6 +5,7 @@ declare type CodeRunnerProps = {
5
5
  example: string;
6
6
  demo: string;
7
7
  exampleTopics: ExampleTopic[];
8
+ size?: number;
8
9
  notFound?: React.Element;
9
10
  };
10
11
  /**
@@ -28,6 +28,7 @@ export var CodeRunner = function CodeRunner(_ref) {
28
28
  topic = _ref.topic,
29
29
  example = _ref.example,
30
30
  demo = _ref.demo,
31
+ size = _ref.size,
31
32
  _ref$notFound = _ref.notFound,
32
33
  notFound = _ref$notFound === void 0 ? /*#__PURE__*/React.createElement(NotFound, null) : _ref$notFound;
33
34
  var demoInfo = getDemoInfo(exampleTopics, topic, example, demo); // 找不到,啥也别干了,404 页面
@@ -61,7 +62,7 @@ export var CodeRunner = function CodeRunner(_ref) {
61
62
  });
62
63
  return /*#__PURE__*/React.createElement(SplitPane, {
63
64
  split: "vertical",
64
- defaultSize: "50%",
65
+ defaultSize: "".concat((1 - size) * 100, "%"),
65
66
  minSize: 100
66
67
  }, /*#__PURE__*/React.createElement(CodePreview, {
67
68
  error: error,
@@ -1,17 +1,18 @@
1
1
  import React from 'react';
2
+ import { Demo, ExampleTopic } from '../../types';
2
3
  export interface ExampleSiderProps {
3
4
  /**
4
5
  * 当前 Example (受控)
5
6
  */
6
- currentDemo: ExamplesPage.Demo;
7
+ currentDemo: Demo;
7
8
  /**
8
9
  * 当选中的 Demo 被改变时做些什么
9
10
  */
10
- onDemoClicked: (demo: ExamplesPage.Demo) => void;
11
+ onDemoClicked: (demo: Demo) => void;
11
12
  /**
12
13
  * 所有的案例主题
13
14
  */
14
- exampleTopics: ExamplesPage.ExampleTopic[];
15
+ exampleTopics: ExampleTopic[];
15
16
  showExampleDemoTitle: boolean;
16
17
  }
17
18
  /**
@@ -22,8 +22,8 @@ import { useLocale } from 'dumi';
22
22
  import { createFromIconfontCN, SearchOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
23
23
  import classNames from 'classnames';
24
24
  import { useT } from "../hooks";
25
- import styles from "./index.module.less";
26
- import { filterTreeNode } from "../utils"; // menu icon
25
+ import { filterTreeNode } from "../utils";
26
+ import styles from "./index.module.less"; // menu icon
27
27
 
28
28
  var MenuIcon = createFromIconfontCN({
29
29
  scriptUrl: '//at.alicdn.com/t/font_470089_1lnym745udm.js' // generated by iconfont.cn
@@ -26,19 +26,23 @@ export var Navs = function Navs(_ref) {
26
26
  var locale = useLocale();
27
27
  return /*#__PURE__*/React.createElement(React.Fragment, null, navs.map(function (nav) {
28
28
  var href = nav.slug.startsWith('http') ? nav.slug : "/".concat(nav.slug);
29
+ var isAnotherSite = nav.slug.startsWith('http');
30
+ var anotherSite = isAnotherSite ? href : '';
29
31
  var title = getDocument(navs, nav.slug).title[locale.id];
30
32
  href = nav.slug.startsWith('/') ? nav.slug : "/".concat(nav.slug);
31
33
 
32
- if (window.location.pathname.includes('en')) {
34
+ if (locale.id == 'en') {
33
35
  href = "/en".concat(href);
34
- }
36
+ } // 去除 docs 防止二次点击相同nav跳转出现04
35
37
 
38
+
39
+ href = href.replace('/docs/', '/');
36
40
  var className = cx('header-menu-item-active', _defineProperty({}, styles.activeItem, path.startsWith(href) || isEqual(path.split('/').slice(0, 4), href.split('/').slice(0, 4))));
37
41
  return /*#__PURE__*/React.createElement("li", {
38
42
  key: title,
39
43
  className: className
40
- }, nav.target === '_blank' || href.startsWith('http') ? /*#__PURE__*/React.createElement("a", {
41
- href: href,
44
+ }, nav.target === '_blank' || isAnotherSite ? /*#__PURE__*/React.createElement("a", {
45
+ href: anotherSite,
42
46
  target: "_blank",
43
47
  rel: "noreferrer"
44
48
  }, title, /*#__PURE__*/React.createElement(LinkOutlined, null)) : /*#__PURE__*/React.createElement(Link, {
@@ -1,11 +1,3 @@
1
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
-
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
-
7
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
-
9
1
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
10
2
 
11
3
  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; }
@@ -34,6 +26,7 @@ import { useLocale, useSiteData, useFullSidebarData, useRouteMeta } from 'dumi';
34
26
  import { useNavigate } from "react-router-dom";
35
27
  import { EditOutlined, MenuFoldOutlined, MenuUnfoldOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
36
28
  import readingTime from 'reading-time';
29
+ import { getBaseRoute, getIndexRoute, getOpenKeys } from "./utils";
37
30
  import { NavigatorBanner } from "./NavigatorBanner";
38
31
  import ReadingTime from "./ReadingTime";
39
32
  import { TOC } from "../TOC";
@@ -63,7 +56,7 @@ export var ManualContent = function ManualContent(_ref) {
63
56
  drawOpen = _useState2[0],
64
57
  setDrawOpen = _useState2[1];
65
58
 
66
- var navigate = useNavigate(); // 获取阅读时间
59
+ var navigate = useNavigate(); // 获取阅读时间
67
60
 
68
61
  var mdInfo = useRouteMeta();
69
62
  var text = mdInfo.texts.reduce(function (prev, next) {
@@ -71,144 +64,149 @@ export var ManualContent = function ManualContent(_ref) {
71
64
  }, '');
72
65
 
73
66
  var _readingTime = readingTime(text),
74
- time = _readingTime.time; // menu渲染
75
- // linkoTitle用来映射路由和Title
67
+ time = _readingTime.time; // linkoTitle用来映射路由和Title
76
68
 
77
69
 
78
70
  var linkoTitle = {};
79
71
 
80
- function getBaseRoute() {
81
- var matchRoute = window.location.pathname; // 兼容 zh
82
-
83
- matchRoute = matchRoute.replace('/zh/', '/'); // 兼容带有docs的route
84
-
85
- matchRoute = matchRoute.replace('/docs', ''); // 查找 baseRoute
86
-
87
- var reg = window.location.pathname.startsWith('/en') ? /(\/[A-z]*\/?\/[A-z]*)\/?/ : /(\/[A-z]*)\/?/;
88
- var mainRoute = matchRoute.match(reg);
89
- return mainRoute[1];
72
+ for (var _i2 = 0, _Object$values = Object.values(sidebar); _i2 < _Object$values.length; _i2++) {
73
+ var route = _Object$values[_i2];
74
+ route[0].children.forEach(function (item) {
75
+ linkoTitle[item.link] = item.title;
76
+ });
90
77
  }
78
+ /**
79
+ * /api/xxx --> /api
80
+ * /en/api --> /en/api
81
+ */
82
+
83
+
84
+ var baseRoute = getBaseRoute(); // 获取最终的 MenuData
85
+
86
+ var renderSidebar = getMenuData(sidebar, docs, baseRoute, []);
87
+
88
+ function getMenuData(funllSidebarData, rootList, hrefId, list) {
89
+ function fullSidebarDataToMenuData(rootList, hrefId, list) {
90
+ // 递归
91
+ rootList.forEach(function (item) {
92
+ var href = !baseRoute.startsWith('/en') ? "/".concat(item.slug) : "/en/".concat(item.slug);
93
+ var id = href.split("/").slice(0, href.split("/").length - 1).join("/");
94
+
95
+ if (href.includes(baseRoute)) {
96
+ if (id === hrefId) {
97
+ list.push(_objectSpread(_objectSpread({}, item), {}, {
98
+ key: href,
99
+ label: item.title[currentLocale]
100
+ }));
101
+ }
102
+ }
103
+ });
91
104
 
92
- var baseRoute = getBaseRoute();
93
-
94
- function fullSidebarDataToMenuData(rootList, hrefId, list) {
95
- // 递归
96
- rootList.forEach(function (item) {
97
- var href = !baseRoute.startsWith('/en') ? "/".concat(item.slug) : "/en/".concat(item.slug);
98
- var id = href.split("/").slice(0, href.split("/").length - 1).join("/");
99
-
100
- if (href.includes(baseRoute)) {
101
- if (id === hrefId) {
102
- list.push(_objectSpread(_objectSpread({}, item), {}, {
103
- key: href,
104
- label: item.title[currentLocale]
105
- }));
105
+ var _iterator = _createForOfIteratorHelper(list),
106
+ _step;
107
+
108
+ try {
109
+ var _loop = function _loop() {
110
+ var _funllSidebarData$ite;
111
+
112
+ var item = _step.value;
113
+ item.children = [];
114
+ fullSidebarDataToMenuData(rootList, item.key, item.children);
115
+ (_funllSidebarData$ite = funllSidebarData[item.key][0].children) === null || _funllSidebarData$ite === void 0 ? void 0 : _funllSidebarData$ite.forEach(function (itemChild) {
116
+ var label = itemChild.title;
117
+ var key = itemChild.link;
118
+ item.children.push(_objectSpread(_objectSpread({}, itemChild), {}, {
119
+ label: label,
120
+ key: key
121
+ }));
122
+ });
123
+
124
+ if (item.children.length == 0) {
125
+ delete item.children;
126
+ }
127
+ };
128
+
129
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
130
+ _loop();
106
131
  }
132
+ } catch (err) {
133
+ _iterator.e(err);
134
+ } finally {
135
+ _iterator.f();
107
136
  }
108
- });
109
137
 
110
- var _iterator = _createForOfIteratorHelper(list),
111
- _step;
138
+ if (hrefId == baseRoute) {
139
+ var _funllSidebarData$bas;
112
140
 
113
- try {
114
- var _loop = function _loop() {
115
- var _sidebar$item$key$0$c;
116
-
117
- var item = _step.value;
118
- item.children = [];
119
- fullSidebarDataToMenuData(rootList, item.key, item.children);
120
- (_sidebar$item$key$0$c = sidebar[item.key][0].children) === null || _sidebar$item$key$0$c === void 0 ? void 0 : _sidebar$item$key$0$c.forEach(function (itemChild) {
121
- var label = itemChild.title;
141
+ funllSidebarData[baseRoute] && ((_funllSidebarData$bas = funllSidebarData[baseRoute][0].children) === null || _funllSidebarData$bas === void 0 ? void 0 : _funllSidebarData$bas.forEach(function (itemChild) {
122
142
  var key = itemChild.link;
123
- item.children.push(_objectSpread(_objectSpread({}, itemChild), {}, {
143
+ var label = itemChild.title;
144
+ list.push(_objectSpread(_objectSpread({}, itemChild), {}, {
124
145
  label: label,
125
146
  key: key
126
147
  }));
127
- linkoTitle[key] = label;
148
+ }));
149
+ list.sort(function (a, b) {
150
+ return a.order - b.order;
128
151
  });
129
-
130
- if (item.children.length == 0) {
131
- delete item.children;
132
- }
133
- };
134
-
135
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
136
- _loop();
152
+ return list;
137
153
  }
138
- } catch (err) {
139
- _iterator.e(err);
140
- } finally {
141
- _iterator.f();
142
154
  }
143
155
 
144
- if (hrefId == baseRoute) {
145
- var _sidebar$baseRoute$0$;
156
+ return fullSidebarDataToMenuData(rootList, hrefId, list);
157
+ } // 获取打开的菜单栏
146
158
 
147
- sidebar[baseRoute] && ((_sidebar$baseRoute$0$ = sidebar[baseRoute][0].children) === null || _sidebar$baseRoute$0$ === void 0 ? void 0 : _sidebar$baseRoute$0$.forEach(function (itemChild) {
148
- var key = itemChild.link;
149
- var label = itemChild.title;
150
- list.push(_objectSpread(_objectSpread({}, itemChild), {}, {
151
- label: label,
152
- key: key
153
- }));
154
- linkoTitle[key] = label;
155
- }));
156
- list.sort(function (a, b) {
157
- return a.order - b.order;
158
- });
159
- return list;
160
- }
161
- } // 获取最终的 MenuData
162
-
163
-
164
- var renderSidebar = fullSidebarDataToMenuData(docs, baseRoute, []); // 获取默认打开的菜单栏
165
-
166
- function getDefaultOpenKeys(MenuData) {
167
- var defaultOpenKeys = [];
168
- var topRoute = MenuData[0];
169
- defaultOpenKeys.push(topRoute.key);
170
159
 
171
- while (topRoute.children) {
172
- topRoute = topRoute.children[0];
173
- defaultOpenKeys.push(topRoute.key);
174
- }
160
+ var _useState3 = useState(function () {
161
+ return getOpenKeys();
162
+ }),
163
+ _useState4 = _slicedToArray(_useState3, 2),
164
+ defaultOpenKeys = _useState4[0],
165
+ setDefaultOpenKeys = _useState4[1]; // 获取第一个md文件的路由
175
166
 
176
- return defaultOpenKeys;
177
- }
178
167
 
179
- var defaultOpenKeys = getDefaultOpenKeys(renderSidebar);
180
- var indexRoute = defaultOpenKeys[defaultOpenKeys.length - 1]; // 点击菜单栏
168
+ var indexRoute = getIndexRoute(renderSidebar); // 点击菜单栏
181
169
 
182
170
  var onClick = function onClick(e) {
183
171
  navigate(e.key);
184
172
  useScrollToTop();
185
173
  };
186
174
 
187
- var _useState3 = useState(renderSidebar.length !== 0 ? [renderSidebar[0].key] : ['']),
188
- _useState4 = _slicedToArray(_useState3, 2),
189
- defaultSelectedKey = _useState4[0],
190
- setDefaultSelectedKey = _useState4[1]; //上一夜下一页
191
-
192
-
193
- var _useState5 = useState(undefined),
175
+ var _useState5 = useState(renderSidebar.length !== 0 ? [renderSidebar[0].key] : ['']),
194
176
  _useState6 = _slicedToArray(_useState5, 2),
195
- prev = _useState6[0],
196
- setPrev = _useState6[1];
177
+ defaultSelectedKey = _useState6[0],
178
+ setDefaultSelectedKey = _useState6[1]; //上一夜下一页
179
+
197
180
 
198
181
  var _useState7 = useState(undefined),
199
182
  _useState8 = _slicedToArray(_useState7, 2),
200
- next = _useState8[0],
201
- setNext = _useState8[1]; // 监听路由去改变 selected menu-item
183
+ prev = _useState8[0],
184
+ setPrev = _useState8[1];
185
+
186
+ var _useState9 = useState(undefined),
187
+ _useState10 = _slicedToArray(_useState9, 2),
188
+ next = _useState10[0],
189
+ setNext = _useState10[1]; // 所有的 sidebar 路由
190
+
191
+
192
+ var sidebarRoutes = [];
193
+
194
+ for (var _i3 = 0, _Object$keys = Object.keys(linkoTitle); _i3 < _Object$keys.length; _i3++) {
195
+ var route = _Object$keys[_i3];
196
+ sidebarRoutes.push(route);
197
+ } // 兜底 如果 nav 指定有误则自动重定向到 indexDocRoute
198
+
199
+
200
+ if (window.location.pathname.startsWith('/docs/') || !sidebarRoutes.includes(window.location.pathname)) {
201
+ navigate(indexRoute);
202
+ } // 改变菜单栏选中和 openKeys 状态
202
203
 
203
204
 
204
205
  useEffect(function () {
205
- // 兜底 如果 nav 指定有误则重定向到 indexDocRoute
206
- if (window.location.pathname !== indexRoute) {
207
- navigate(indexRoute);
206
+ if (window.location.pathname == indexRoute) {
207
+ setDefaultOpenKeys(getOpenKeys());
208
208
  }
209
- }, []); // 改变菜单栏选中状态
210
209
 
211
- useEffect(function () {
212
210
  setDefaultSelectedKey([window.location.pathname]);
213
211
  }, [window.location.pathname]);
214
212
  useEffect(function () {
@@ -250,16 +248,19 @@ export var ManualContent = function ManualContent(_ref) {
250
248
 
251
249
  var menu = /*#__PURE__*/React.createElement(Menu, {
252
250
  onClick: onClick,
253
- defaultSelectedKeys: defaultSelectedKey,
251
+ onOpenChange: function onOpenChange(openKeys) {
252
+ setDefaultOpenKeys(openKeys);
253
+ },
254
254
  selectedKeys: defaultSelectedKey,
255
- defaultOpenKeys: _toConsumableArray(defaultOpenKeys),
255
+ openKeys: defaultOpenKeys,
256
256
  mode: "inline",
257
257
  items: renderSidebar,
258
258
  inlineIndent: 16,
259
259
  style: {
260
260
  height: '100%'
261
261
  },
262
- forceSubMenuRender: true
262
+ forceSubMenuRender: true,
263
+ triggerSubMenuAction: "click"
263
264
  });
264
265
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Layout, {
265
266
  style: {
@@ -0,0 +1,3 @@
1
+ export declare function getOpenKeys(): any[];
2
+ export declare function getBaseRoute(): string;
3
+ export declare function getIndexRoute(MenuData: any): any;
@@ -0,0 +1,35 @@
1
+ export function getOpenKeys() {
2
+ var pathname = window.location.pathname;
3
+ var pathArr = pathname.split('/');
4
+ var openKeys = [];
5
+
6
+ for (var i = pathArr.length; i > 0; i--) {
7
+ var tem = pathArr.slice(0, i);
8
+ openKeys.push(tem.join('/'));
9
+ }
10
+
11
+ return openKeys;
12
+ }
13
+ export function getBaseRoute() {
14
+ var matchRoute = window.location.pathname; // 兼容 zh
15
+
16
+ matchRoute = matchRoute.replace('/zh/', '/'); // 兼容带有docs的route
17
+
18
+ matchRoute = matchRoute.replace('/docs', ''); // 查找 baseRoute
19
+
20
+ var reg = window.location.pathname.startsWith('/en') ? /(\/[A-z]*\/?\/[A-z]*)\/?/ : /(\/[A-z]*)\/?/;
21
+ var mainRoute = matchRoute.match(reg);
22
+ return mainRoute[1];
23
+ }
24
+ export function getIndexRoute(MenuData) {
25
+ var defaultOpenKeys = [];
26
+ var topRoute = MenuData[0];
27
+ defaultOpenKeys.push(topRoute.key);
28
+
29
+ while (topRoute.children) {
30
+ topRoute = topRoute.children[0];
31
+ defaultOpenKeys.push(topRoute.key);
32
+ }
33
+
34
+ return defaultOpenKeys[defaultOpenKeys.length - 1];
35
+ }
@@ -1,5 +1,5 @@
1
- import { Status } from '../types';
1
+ import { Status, TreeNode } from '../types';
2
2
  export declare function ping(): Promise<Status>;
3
3
  export declare const getChinaMirrorHost: (host?: string) => string;
4
4
  export declare function getGithubSourceURL(githubUrl: string, relativePath: string, prefix?: string): string;
5
- export declare const filterTreeNode: (treeNode: ExamplesPage.TreeNode, keyValue: string, locale: string) => ExamplesPage.TreeNode;
5
+ export declare const filterTreeNode: (treeNode: TreeNode, keyValue: string, locale: string) => TreeNode;
package/dist/types.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare type IC = string | {
9
9
  zh: string;
10
10
  en: string;
11
11
  };
12
- interface TreeNode {
12
+ export interface TreeNode {
13
13
  /**
14
14
  * id
15
15
  */
@@ -84,4 +84,3 @@ export interface ExampleTopic extends TreeNode {
84
84
  */
85
85
  examples: Example[];
86
86
  }
87
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.3.0-beta.5",
3
+ "version": "0.3.0-beta.6",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "types": "dist/types.d.ts",
6
6
  "scripts": {