@antv/dumi-theme-antv 0.6.3 → 0.6.4-alpha.0

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 (61) hide show
  1. package/dist/builtins/Playground/index.js +1 -1
  2. package/dist/common/ClientOnly.js +21 -0
  3. package/dist/common/InViewSuspense.js +26 -0
  4. package/dist/common/SEO.js +3 -1
  5. package/dist/hooks/useLocale.js +8 -0
  6. package/dist/hooks/useMenu.js +1 -1
  7. package/dist/layouts/DocLayout.js +15 -11
  8. package/dist/layouts/IndexLayout/index.js +16 -0
  9. package/dist/layouts/{entry/Manual.js → ManualLayout/index.js} +5 -4
  10. package/dist/pages/404.js +3 -2
  11. package/dist/pages/Example/components/ExampleSider/index.js +190 -0
  12. package/dist/pages/Example/index.js +70 -51
  13. package/dist/pages/Examples/components/ExampleTopicMenu/index.js +3 -2
  14. package/dist/pages/Examples/index.js +26 -30
  15. package/dist/{slots → pages/Index/components}/Cases/index.js +1 -1
  16. package/dist/{slots → pages/Index/components}/Detail/News.js +1 -1
  17. package/dist/{slots → pages/Index/components}/Detail/index.js +1 -1
  18. package/dist/{slots → pages/Index/components}/Features/FeatureCard.js +1 -1
  19. package/dist/{slots → pages/Index/components}/Features/index.js +1 -1
  20. package/dist/pages/Index/components/_.less +119 -0
  21. package/dist/{layouts/entry/Index.js → pages/Index/index.js} +15 -19
  22. package/dist/plugin/index.js +52 -43
  23. package/dist/slots/CodeEditor/index.js +4 -3
  24. package/dist/slots/CodePreview/CodeHeader.js +3 -2
  25. package/dist/slots/CodePreview/index.js +3 -2
  26. package/dist/slots/CodeRunner/index.js +34 -29
  27. package/dist/slots/ExampleSider/index.js +3 -2
  28. package/dist/slots/Feedback/Contributors.js +3 -2
  29. package/dist/slots/Feedback/EditButton.js +3 -2
  30. package/dist/slots/Feedback/PageFeedback.js +4 -3
  31. package/dist/slots/Feedback/SectionFeedback.js +3 -2
  32. package/dist/slots/Feedback/index.js +12 -10
  33. package/dist/slots/Footer/index.js +3 -2
  34. package/dist/slots/Header/Search/index.js +1 -1
  35. package/dist/slots/Header/index.js +17 -12
  36. package/dist/slots/ManualContent/Main.js +17 -17
  37. package/dist/slots/ManualContent/NavigatorBanner.js +4 -2
  38. package/dist/slots/ManualContent/ObPreview.js +17 -0
  39. package/dist/slots/ManualContent/index.js +2 -4
  40. package/dist/slots/ManualContent/usePreview.js +7 -1
  41. package/dist/slots/ManualContent/utils.js +3 -13
  42. package/dist/slots/global.js +4 -4
  43. package/dist/slots/hooks.js +0 -25
  44. package/dist/slots/utils.js +0 -7
  45. package/dist/utils/env.js +10 -0
  46. package/dist/utils/location.js +3 -0
  47. package/package.json +6 -5
  48. package/dist/layouts/entry/API.js +0 -12
  49. package/dist/pages/Example/utils.js +0 -9
  50. package/dist/slots/Article/index.js +0 -9
  51. package/dist/slots/Article/index.module.less +0 -8
  52. package/dist/slots/CodePreview/CodeHeader.module.less +0 -0
  53. package/dist/slots/Header/Products/NavigatorBanner.js +0 -29
  54. package/dist/slots/Header/Products/NavigatorBanner.module.less +0 -39
  55. /package/dist/{slots → pages/Index/components}/Cases/index.module.less +0 -0
  56. /package/dist/{slots → pages/Index/components}/Companies/index.js +0 -0
  57. /package/dist/{slots → pages/Index/components}/Companies/index.module.less +0 -0
  58. /package/dist/{slots → pages/Index/components}/Detail/News.module.less +0 -0
  59. /package/dist/{slots → pages/Index/components}/Detail/index.module.less +0 -0
  60. /package/dist/{slots → pages/Index/components}/Features/FeatureCard.module.less +0 -0
  61. /package/dist/{slots → pages/Index/components}/Features/index.module.less +0 -0
