@antv/dumi-theme-antv 0.3.0-beta.3 → 0.3.0-beta.4

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.
@@ -16,20 +16,18 @@ export default (function () {
16
16
  var _useLocation = useLocation(),
17
17
  pathname = _useLocation.pathname;
18
18
 
19
- var p = pathname.toLowerCase(); // @todo 南洋
20
- // 做一些跳转,比如:/zh/examples/xxx -> /examples/xxx
21
- // 首页
19
+ var p = pathname.toLowerCase(); // 首页
22
20
 
23
- if (p === '/' || p === '/en' || p === '/en/') return /*#__PURE__*/React.createElement(Index, null); // API 页面
21
+ if (p === '/' || p === '/zh' || p === '/en' || p === '/en/') return /*#__PURE__*/React.createElement(Index, null); // API 页面
24
22
 
25
- if (p.startsWith('/api') || p.startsWith('/en/api') || // 这两个是兼容之前的
26
- p.startsWith('/zh/docs/api') || p.startsWith('/en/docs/api')) {
23
+ if (p.startsWith('/api') || p.startsWith('/en/api') || // 这四个是兼容之前的
24
+ p.startsWith('/zh/api') || p.startsWith('/en/api') || p.startsWith('/zh/docs/api') || p.startsWith('/en/docs/api')) {
27
25
  return /*#__PURE__*/React.createElement(API, null, " ", outlet, " ");
28
26
  } // 教程页面
29
27
 
30
28
 
31
- if (p.startsWith('/manual') || p.startsWith('/en/manual') || // 这两个是兼容之前的
32
- p.startsWith('/zh/docs/manual/') || p.startsWith('/en/docs/manual/')) {
29
+ if (p.startsWith('/manual') || p.startsWith('/en/manual') || // 这四个是兼容之前的
30
+ p.startsWith('/zh/manual') || p.startsWith('/en/manual') || p.startsWith('/zh/docs/manual/') || p.startsWith('/en/docs/manual/')) {
33
31
  return /*#__PURE__*/React.createElement(Manual, null, " ", outlet, " ");
34
32
  } // More router, add here...
35
33
 
@@ -1,9 +1,3 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
2
 
9
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."); }
@@ -39,8 +33,6 @@ var Example = function Example() {
39
33
  var nav = useNavigate();
40
34
 
41
35
  var _useParams = useParams(),
42
- _useParams$language = _useParams.language,
43
- language = _useParams$language === void 0 ? 'zh' : _useParams$language,
44
36
  topic = _useParams.topic,
45
37
  example = _useParams.example;
46
38
  /** 示例页面的元数据信息 */
@@ -56,51 +48,17 @@ var Example = function Example() {
56
48
  currentDemo = _useState2[0],
57
49
  setCurrentDemo = _useState2[1];
58
50
 
51
+ var _useState3 = useState(false),
52
+ _useState4 = _slicedToArray(_useState3, 2),
53
+ isCollapsed = _useState4[0],
54
+ setIsCollapsed = _useState4[1];
55
+
59
56
  useEffect(function () {
60
57
  if (topic && example && demo) {
61
58
  var targetDemoInfo = getDemoInfo(exampleTopics, topic, example, demo);
62
59
  setCurrentDemo(targetDemoInfo);
63
60
  }
64
- }, [topic, example, hash]); // 提取出来获取 唯一value值的 方法
65
-
66
- var getPath = function getPath(item) {
67
- var _item$relativePath;
68
-
69
- if (!item) {// @todo 怀策
70
- // debugger
71
- }
72
-
73
- var demoSlug = (_item$relativePath = item.relativePath) === null || _item$relativePath === void 0 ? void 0 : _item$relativePath.replace(/\/demo\/(.*)\..*/, function (_, filename) {
74
- return "#".concat(filename);
75
- });
76
- return "/".concat(locale.id, "/examples/").concat(demoSlug);
77
- }; // 一级菜单,二级菜单 数据 treeData + 二级菜单,示例 数据 result 写成一个 一级,二级,示例的三层树结构 数据
78
-
79
-
80
- var transformNode = function transformNode(data, result) {
81
- return data.map(function (item) {
82
- var _result$find;
83
-
84
- if (item.children && !item.node) {
85
- return _objectSpread(_objectSpread({}, item), {}, {
86
- children: transformNode(item.children, result)
87
- });
88
- }
89
-
90
- var _item$node = item.node,
91
- frontmatter = _item$node.frontmatter,
92
- fields = _item$node.fields;
93
- return _objectSpread(_objectSpread({}, frontmatter), {}, {
94
- // 提前给二级菜单的key值加入 特殊值 好辨别
95
- value: "secondaryKey-".concat(fields === null || fields === void 0 ? void 0 : fields.slug),
96
- children: (_result$find = result.find(function (_ref) {
97
- var k = _ref.title;
98
- return k === frontmatter.title;
99
- })) === null || _result$find === void 0 ? void 0 : _result$find.children
100
- });
101
- });
102
- };
103
-
61
+ }, [topic, example, hash]);
104
62
  return /*#__PURE__*/React.createElement("div", {
105
63
  className: styles.example
106
64
  }, /*#__PURE__*/React.createElement(Header, {
@@ -112,7 +70,8 @@ var Example = function Example() {
112
70
  width: 250,
113
71
  trigger: null,
114
72
  collapsible: true,
115
- className: styles.sider,
73
+ collapsed: isCollapsed,
74
+ className: styles.menuSider,
116
75
  theme: "light"
117
76
  }, currentDemo && /*#__PURE__*/React.createElement(ExampleSider, {
118
77
  showExampleDemoTitle: true,
@@ -16,14 +16,6 @@
16
16
  flex: 1;
17
17
  background-color: #fff;
18
18
 
19
- .sider {
20
- height: 100%;
21
-
22
- .exampleList {
23
-
24
- }
25
- }
26
-
27
19
  .content {
28
20
  position: relative;
29
21
  height: 100%;
@@ -38,3 +30,53 @@
38
30
  }
39
31
  }
40
32
  }
33
+
34
+ .menuSider {
35
+ background-color: #f8f9fc;
36
+ border-right: 1px solid #ececec;
37
+
38
+ :global {
39
+ .ant-layout-sider-children {
40
+ overflow-y: hidden;
41
+ overflow-x: hidden;
42
+
43
+ &:hover {
44
+ overflow-y: auto;
45
+ }
46
+ }
47
+ }
48
+ }
49
+
50
+ .trigger {
51
+ font-size: 12px;
52
+ position: relative;
53
+ margin: auto;
54
+ color: #6c7f90;
55
+ left: -1px;
56
+ z-index: 4;
57
+ width: 22px;
58
+ cursor: pointer;
59
+ transition: color 0.3s;
60
+ border: 1px solid #ececec;
61
+ border-left: none;
62
+ background-color: #fff;
63
+ height: 66px;
64
+ box-sizing: border-box;
65
+ border-bottom-right-radius: 4px;
66
+ border-top-right-radius: 4px;
67
+ text-align: center;
68
+
69
+ &[type='menu-unfold'] {
70
+ background-color: #f8f9fc;
71
+ }
72
+
73
+ svg {
74
+ position: absolute;
75
+ left: 3px;
76
+ top: 25px;
77
+ }
78
+ }
79
+
80
+ .trigger:hover {
81
+ color: @primary-color;
82
+ }
@@ -25,7 +25,7 @@ export var DemoCard = function DemoCard(props) {
25
25
 
26
26
  return /*#__PURE__*/React.createElement(Link, {
27
27
  className: styles.galleryCardLink,
28
- to: "/".concat(locale.id, "/examples/").concat(topicId, "/").concat(exampleId, "/#").concat(demo.id)
28
+ to: "".concat(locale.id == 'zh' ? '' : '/en', "/examples/").concat(topicId, "/").concat(exampleId, "/#").concat(demo.id)
29
29
  }, demo.isNew ? /*#__PURE__*/React.createElement(Badge.Ribbon, {
30
30
  text: "new",
31
31
  className: styles.customRibbon
@@ -11,7 +11,8 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
13
  import React from 'react';
14
- import { useContext } from 'react';
14
+ import { useContext, useEffect } from 'react';
15
+ import { useNavigate } from 'react-router-dom';
15
16
  import { BackTop, Layout as AntLayout } from 'antd';
16
17
  import { Header } from "../../slots/Header";
17
18
  import { Footer } from "../../slots/Footer";
@@ -30,15 +31,25 @@ import styles from "./index.module.less";
30
31
  */
31
32
 
32
33
  var Example = function Example() {
34
+ var nav = useNavigate();
33
35
  /** 示例页面的元数据信息 */
36
+
34
37
  var metaData = useContext(ThemeAntVContext);
35
38
  var exampleTopics = metaData.meta.exampleTopics;
36
39
 
37
40
  var _usePrevAndNext = usePrevAndNext(),
38
41
  _usePrevAndNext2 = _slicedToArray(_usePrevAndNext, 2),
39
42
  prev = _usePrevAndNext2[0],
40
- next = _usePrevAndNext2[1];
43
+ next = _usePrevAndNext2[1]; // 为 zh 做兜底
44
+
41
45
 
46
+ useEffect(function () {
47
+ var p = window.location.pathname;
48
+
49
+ if (p.includes('/zh/')) {
50
+ nav(p.replace('/zh/', '/'));
51
+ }
52
+ }, []);
42
53
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Header, {
43
54
  isHomePage: false
44
55
  }), /*#__PURE__*/React.createElement(AntLayout, {
@@ -268,6 +268,7 @@
268
268
  .sider {
269
269
  width: 280px !important;
270
270
  height: inherit;
271
+ background-color: #fff;
271
272
 
272
273
  // menu 滚动
273
274
  :global {
@@ -282,6 +283,7 @@
282
283
  }
283
284
 
284
285
  .affix {
286
+ background-color: #fff;
285
287
  & > div {
286
288
  height: 100%;
287
289
  }
@@ -9,4 +9,5 @@ export declare const getExamplesPageTopics: (exampleTopics: ExamplesPage.Example
9
9
  title: ExamplesPage.ExampleTopic;
10
10
  icon: ExamplesPage.ExampleTopic;
11
11
  examples: ExamplesPage.Example[];
12
+ childrenKey: string;
12
13
  }[];
@@ -63,7 +63,8 @@ var getTopicExamples = (topicPath) => {
63
63
  title: {
64
64
  en: exampleMetaEnContent.attributes.title,
65
65
  zh: exampleMetaZhContent.attributes.title
66
- }
66
+ },
67
+ childrenKey: "demos"
67
68
  };
68
69
  return example;
69
70
  });
@@ -81,7 +82,8 @@ var getExamplesPageTopics = (exampleTopics) => {
81
82
  id: nid,
82
83
  title,
83
84
  icon,
84
- examples
85
+ examples,
86
+ childrenKey: "examples"
85
87
  };
86
88
  });
87
89
  };
@@ -26,6 +26,10 @@ var import_examples = require("./examples");
26
26
  var import_utils = require("./utils");
27
27
  var plugin_default = (api) => {
28
28
  api.describe({ key: `dumi-theme:${require("../../package.json").name}` });
29
+ api.modifyDefaultConfig((memo) => {
30
+ memo.resolve.codeBlockMode = "passive";
31
+ return memo;
32
+ });
29
33
  const pages = [
30
34
  {
31
35
  id: "dumi-theme-antv-example-list-zh",
@@ -19,7 +19,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
19
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
20
 
21
21
  import React, { useEffect, useState } from 'react';
22
- import { CodeSandboxOutlined, PlayCircleOutlined, ThunderboltOutlined, FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
22
+ import { CodeSandboxOutlined, PlayCircleOutlined, ThunderboltOutlined } from '@ant-design/icons';
23
23
  import { Typography, Tooltip } from 'antd';
24
24
  import { useLocale } from 'dumi';
25
25
  import { getParameters } from 'codesandbox/lib/api/define';
@@ -68,8 +68,8 @@ export var Toolbar = function Toolbar(_ref) {
68
68
  updateRiddleVisible = _useState2[1];
69
69
 
70
70
  useEffect(function () {
71
- ping(function (status) {
72
- updateRiddleVisible(status === 'responded');
71
+ ping().then(function (status) {
72
+ return updateRiddleVisible(status === 'responded');
73
73
  });
74
74
  }, []);
75
75
  return /*#__PURE__*/React.createElement("div", {
@@ -129,19 +129,7 @@ export var Toolbar = function Toolbar(_ref) {
129
129
  style: {
130
130
  marginLeft: 6
131
131
  }
132
- }), onToggleFullscreen ? /*#__PURE__*/React.createElement(Tooltip, {
133
- title: isFullScreen ? useT('离开全屏') : useT('进入全屏')
134
- }, isFullScreen ? /*#__PURE__*/React.createElement(FullscreenExitOutlined, {
135
- onClick: onToggleFullscreen,
136
- style: {
137
- marginLeft: 12
138
- }
139
- }) : /*#__PURE__*/React.createElement(FullscreenOutlined, {
140
- onClick: onToggleFullscreen,
141
- style: {
142
- marginLeft: 12
143
- }
144
- })) : null, /*#__PURE__*/React.createElement(Tooltip, {
132
+ }), /*#__PURE__*/React.createElement(Tooltip, {
145
133
  title: useT('执行代码')
146
134
  }, /*#__PURE__*/React.createElement(PlayCircleOutlined, {
147
135
  onClick: onExecuteCode,
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { PageHeader, Tooltip, Space, Divider } from 'antd';
3
3
  import { EditOutlined } from '@ant-design/icons';
4
4
  import { useT } from "../hooks";
5
- import { getGithubSourceUrl } from "../utils";
5
+ import { getGithubSourceURL } from "../utils";
6
6
  import styles from "./CodeHeader.module.less";
7
7
 
8
8
  /**
@@ -18,7 +18,7 @@ export var CodeHeader = function CodeHeader(_ref) {
18
18
  subTitle: /*#__PURE__*/React.createElement(Tooltip, {
19
19
  title: useT('在 GitHub 上编辑')
20
20
  }, /*#__PURE__*/React.createElement("a", {
21
- href: getGithubSourceUrl(githubUrl, relativePath, 'examples'),
21
+ href: getGithubSourceURL(githubUrl, relativePath, 'examples'),
22
22
  target: "_blank",
23
23
  rel: "noopener noreferrer",
24
24
  className: styles.editOnGtiHubButton
@@ -71,6 +71,7 @@ export var CodeRunner = function CodeRunner(_ref) {
71
71
  onError: setError,
72
72
  onFullscreen: setFullscreen,
73
73
  onDestroy: noop,
74
- onReady: noop
74
+ onReady: noop,
75
+ playground: {}
75
76
  }));
76
77
  };
@@ -7,4 +7,4 @@ export declare function getExampleTopicMap(exampleTopics: ExamplesPage.ExampleTo
7
7
  /**
8
8
  * 从 Context 信息中,获取到 Example 相关的信息,用于页面渲染
9
9
  */
10
- export declare function getDemoInfo(exampleTopics: ExamplesPage.ExampleTopic[], topic: string, example: string, demo: string): ExamplesPage.Demo | undefined;
10
+ export declare function getDemoInfo(exampleTopics: ExamplesPage.ExampleTopic[], topic: string, example: string, demo: string): ExamplesPage.Demo;
@@ -81,7 +81,7 @@ export var Detail = function Detail(_ref) {
81
81
  link = _ref2.link,
82
82
  shape = _ref2.shape;
83
83
  return /*#__PURE__*/React.createElement("a", {
84
- key: text,
84
+ key: ic(text),
85
85
  className: cx(styles.buttonLink, styles[type || ''], type === 'primary' ? 'primary-button' : 'common-button'),
86
86
  style: _objectSpread({
87
87
  borderRadius: shape === 'square' ? '4px' : '1000px'
@@ -1,39 +1,4 @@
1
1
  import React from 'react';
2
- export interface PlayGroundItemProps {
3
- source: string;
4
- examples: PlayGroundItemProps[];
5
- babeledSource: string;
6
- absolutePath?: string;
7
- relativePath?: string;
8
- screenshot?: string;
9
- recommended?: boolean;
10
- filename: string;
11
- title?: string;
12
- location?: Location;
13
- playground?: {
14
- container?: string;
15
- playgroundDidMount?: string;
16
- playgroundWillUnmount?: string;
17
- dependencies?: {
18
- [key: string]: string;
19
- };
20
- devDependencies?: {
21
- [key: string]: string;
22
- };
23
- htmlCodeTemplate?: string;
24
- };
25
- }
26
- export interface TreeItem {
27
- title?: string;
28
- value?: string;
29
- key?: string;
30
- children?: any;
31
- icon?: string;
32
- relativePath?: string;
33
- filename?: string;
34
- screenshot?: string;
35
- node?: any;
36
- }
37
2
  export interface ExampleSiderProps {
38
3
  /**
39
4
  * 当前 Example (受控)
@@ -4,14 +4,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
-
9
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
-
11
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
-
13
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
14
-
15
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
16
8
 
17
9
  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."); }
@@ -29,10 +21,10 @@ import { Input, Menu, Tooltip } from 'antd';
29
21
  import { useLocale } from 'dumi';
30
22
  import { createFromIconfontCN, SearchOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
31
23
  import classNames from 'classnames';
32
- import { reduce, size } from 'lodash-es';
33
24
  import { useT } from "../hooks";
34
25
  import styles from "./index.module.less";
35
- // menu icon
26
+ import { filterTreeNode } from "../utils"; // menu icon
27
+
36
28
  var MenuIcon = createFromIconfontCN({
37
29
  scriptUrl: '//at.alicdn.com/t/font_470089_1lnym745udm.js' // generated by iconfont.cn
38
30
 
@@ -64,37 +56,23 @@ export var ExampleSider = function ExampleSider(props) {
64
56
  searchValue = _useState6[0],
65
57
  setSearchValue = _useState6[1];
66
58
 
67
- var locale = useLocale(); // 查找符合条件的数据 从title和 searchValue 可以匹配 就返回 否自返回[]
68
-
69
- var findSearchTreeData = function findSearchTreeData(data) {
70
- return reduce(data, function (value, item) {
71
- var _item$title;
72
-
73
- if ((_item$title = item.title) !== null && _item$title !== void 0 && _item$title.match(searchValue)) {
74
- return [].concat(_toConsumableArray(value), [item]);
75
- }
76
-
77
- if (item.children) {
78
- var searchData = findSearchTreeData(item.children);
79
- return size(searchData) ? [].concat(_toConsumableArray(value), [_objectSpread(_objectSpread({}, item), {}, {
80
- children: searchData
81
- })]) : value;
82
- }
83
-
84
- return value;
85
- }, []);
86
- }; // 获取默认展开的keys数组 传入treeData 和 底层的 key 返回符合条件的 keys
87
-
88
-
89
- var getDefaultOpenKeys = function getDefaultOpenKeys(data, key) {
90
- return reduce(data, function (value, item) {
91
- if (item.children) {
92
- var keys = getDefaultOpenKeys(item.children, key);
93
- return keys.length ? [].concat(_toConsumableArray(value), [item.value], _toConsumableArray(keys)) : value;
94
- }
59
+ var locale = useLocale();
60
+
61
+ var getCurrentTopics = function getCurrentTopics() {
62
+ if (searchValue) {
63
+ var res = filterTreeNode({
64
+ id: 'FAKE_ID',
65
+ childrenKey: 'exampleTopics',
66
+ title: {
67
+ 'zh': 'FAKE_TITLE',
68
+ 'en': 'FAKE_TITLE'
69
+ },
70
+ exampleTopics: exampleTopics
71
+ }, searchValue, locale.id);
72
+ return (res === null || res === void 0 ? void 0 : res.exampleTopics) || [];
73
+ }
95
74
 
96
- return key === item.value ? [item.value] : value;
97
- }, []);
75
+ return exampleTopics;
98
76
  }; // 初始化菜单栏展开keys
99
77
 
100
78
 
@@ -142,7 +120,7 @@ export var ExampleSider = function ExampleSider(props) {
142
120
  };
143
121
 
144
122
  var renderSubMenu = function renderSubMenu() {
145
- return exampleTopics.map(function (topic) {
123
+ return getCurrentTopics().map(function (topic) {
146
124
  return /*#__PURE__*/React.createElement(Menu.SubMenu, {
147
125
  key: "TOPIC-".concat(topic.id),
148
126
  title: /*#__PURE__*/React.createElement("div", null, topic.icon && /*#__PURE__*/React.createElement(MenuIcon, {
@@ -208,7 +186,7 @@ export var ExampleSider = function ExampleSider(props) {
208
186
  style: {
209
187
  width: '100%'
210
188
  },
211
- className: styles.siderbarMenu,
189
+ className: styles.sideBarMenu,
212
190
  openKeys: openKeys,
213
191
  selectedKeys: ["DEMO-".concat(currentDemo.id)],
214
192
  onOpenChange: function onOpenChange(keys) {
@@ -122,7 +122,7 @@
122
122
  font-weight: 500;
123
123
  }
124
124
 
125
- .siderbarMenu {
125
+ .sideBarMenu {
126
126
  border: none;
127
127
 
128
128
  .menuTitleContent {
@@ -3,6 +3,7 @@ import { Row, Col } from 'antd';
3
3
  import cx from 'classnames';
4
4
  import FeatureCard from "./FeatureCard";
5
5
  import styles from "./index.module.less";
6
+ import { ic } from "../hooks";
6
7
  export var Features = function Features(_ref) {
7
8
  var title = _ref.title,
8
9
  _ref$features = _ref.features,
@@ -15,7 +16,7 @@ export var Features = function Features(_ref) {
15
16
  var children = features.map(function (card) {
16
17
  return /*#__PURE__*/React.createElement(Col, {
17
18
  className: styles.cardWrapper,
18
- key: card.title,
19
+ key: ic(card.title),
19
20
  md: 8,
20
21
  xs: 24
21
22
  }, /*#__PURE__*/React.createElement(FeatureCard, card));
@@ -27,6 +27,7 @@ export var Navs = function Navs(_ref) {
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
29
  var title = getDocument(navs, nav.slug).title[locale.id];
30
+ href = nav.slug.startsWith('/') ? nav.slug : "/".concat(nav.slug);
30
31
 
31
32
  if (window.location.pathname.includes('en')) {
32
33
  href = "/en".concat(href);
@@ -38,7 +39,8 @@ export var Navs = function Navs(_ref) {
38
39
  className: className
39
40
  }, nav.target === '_blank' || href.startsWith('http') ? /*#__PURE__*/React.createElement("a", {
40
41
  href: href,
41
- target: "_blank"
42
+ target: "_blank",
43
+ rel: "noreferrer"
42
44
  }, title, /*#__PURE__*/React.createElement(LinkOutlined, null)) : /*#__PURE__*/React.createElement(Link, {
43
45
  to: href
44
46
  }, title));
@@ -312,7 +312,8 @@ var HeaderComponent = function HeaderComponent(_ref) {
312
312
  className: styles.githubCorner
313
313
  }, /*#__PURE__*/React.createElement("a", {
314
314
  href: githubUrl,
315
- target: "_blank"
315
+ target: "_blank",
316
+ rel: "noreferrer"
316
317
  }, /*#__PURE__*/React.createElement(GithubOutlined, null))));
317
318
  return /*#__PURE__*/React.createElement("header", {
318
319
  className: cx(styles.header, (_cx4 = {}, _defineProperty(_cx4, styles.transparent, !!transparent && !productMenuVisible), _defineProperty(_cx4, styles.isHomePage, !!isHomePage && !isAntVHome), _defineProperty(_cx4, styles.lightTheme, !!isAntVHome && !productMenuVisible && isWide), _defineProperty(_cx4, styles.fixed, popupMenuVisible), _cx4))
@@ -78,7 +78,12 @@ export var ManualContent = function ManualContent(_ref) {
78
78
  var linkoTitle = {};
79
79
 
80
80
  function getBaseRoute() {
81
- var matchRoute = window.location.pathname;
81
+ var matchRoute = window.location.pathname; // 兼容 zh
82
+
83
+ matchRoute = matchRoute.replace('/zh/', '/'); // 兼容带有docs的route
84
+
85
+ matchRoute = matchRoute.replace('/docs', ''); // 查找 baseRoute
86
+
82
87
  var reg = window.location.pathname.startsWith('/en') ? /(\/[A-z]*\/?\/[A-z]*)\/?/ : /(\/[A-z]*)\/?/;
83
88
  var mainRoute = matchRoute.match(reg);
84
89
  return mainRoute[1];
@@ -140,18 +145,20 @@ export var ManualContent = function ManualContent(_ref) {
140
145
  var _sidebar$baseRoute$0$;
141
146
 
142
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;
143
149
  var label = itemChild.title;
144
150
  list.push(_objectSpread(_objectSpread({}, itemChild), {}, {
145
151
  label: label,
146
- key: itemChild.link
152
+ key: key
147
153
  }));
154
+ linkoTitle[key] = label;
148
155
  }));
149
156
  list.sort(function (a, b) {
150
157
  return a.order - b.order;
151
158
  });
152
159
  return list;
153
160
  }
154
- } // 获取最终的MenuData
161
+ } // 获取最终的 MenuData
155
162
 
156
163
 
157
164
  var renderSidebar = fullSidebarDataToMenuData(docs, baseRoute, []); // 获取默认打开的菜单栏
@@ -169,14 +176,15 @@ export var ManualContent = function ManualContent(_ref) {
169
176
  return defaultOpenKeys;
170
177
  }
171
178
 
172
- var defaultOpenKeys = getDefaultOpenKeys(renderSidebar); // 点击菜单栏
179
+ var defaultOpenKeys = getDefaultOpenKeys(renderSidebar);
180
+ var indexRoute = defaultOpenKeys[defaultOpenKeys.length - 1]; // 点击菜单栏
173
181
 
174
182
  var onClick = function onClick(e) {
175
183
  navigate(e.key);
176
184
  useScrollToTop();
177
185
  };
178
186
 
179
- var _useState3 = useState([renderSidebar[0].key]),
187
+ var _useState3 = useState(renderSidebar.length !== 0 ? [renderSidebar[0].key] : ['']),
180
188
  _useState4 = _slicedToArray(_useState3, 2),
181
189
  defaultSelectedKey = _useState4[0],
182
190
  setDefaultSelectedKey = _useState4[1]; //上一夜下一页
@@ -190,12 +198,13 @@ export var ManualContent = function ManualContent(_ref) {
190
198
  var _useState7 = useState(undefined),
191
199
  _useState8 = _slicedToArray(_useState7, 2),
192
200
  next = _useState8[0],
193
- setNext = _useState8[1]; // 监听路由去改变selected menu-item
201
+ setNext = _useState8[1]; // 监听路由去改变 selected menu-item
194
202
 
195
203
 
196
204
  useEffect(function () {
197
- if (window.location.pathname == baseRoute) {
198
- navigate(renderSidebar[0].key);
205
+ // 兜底 如果 nav 指定有误则重定向到 indexDocRoute
206
+ if (window.location.pathname !== indexRoute) {
207
+ navigate(indexRoute);
199
208
  return;
200
209
  }
201
210
 
@@ -3,9 +3,9 @@ export declare const useChinaMirrorHost: () => [boolean];
3
3
  export declare const useScrollToTop: () => void;
4
4
  export declare const useT: (transformedMessage: string) => string;
5
5
  export declare const useLogoLink: ({ link, siteUrl, lang, }: {
6
- link?: string | undefined;
7
- siteUrl?: string | undefined;
8
- lang?: string | undefined;
6
+ link?: string;
7
+ siteUrl?: string;
8
+ lang?: string;
9
9
  }) => [string];
10
10
  export declare const usePrevAndNext: () => NavigatorBannerProps['post'][];
11
11
  /**
@@ -1,20 +1,5 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- /// <reference types="node" />
5
- /// <reference types="lodash" />
6
- declare type Status = 'responded' | 'error' | 'timeout';
7
- export declare const ping: (callback: (status: Status) => void) => NodeJS.Timeout;
1
+ import { Status } from '../types';
2
+ export declare function ping(): Promise<Status>;
8
3
  export declare const getChinaMirrorHost: (host?: string) => string;
9
- export declare function getGithubSourceUrl(githubUrl: string, relativePath: string, prefix?: string): string;
10
- export declare const getAllDemosInCategory: (allDemos: any[], lang: string) => import("lodash").Dictionary<any[]>;
11
- export declare const getSortedCategories: (allDemosInCategory: any, locale: string) => string[];
12
- export declare const getGroupedEdges: (edges: any) => import("lodash").Dictionary<any[]>;
13
- export declare const getGroupedEdgesDataEdit: (examples: any, edges: any, local: string) => string[];
14
- export declare const getTreeDataByExamplesAndEdges: (examples: any, edges: any, locale: string) => {
15
- title: any;
16
- value: string;
17
- icon: any;
18
- children: any[];
19
- }[];
20
- export {};
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;
@@ -1,30 +1,67 @@
1
- import { groupBy } from 'lodash-es';
2
- export var ping = function ping(callback) {
3
- var url = 'https://private-a' + 'lipay' + 'objects.alip' + 'ay.com/alip' + 'ay-rmsdeploy-image/rmsportal/RKuAiriJqrUhyqW.png';
4
- var img = new Image();
5
- var done = false;
6
-
7
- var finish = function finish(status) {
8
- if (!done) {
9
- done = true;
10
- img.src = '';
11
- callback(status);
12
- }
13
- };
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
14
2
 
15
- img.onload = function () {
16
- return finish('responded');
17
- };
3
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
18
4
 
19
- img.onerror = function () {
20
- return finish('error');
21
- };
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+
7
+ 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."); }
8
+
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+
11
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
+
13
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
14
+
15
+ 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; }
16
+
17
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
18
+
19
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
20
+
21
+ export function ping() {
22
+ return _ping.apply(this, arguments);
23
+ }
24
+
25
+ function _ping() {
26
+ _ping = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
27
+ var timeout, network;
28
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
29
+ while (1) {
30
+ switch (_context.prev = _context.next) {
31
+ case 0:
32
+ timeout = new Promise(function (resolve) {
33
+ setTimeout(function () {
34
+ resolve('timeout');
35
+ }, 1500);
36
+ });
37
+ network = new Promise(function (resolve) {
38
+ var url = 'https://private-a' + 'lipay' + 'objects.alip' + 'ay.com/alip' + 'ay-rmsdeploy-image/rmsportal/RKuAiriJqrUhyqW.png';
39
+ var img = new Image();
40
+
41
+ img.onload = function () {
42
+ img.src = '';
43
+ resolve('responded');
44
+ };
45
+
46
+ img.onerror = function () {
47
+ img.src = '';
48
+ resolve('error');
49
+ };
50
+
51
+ img.src = url;
52
+ });
53
+ return _context.abrupt("return", Promise.race([timeout, network]));
54
+
55
+ case 3:
56
+ case "end":
57
+ return _context.stop();
58
+ }
59
+ }
60
+ }, _callee);
61
+ }));
62
+ return _ping.apply(this, arguments);
63
+ }
22
64
 
23
- img.src = url;
24
- return setTimeout(function () {
25
- return finish('timeout');
26
- }, 1500);
27
- };
28
65
  export var getChinaMirrorHost = function getChinaMirrorHost(host) {
29
66
  var hostString = typeof host === 'undefined' ? window.location.host : host; // antv.vision => antv.gitee.io
30
67
 
@@ -41,7 +78,7 @@ export var getChinaMirrorHost = function getChinaMirrorHost(host) {
41
78
 
42
79
  return hostString;
43
80
  };
44
- export function getGithubSourceUrl(githubUrl, relativePath) {
81
+ export function getGithubSourceURL(githubUrl, relativePath) {
45
82
  var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'examples';
46
83
 
47
84
  // https://github.com/antvis/x6/tree/master/packages/x6-sites
@@ -51,104 +88,25 @@ export function getGithubSourceUrl(githubUrl, relativePath) {
51
88
 
52
89
  return "".concat(githubUrl, "/edit/master/").concat(prefix, "/").concat(relativePath);
53
90
  }
54
- export var getAllDemosInCategory = function getAllDemosInCategory(allDemos, lang) {
55
- return groupBy(allDemos || [], function (demo) {
56
- if (!demo.postFrontmatter || !demo.postFrontmatter[lang]) {
57
- return 'OTHER';
58
- }
59
-
60
- return demo.postFrontmatter[lang].title;
61
- });
62
- };
63
- export var getSortedCategories = function getSortedCategories(allDemosInCategory, locale) {
64
- return Object.keys(allDemosInCategory).sort(function (a, b) {
65
- if (a === 'OTHER') {
66
- return -1;
67
- }
91
+ export var filterTreeNode = function filterTreeNode(treeNode, keyValue, locale) {
92
+ if (treeNode.childrenKey && Array.isArray(treeNode[treeNode.childrenKey])) {
93
+ var children = treeNode[treeNode.childrenKey];
94
+ var filteredChildren = children.filter(function (child) {
95
+ var c = filterTreeNode(child, keyValue, locale);
96
+ return c !== null;
97
+ });
68
98
 
69
- if (b === 'OTHER') {
70
- return 1;
99
+ if (filteredChildren.length > 0) {
100
+ treeNode[treeNode.childrenKey] = _toConsumableArray(filteredChildren);
101
+ return treeNode;
71
102
  }
72
-
73
- return allDemosInCategory[a][0].postFrontmatter[locale].order - allDemosInCategory[b][0].postFrontmatter[locale].order;
74
- });
75
- };
76
-
77
- var getMenuItemLocaleKey = function getMenuItemLocaleKey() {
78
- var slug = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
79
- var slugPieces = slug.split('/');
80
- return slugPieces.slice(slugPieces.indexOf('examples') + 1).filter(function (key) {
81
- return key;
82
- }).join('/');
83
- };
84
-
85
- var getExampleOrder = function getExampleOrder(options) {
86
- var groupedEdgeKey = options.groupedEdgeKey,
87
- groupedEdges = options.groupedEdges,
88
- examples = options.examples;
89
- var key = getMenuItemLocaleKey(groupedEdgeKey);
90
-
91
- if (examples.find(function (item) {
92
- return item.slug === key;
93
- })) {
94
- return (examples.findIndex(function (item) {
95
- return item.slug === key;
96
- }) || 0) + 100;
97
103
  }
98
104
 
99
- if (!groupedEdges[groupedEdgeKey] && !groupedEdges[groupedEdgeKey].length) {
100
- return 0;
101
- }
105
+ var isCurrentTreeNodeMatched = treeNode.title[locale].toLowerCase().includes(keyValue.toLowerCase()); // 当前节点自身匹配,那么其孩子直接匹配,可以直接返回当前节点
102
106
 
103
- return groupedEdges[groupedEdgeKey][0].node.frontmatter.order || 0;
104
- };
107
+ if (isCurrentTreeNodeMatched) {
108
+ return treeNode;
109
+ }
105
110
 
106
- export var getGroupedEdges = function getGroupedEdges(edges) {
107
- return groupBy(edges, function (_ref) {
108
- var slugString = _ref.node.fields.slug;
109
-
110
- // API.md and design.md
111
- if (slugString.endsWith('/API') || slugString.endsWith('/design')) {
112
- return slugString.split('/').slice(0, -2).join('/');
113
- } // index.md
114
-
115
-
116
- return slugString.split('/').slice(0, -1).join('/');
117
- });
118
- }; // 提取出筛选 和 排序的方法 好在获取treeData 的时候使用
119
-
120
- export var getGroupedEdgesDataEdit = function getGroupedEdgesDataEdit(examples, edges, local) {
121
- var groupedEdges = getGroupedEdges(edges);
122
- return Object.keys(groupedEdges).filter(function (key) {
123
- return key.startsWith("/".concat(local, "/"));
124
- }).sort(function (a, b) {
125
- var aOrder = getExampleOrder({
126
- groupedEdgeKey: a,
127
- examples: examples,
128
- groupedEdges: groupedEdges
129
- });
130
- var bOrder = getExampleOrder({
131
- groupedEdgeKey: b,
132
- examples: examples,
133
- groupedEdges: groupedEdges
134
- });
135
- return aOrder - bOrder;
136
- });
137
- };
138
- export var getTreeDataByExamplesAndEdges = function getTreeDataByExamplesAndEdges(examples, edges, locale) {
139
- return getGroupedEdgesDataEdit(examples, edges, locale).map(function (slugString) {
140
- var menuItemLocaleKey = getMenuItemLocaleKey(slugString);
141
- var doc = examples.find(function (item) {
142
- return item.slug === menuItemLocaleKey;
143
- }) || {};
144
- return {
145
- title: doc && doc.title ? doc.title[locale] : menuItemLocaleKey,
146
- value: slugString,
147
- icon: doc.icon,
148
- children: getGroupedEdges(edges)[slugString].filter(function (edge) {
149
- var slug = edge.node.fields.slug;
150
- return !(slug.endsWith('/API') || slug.endsWith('/design') || slug.endsWith('/gallery'));
151
- })
152
- };
153
- });
111
+ return null;
154
112
  };
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export interface IThemeConfig {
2
2
  [key: string]: any;
3
3
  }
4
+ export declare type Status = 'responded' | 'error' | 'timeout';
package/dist/typings.d.ts CHANGED
@@ -24,13 +24,17 @@ declare module '\*.svg' {
24
24
  }
25
25
 
26
26
  declare namespace ExamplesPage {
27
- /** 案例 DEMO */
28
- export interface Demo {
27
+ export interface TreeNode {
29
28
  /**
30
29
  * id
31
30
  */
32
31
  id: string;
33
32
 
33
+ /**
34
+ * 孩子节点 key
35
+ */
36
+ childrenKey?: string;
37
+
34
38
  /**
35
39
  * 标题(支持国际化)
36
40
  */
@@ -39,6 +43,11 @@ declare namespace ExamplesPage {
39
43
  en: string;
40
44
  };
41
45
 
46
+ [key: string]: any;
47
+ }
48
+
49
+ /** 案例 DEMO */
50
+ export interface Demo extends TreeNode {
42
51
  /**
43
52
  * 截图
44
53
  */
@@ -76,20 +85,7 @@ declare namespace ExamplesPage {
76
85
  }
77
86
 
78
87
  /** 示例 */
79
- export interface Example {
80
- /**
81
- * id
82
- */
83
- id: string;
84
-
85
- /**
86
- * 标题(支持国际化)
87
- */
88
- title: {
89
- zh: string;
90
- en: string;
91
- };
92
-
88
+ export interface Example extends TreeNode {
93
89
  /**
94
90
  * 图标
95
91
  */
@@ -102,27 +98,16 @@ declare namespace ExamplesPage {
102
98
  }
103
99
 
104
100
  /** 案例主题 */
105
- export interface ExampleTopic {
101
+ export interface ExampleTopic extends TreeNode {
106
102
  /**
107
- * id 和文件夹目录名保持一致
103
+ * 图标
108
104
  */
109
- id: string;
105
+ icon: string;
106
+
110
107
  /**
111
108
  * slug 和 id 一样,兼容旧配置
112
109
  */
113
110
  slug?: string;
114
- /**
115
- * 标题
116
- */
117
- title: {
118
- zh: string;
119
- en: string;
120
- };
121
-
122
- /**
123
- * 图标
124
- */
125
- icon: string;
126
111
 
127
112
  /**
128
113
  * 所有案例
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.3.0-beta.3",
3
+ "version": "0.3.0-beta.4",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "types": "dist/types.d.ts",
6
6
  "scripts": {
7
7
  "dev": "father dev",
8
+ "dev:example-site": "cd example && npm run start",
8
9
  "build": "father build",
9
10
  "prepare": "father link-dev-theme",
10
11
  "lint": "npm run lint:es && npm run lint:css",
@@ -61,7 +62,7 @@
61
62
  "classnames": "^2.3.2",
62
63
  "codesandbox": "^2.2.3",
63
64
  "docsearch.js": "^2.6.3",
64
- "dumi": "^2.0.0-beta.11",
65
+ "dumi": "^2.0.0-beta.15",
65
66
  "front-matter": "^4.0.2",
66
67
  "fs-extra": "^10.1.0",
67
68
  "glob": "^8.0.3",
@@ -84,7 +85,7 @@
84
85
  "uri-parse": "^1.0.0"
85
86
  },
86
87
  "peerDependencies": {
87
- "dumi": "^2.0.0-beta.14",
88
+ "dumi": "^2.0.0-beta.15",
88
89
  "react": ">=16.9.0",
89
90
  "react-dom": ">=16.9.0"
90
91
  },
@@ -100,7 +101,6 @@
100
101
  "@types/react-router-dom": "^5.3.3",
101
102
  "@types/react-slick": "^0.23.10",
102
103
  "@umijs/lint": "^4.0.0",
103
- "dumi": "^2.0.0-beta.14",
104
104
  "eslint": "^8.23.0",
105
105
  "father": "^4.1.0",
106
106
  "father-plugin-dumi-theme": "^1.0.0-beta.1",