@@ -1,13 +1,15 @@
1
1
  import { useSiteData } from 'dumi';
2
- import React from 'react';
3
- import { styled } from 'styled-components';
4
- import { Contributors } from "./Contributors";
5
- import { EditButton } from "./EditButton";
6
- import { SectionFeedback } from "./SectionFeedback";
7
- var StyledWrapper = styled.div.withConfig({
8
- displayName: "StyledWrapper",
9
- componentId: "dumi-theme-antv-c7ef__sc-yubwx0-0"
10
- })(["margin-top:40px;"]);
2
+ import React, { lazy } from 'react';
3
+ import InViewSuspense from "../../common/InViewSuspense";
4
+ var EditButton = /*#__PURE__*/lazy(function () {
5
+ return import("./EditButton");
6
+ });
7
+ var Contributors = /*#__PURE__*/lazy(function () {
8
+ return import("./Contributors");
9
+ });
10
+ var SectionFeedback = /*#__PURE__*/lazy(function () {
11
+ return import("./SectionFeedback");
12
+ });
11
13
  export var Feedback = function Feedback() {
12
14
  var _useSiteData = useSiteData(),
13
15
  themeConfig = _useSiteData.themeConfig;
@@ -15,5 +17,5 @@ export var Feedback = function Feedback() {
15
17
  if (!feedback) {
16
18
  return null;
17
19
  }
18
- return /*#__PURE__*/React.createElement(StyledWrapper, null, /*#__PURE__*/React.createElement(EditButton, null), /*#__PURE__*/React.createElement(Contributors, null), /*#__PURE__*/React.createElement(SectionFeedback, null));
20
+ return /*#__PURE__*/React.createElement(InViewSuspense, null, /*#__PURE__*/React.createElement(EditButton, null), /*#__PURE__*/React.createElement(Contributors, null), /*#__PURE__*/React.createElement(SectionFeedback, null));
19
21
  };
@@ -18,7 +18,7 @@ import styles from "./index.module.less";
18
18
  * 底部菜单
19
19
  * @returns
20
20
  */
21
- export var Footer = function Footer(props) {
21
+ var Footer = function Footer(props) {
22
22
  var columns = props.columns,
23
23
  bottom = props.bottom,
24
24
  language = props.language,
@@ -222,4 +222,5 @@ export var Footer = function Footer(props) {
222
222
  href: "https://xtech.antfin.com/"
223
223
  }, "AntV")))))
224
224
  }, omit(restProps, ['githubUrl'])));
225
- };
225
+ };
226
+ export default Footer;
@@ -8,9 +8,9 @@ import { SearchOutlined } from '@ant-design/icons';
8
8
  import { Popover } from 'antd';
9
9
  import { useIntl, useSiteData, useSiteSearch } from 'dumi';
10
10
  import React, { useEffect, useMemo, useState } from 'react';
11
- import { SearchResult } from "./SearchResult";
12
11
  import { getSearchResults } from "./helper";
13
12
  import styles from "./index.module.less";
13
+ import { SearchResult } from "./SearchResult";
14
14
  export var Search = function Search() {
15
15
  var intl = useIntl();
16
16
  var _useState = useState(false),
@@ -21,6 +21,7 @@ import { get, map, size } from 'lodash-es';
21
21
  import React, { useEffect, useMemo, useState } from 'react';
22
22
  import { useNavigate } from 'react-router-dom';
23
23
  import { useMedia } from 'react-use';
24
+ import { getPurePathname } from "../../utils/location";
24
25
  import { ic } from "../hooks";
25
26
  import { Navs } from "./Navs";
26
27
  import { Products } from "./Products";
@@ -28,6 +29,7 @@ import { Search } from "./Search";
28
29
  import { findVersion, getLangUrl } from "./utils";
29
30
  import { Assistant } from '@petercatai/assistant';
30
31
  import '@petercatai/assistant/style';
32
+ import { useLocation } from 'react-router-dom';
31
33
  import { determineUserType } from "../../utils/user";
32
34
  import styles from "./index.module.less";
33
35
  function redirectChinaMirror(chinaMirrorOrigin) {
@@ -154,11 +156,13 @@ var HeaderComponent = function HeaderComponent(_ref) {
154
156
  }, logo),
155
157
  img = _img$link$logo.img,
156
158
  link = _img$link$logo.link;
159
+ var _useLocation = useLocation(),
160
+ pathname = _useLocation.pathname;
157
161
  useEffect(function () {
158
162
  if (popupMenuVisible) {
159
163
  setPopupMenuVisible(false);
160
164
  }
161
- }, [window.location.pathname]);
165
+ }, [pathname]);
162
166
 
163
167
  // 移动端下弹出菜单时,禁止页面滚动
164
168
  useEffect(function () {
@@ -188,7 +192,7 @@ var HeaderComponent = function HeaderComponent(_ref) {
188
192
  }, /** 最左侧的菜单,一般是 教程、API、示例,或者其他自定义,有配置文件中的 `navs` 决定 */
189
193
  size(navs) ? /*#__PURE__*/React.createElement(Navs, {
190
194
  navs: navs,
191
- path: window.location.pathname
195
+ path: pathname
192
196
  }) : null, /** 生态产品 */
193
197
  size(ecosystems) ? /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(Dropdown, {
194
198
  className: styles.ecoSystems,
@@ -242,7 +246,7 @@ var HeaderComponent = function HeaderComponent(_ref) {
242
246
  updateChinaMirrorHintVisible(false);
243
247
  }
244
248
  }, "\u4E0D\u518D\u63D0\u9192"))),
245
- visible: chinaMirrorHintVisible,
249
+ open: chinaMirrorHintVisible,
246
250
  placement: "bottomRight",
247
251
  align: {
248
252
  offset: [-12, -16]
@@ -258,7 +262,7 @@ var HeaderComponent = function HeaderComponent(_ref) {
258
262
  marginLeft: '6px'
259
263
  }
260
264
  })))) : null, showChinaMirror && !isWide && /*#__PURE__*/React.createElement(Modal, {
261
- visible: chinaMirrorHintVisible,
265
+ open: chinaMirrorHintVisible,
262
266
  cancelText: "\u4E0D\u518D\u63D0\u9192",
263
267
  okText: "\u7ACB\u5373\u524D\u5F80",
264
268
  onCancel: function onCancel() {
@@ -412,10 +416,10 @@ var HeaderComponent = function HeaderComponent(_ref) {
412
416
  className: styles.banner,
413
417
  message: /*#__PURE__*/React.createElement("div", {
414
418
  className: styles.topAlert
415
- }, announcement.icon && /*#__PURE__*/React.createElement("img", {
419
+ }, (announcement === null || announcement === void 0 ? void 0 : announcement.icon) && /*#__PURE__*/React.createElement("img", {
416
420
  src: announcement.icon
417
421
  }), /*#__PURE__*/React.createElement("div", null, announcementTitle), announcementLinkTitle && /*#__PURE__*/React.createElement("a", {
418
- href: announcement.link.url
422
+ href: announcement === null || announcement === void 0 ? void 0 : announcement.link.url
419
423
  }, announcementLinkTitle)),
420
424
  type: "info",
421
425
  banner: true,
@@ -433,12 +437,12 @@ var HeaderComponent = function HeaderComponent(_ref) {
433
437
  }), /*#__PURE__*/React.createElement("h2", {
434
438
  className: styles.subProduceName
435
439
  }, /*#__PURE__*/React.createElement("a", {
436
- href: window.location.pathname.startsWith('/en') ? '/en' : '/'
440
+ href: pathname.startsWith('/en') ? '/en' : '/'
437
441
  }, subTitle))), showSearch && !isAntVHome && /*#__PURE__*/React.createElement(Search, null)), /*#__PURE__*/React.createElement("nav", {
438
442
  className: styles.nav
439
443
  }, menu, menuIcon)));
440
444
  };
441
- export var Header = function Header(props) {
445
+ var Header = function Header(props) {
442
446
  var _useSiteData = useSiteData(),
443
447
  themeConfig = _useSiteData.themeConfig;
444
448
  var title = themeConfig.title,
@@ -465,9 +469,9 @@ export var Header = function Header(props) {
465
469
  var searchOptions = {
466
470
  docsearchOptions: docsearchOptions
467
471
  };
468
- var locale = useLocale();
469
- var path = window.location.pathname;
470
- var isHomePage = path === '/' || path === "/".concat(locale.id) || path === "/".concat(locale.id, "/");
472
+ var _useLocation2 = useLocation(),
473
+ pathname = _useLocation2.pathname;
474
+ var isHomePage = ['/', ''].includes(getPurePathname(pathname));
471
475
  var headerProps = {
472
476
  subTitle: title,
473
477
  subTitleHref: subTitleHref,
@@ -539,4 +543,5 @@ export var Header = function Header(props) {
539
543
  token: petercat === null || petercat === void 0 ? void 0 : petercat.token,
540
544
  apiDomain: "https://api.petercat.ai"
541
545
  }));
542
- };
546
+ };
547
+ export default Header;
@@ -1,23 +1,21 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
- 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."); }
3
- 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); }
4
- 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; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
1
  import { VerticalAlignTopOutlined } from '@ant-design/icons';
8
2
  import { BackTop, Layout } from 'antd';
9
3
  import { useRouteMeta } from 'dumi';
10
- import React from 'react';
4
+ import React, { lazy, Suspense } from 'react';
11
5
  import { useMedia } from 'react-use';
12
6
  import readingTime from 'reading-time';
13
- import { useMenu } from "../../hooks/useMenu";
7
+ import InViewSuspense from "../../common/InViewSuspense";
14
8
  import { ContentTable } from "dumi/theme/slots/ContentTable";
15
9
  import { Feedback } from "dumi/theme/slots/Feedback";
16
- import { PageFeedback } from "../Feedback/PageFeedback";
17
10
  import styles from "./index.module.less";
18
11
  import { PrevAndNext } from "./PrevAndNext";
19
12
  import ReadingTime from "./ReadingTime";
20
- import { usePreview } from "./usePreview";
13
+ var PageFeedback = /*#__PURE__*/lazy(function () {
14
+ return import("../Feedback/PageFeedback");
15
+ });
16
+ var ObPreview = /*#__PURE__*/lazy(function () {
17
+ return import("./ObPreview");
18
+ });
21
19
  export var Main = function Main(_ref) {
22
20
  var children = _ref.children;
23
21
  var meta = useRouteMeta();
@@ -26,13 +24,11 @@ export var Main = function Main(_ref) {
26
24
  }, '');
27
25
  var _readingTime = readingTime(text),
28
26
  time = _readingTime.time;
29
- var _useMenu = useMenu(),
30
- _useMenu2 = _slicedToArray(_useMenu, 2),
31
- selectedKey = _useMenu2[1];
32
27
  var is991Wide = useMedia('(min-width: 991.99px)', true);
33
28
  var showToc = is991Wide && meta.frontmatter.showToc !== false;
34
- usePreview({}, selectedKey);
35
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Layout.Content, {
29
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Suspense, {
30
+ fallback: null
31
+ }, /*#__PURE__*/React.createElement(ObPreview, null)), /*#__PURE__*/React.createElement(Layout.Content, {
36
32
  className: styles.content
37
33
  }, /*#__PURE__*/React.createElement("div", {
38
34
  className: styles.main
@@ -45,7 +41,11 @@ export var Main = function Main(_ref) {
45
41
  className: styles.readtime
46
42
  })), /*#__PURE__*/React.createElement("div", {
47
43
  className: styles.markdown
48
- }, children), /*#__PURE__*/React.createElement(Feedback, null), /*#__PURE__*/React.createElement(PrevAndNext, null)), /*#__PURE__*/React.createElement(BackTop, {
44
+ }, children), /*#__PURE__*/React.createElement("div", {
45
+ style: {
46
+ marginTop: '40px'
47
+ }
48
+ }, /*#__PURE__*/React.createElement(Feedback, null)), /*#__PURE__*/React.createElement(PrevAndNext, null)), /*#__PURE__*/React.createElement(BackTop, {
49
49
  style: {
50
50
  right: 24
51
51
  }
@@ -56,5 +56,5 @@ export var Main = function Main(_ref) {
56
56
  width: 260
57
57
  }, /*#__PURE__*/React.createElement("div", {
58
58
  className: styles.toc
59
- }, /*#__PURE__*/React.createElement(PageFeedback, null), /*#__PURE__*/React.createElement(ContentTable, null))));
59
+ }, /*#__PURE__*/React.createElement(InViewSuspense, null, /*#__PURE__*/React.createElement(PageFeedback, null)), /*#__PURE__*/React.createElement(ContentTable, null))));
60
60
  };
@@ -1,11 +1,13 @@
1
1
  import classNames from 'classnames';
2
- import { FormattedMessage, history } from 'dumi';
2
+ import { history, useIntl } from 'dumi';
3
3
  import React from 'react';
4
4
  import { useScrollToTop } from "../hooks";
5
5
  import styles from "./NavigatorBanner.module.less";
6
6
  export var NavigatorBanner = function NavigatorBanner(_ref) {
7
7
  var post = _ref.post,
8
8
  type = _ref.type;
9
+ var _useIntl = useIntl(),
10
+ formatMessage = _useIntl.formatMessage;
9
11
  if (!post) {
10
12
  return /*#__PURE__*/React.createElement("div", {
11
13
  className: classNames(styles.button, styles.hidden)
@@ -25,7 +27,7 @@ export var NavigatorBanner = function NavigatorBanner(_ref) {
25
27
  onClick: go
26
28
  }, /*#__PURE__*/React.createElement("div", {
27
29
  className: styles.label
28
- }, /*#__PURE__*/React.createElement(FormattedMessage, {
30
+ }, formatMessage({
29
31
  id: type === 'prev' ? '上一篇' : '下一篇'
30
32
  })), /*#__PURE__*/React.createElement("div", {
31
33
  className: styles.title
@@ -0,0 +1,17 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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); }
4
+ 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; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import React from 'react';
8
+ import { useMenu } from "../../hooks/useMenu";
9
+ import { usePreview } from "./usePreview";
10
+ var ObPreview = function ObPreview() {
11
+ var _useMenu = useMenu(),
12
+ _useMenu2 = _slicedToArray(_useMenu, 2),
13
+ selectedKey = _useMenu2[1];
14
+ usePreview({}, selectedKey);
15
+ return /*#__PURE__*/React.createElement("div", null);
16
+ };
17
+ export default ObPreview;
@@ -1,5 +1,5 @@
1
1
  import { Layout } from 'antd';
2
- import React, { Suspense } from 'react';
2
+ import React from 'react';
3
3
  import styles from "./index.module.less";
4
4
  import { Main } from "./Main";
5
5
  import { Sidebar } from "./Sidebar";
@@ -8,7 +8,5 @@ export var ManualContent = function ManualContent(_ref) {
8
8
  return /*#__PURE__*/React.createElement(Layout, {
9
9
  hasSider: true,
10
10
  className: styles.layout
11
- }, /*#__PURE__*/React.createElement(Sidebar, null), /*#__PURE__*/React.createElement(Suspense, {
12
- fallback: null
13
- }, /*#__PURE__*/React.createElement(Main, null, children)));
11
+ }, /*#__PURE__*/React.createElement(Sidebar, null), /*#__PURE__*/React.createElement(Main, null, children));
14
12
  };
@@ -2,6 +2,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
2
2
  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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
3
  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); }
4
4
  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; }
5
+ 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); }
5
6
  import React, { useEffect } from 'react';
6
7
  import { createRoot } from 'react-dom/client';
7
8
  import { Preview } from "./Preview";
@@ -28,11 +29,16 @@ function sourceOf(block) {
28
29
  return cloned.textContent;
29
30
  }
30
31
  function blockOf() {
31
- return Array.from(document.querySelectorAll('.ob-codeblock .dumi-default-source-code'));
32
+ if ((typeof document === "undefined" ? "undefined" : _typeof(document)) !== undefined && document) {
33
+ var blocks = Array.from(document.querySelectorAll('.ob-codeblock .dumi-default-source-code'));
34
+ return blocks;
35
+ }
36
+ return [];
32
37
  }
33
38
  export function usePreview() {
34
39
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
35
40
  var select = arguments.length > 1 ? arguments[1] : undefined;
41
+ if (typeof document === 'undefined') return;
36
42
  var key = select + ',' + blockOf().length;
37
43
  useEffect(function () {
38
44
  var blocks = blockOf();
@@ -1,27 +1,17 @@
1
1
  import { isEmpty } from 'lodash-es';
2
- export function getOpenKeys() {
3
- var pathname = window.location.pathname.replace('/docs/', '/').replace('/zh/', '/');
4
- var pathArr = pathname.split('/');
5
- var openKeys = [];
6
- for (var i = pathArr.length; i > 0; i--) {
7
- var tem = pathArr.slice(0, i);
8
- openKeys.push(tem.join('/'));
9
- }
10
- return openKeys;
11
- }
12
2
 
13
3
  /**
14
4
  * /api/xxx --> /api
15
5
  * /en/api --> /en/api
16
6
  */
17
- export function getBaseRoute() {
18
- var matchRoute = window.location.pathname;
7
+ export function getBaseRoute(pathname) {
8
+ var matchRoute = pathname;
19
9
  // 兼容 zh
20
10
  matchRoute = matchRoute.replace('/zh/', '/');
21
11
  // 兼容带有docs的route
22
12
  matchRoute = matchRoute.replace('/docs', '');
23
13
  // 查找 baseRoute
24
- var reg = window.location.pathname.startsWith('/en') ? /(\/[A-z]*\/?\/[A-z]*)\/?/ : /(\/[A-z]*)\/?/;
14
+ var reg = pathname.startsWith('/en') ? /(\/[A-z]*\/?\/[A-z]*)\/?/ : /(\/[A-z]*)\/?/;
25
15
  var mainRoute = matchRoute.match(reg);
26
16
  return mainRoute[1];
27
17
  }
@@ -1,8 +1,8 @@
1
1
  import insertCss from 'insert-css';
2
2
  import * as _ from 'lodash-es';
3
-
4
- // 挂载一些全局变量
5
- if (window) {
3
+ import { safeWindow } from "../utils/env";
4
+ safeWindow(function (window) {
5
+ // 挂载一些全局变量
6
6
  window.lodash = _;
7
7
  window.insertCss = insertCss;
8
- }
8
+ });
@@ -49,31 +49,6 @@ export var useLogoLink = function useLogoLink(_ref) {
49
49
  }, []);
50
50
  return [giteeLogoLink || defaultLogoLink];
51
51
  };
52
- export var usePrevAndNext = function usePrevAndNext() {
53
- var _useState5 = useState([]),
54
- _useState6 = _slicedToArray(_useState5, 2),
55
- prevAndNext = _useState6[0],
56
- setPrevAndNext = _useState6[1];
57
- useEffect(function () {
58
- var menuNodes = document.querySelectorAll('aside .ant-menu-item a');
59
- var currentMenuNode = document.querySelector('aside .ant-menu-item-selected a');
60
- var currentIndex = Array.from(menuNodes).findIndex(function (node) {
61
- return node === currentMenuNode;
62
- });
63
- var prevNode = currentIndex - 1 >= 0 ? menuNodes[currentIndex - 1] : undefined;
64
- var nextNode = currentIndex + 1 < menuNodes.length ? menuNodes[currentIndex + 1] : undefined;
65
- var prev = prevNode ? {
66
- slug: prevNode.getAttribute('href') || undefined,
67
- title: prevNode.textContent || undefined
68
- } : undefined;
69
- var next = nextNode ? {
70
- slug: nextNode.getAttribute('href') || undefined,
71
- title: nextNode.textContent || undefined
72
- } : undefined;
73
- setPrevAndNext([prev, next]);
74
- }, []);
75
- return prevAndNext;
76
- };
77
52
 
78
53
  /**
79
54
  * i18n .umirc config
@@ -9,13 +9,6 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
9
9
  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); } }
10
10
  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); }); }; }
11
11
  import { icWithLocale } from "./hooks";
12
-
13
- /**
14
- * 统一去掉中英文前缀
15
- */
16
- export function getCurrentPathname() {
17
- return window.location.pathname.replace('/zh/', '/').replace('/en/', '/');
18
- }
19
12
  export function ping() {
20
13
  return _ping.apply(this, arguments);
21
14
  }
@@ -0,0 +1,10 @@
1
+ // 判断是否在浏览器环境
2
+ export var isBrowser = function isBrowser() {
3
+ return typeof window !== 'undefined' && window;
4
+ };
5
+
6
+ // 安全访问浏览器 API
7
+ // eslint-disable-next-line no-unused-vars
8
+ export var safeWindow = function safeWindow(fn) {
9
+ if (isBrowser()) fn(window);
10
+ };
@@ -0,0 +1,3 @@
1
+ export function getPurePathname(pathname) {
2
+ return pathname.replace('/zh', '').replace('/en', '');
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.6.3",
3
+ "version": "0.6.4-alpha.0",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "keywords": [
6
6
  "dumi",
@@ -67,14 +67,13 @@
67
67
  "monaco-editor": "^0.25.2",
68
68
  "nprogress": "^0.2.0",
69
69
  "parse-github-url": "^1.0.3",
70
- "prettier": "^2.8.8",
71
70
  "rc-drawer": "^4.4.3",
72
71
  "rc-footer": "^0.6.8",
73
72
  "react": "^18.3.1",
74
73
  "react-dom": "^18.3.1",
75
74
  "react-error-boundary": "^3.1.4",
76
75
  "react-github-button": "^0.1.11",
77
- "react-helmet": "^6.1.0",
76
+ "react-intersection-observer": "^9.16.0",
78
77
  "react-markdown": "^9.0.1",
79
78
  "react-router-dom": "^6.28.0",
80
79
  "react-slick": "^0.29.0",
@@ -111,7 +110,7 @@
111
110
  "@types/react-slick": "^0.23.13",
112
111
  "@types/styled-components": "^5.1.34",
113
112
  "@umijs/lint": "^4.3.34",
114
- "dumi": "^2.4.13",
113
+ "dumi": "2.4.13",
115
114
  "eslint": "^8.57.1",
116
115
  "father": "^4.5.1",
117
116
  "father-plugin-dumi-theme": "1.0.0-rc.1",
@@ -119,6 +118,7 @@
119
118
  "less": "^4.2.1",
120
119
  "less-loader": "^12.2.0",
121
120
  "lint-staged": "^13.3.0",
121
+ "prettier": "^2.8.8",
122
122
  "prettier-plugin-organize-imports": "^3.2.4",
123
123
  "prettier-plugin-packagejson": "^2.5.3",
124
124
  "stylelint": "^14.16.1"
@@ -129,7 +129,8 @@
129
129
  "react-dom": ">=16.9.0"
130
130
  },
131
131
  "publishConfig": {
132
- "access": "public"
132
+ "access": "public",
133
+ "tag": "alpha"
133
134
  },
134
135
  "authors": [
135
136
  "dumi",
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { Manual } from "./Manual";
3
-
4
- /**
5
- * API 路由下的入口
6
- * - 读取 API markdown 文件
7
- * - 渲染 UI
8
- */
9
- export var API = function API(_ref) {
10
- var children = _ref.children;
11
- return /*#__PURE__*/React.createElement(Manual, null, children);
12
- };
@@ -1,9 +0,0 @@
1
- export function getCurrentTitle(exampleTopics, topic, example) {
2
- var topicItem = exampleTopics.find(function (item) {
3
- return item.id === topic;
4
- });
5
- var exmapleItem = topicItem.examples.find(function (item) {
6
- return item.id === example;
7
- });
8
- return exmapleItem.title;
9
- }
@@ -1,9 +0,0 @@
1
- import { Layout } from 'antd';
2
- import React from 'react';
3
- import styles from "./index.module.less";
4
- var Article = function Article(props) {
5
- return /*#__PURE__*/React.createElement(Layout.Content, {
6
- className: styles.article
7
- }, /*#__PURE__*/React.createElement("article", props));
8
- };
9
- export default Article;
@@ -1,8 +0,0 @@
1
- .article {
2
- padding: 0;
3
-
4
- h2 {
5
- font-size: 36px;
6
- margin-top: 0;
7
- }
8
- }
File without changes
@@ -1,29 +0,0 @@
1
- import classNames from 'classnames';
2
- import { FormattedMessage, Link } from 'dumi';
3
- import React from 'react';
4
- import styles from "./NavigatorBanner.module.less";
5
- var NavigatorBanner = function NavigatorBanner(_ref) {
6
- var post = _ref.post,
7
- type = _ref.type;
8
- if (!post) {
9
- return /*#__PURE__*/React.createElement("div", {
10
- className: classNames(styles.button, styles.hidden)
11
- });
12
- }
13
- var slug = post.slug,
14
- title = post.title;
15
- if (!slug || !title) {
16
- return null;
17
- }
18
- return /*#__PURE__*/React.createElement(Link, {
19
- to: slug,
20
- className: classNames(styles.button, styles[type])
21
- }, /*#__PURE__*/React.createElement("div", {
22
- className: styles.label
23
- }, /*#__PURE__*/React.createElement(FormattedMessage, {
24
- id: type === 'prev' ? '上一篇' : '下一篇'
25
- })), /*#__PURE__*/React.createElement("div", {
26
- className: styles.title
27
- }, title));
28
- };
29
- export default NavigatorBanner;
@@ -1,39 +0,0 @@
1
- .button {
2
- width: 50%;
3
- display: inline-block;
4
- margin-top: 32px;
5
- padding: 32px 0 0;
6
- cursor: pointer;
7
- border-top: 1px solid #e8e8e8;
8
- line-height: 1.5;
9
- vertical-align: top;
10
-
11
- &.hidden {
12
- height: 86px;
13
- cursor: auto;
14
- }
15
-
16
- .label {
17
- margin-bottom: 8px;
18
- font-size: 14px;
19
- color: #bfbfbf;
20
- }
21
-
22
- .title {
23
- font-size: 16px;
24
- font-weight: 500;
25
- color: #333;
26
- transition: all 0.3s;
27
- white-space: nowrap;
28
- overflow: hidden;
29
- text-overflow: ellipsis;
30
- }
31
-
32
- &:hover .title {
33
- color: #000;
34
- }
35
-
36
- &.next {
37
- text-align: right;
38
- }
39
- }