@antv/dumi-theme-antv 0.3.3 → 0.3.5

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.
@@ -11,7 +11,8 @@ import "../slots/_.less";
11
11
 
12
12
  export default (function () {
13
13
  var _useSiteData = useSiteData(),
14
- themeConfig = _useSiteData.themeConfig;
14
+ themeConfig = _useSiteData.themeConfig,
15
+ loading = _useSiteData.loading;
15
16
 
16
17
  var navs = themeConfig.navs; // 打印控制台文案
17
18
 
@@ -21,8 +22,19 @@ export default (function () {
21
22
  var outlet = useOutlet();
22
23
 
23
24
  var _useLocation = useLocation(),
24
- pathname = _useLocation.pathname;
25
+ pathname = _useLocation.pathname,
26
+ hash = _useLocation.hash; // 监听 hash 变更,跳转到锚点位置
27
+ // 同时监听页面 loading 状态,因为路由按需加载时需要等待页面渲染完毕才能找到锚点位置
25
28
 
29
+
30
+ useEffect(function () {
31
+ var id = hash.replace('#', '');
32
+
33
+ if (id) {
34
+ var elm = document.getElementById(decodeURIComponent(id));
35
+ if (elm) document.documentElement.scrollTo(0, elm.offsetTop - 80);
36
+ }
37
+ }, [loading, hash]);
26
38
  var path = pathname; // 统一去掉中英文前缀
27
39
 
28
40
  var p = path.replace('/zh/', '/').replace('/en/', '/'); // 首页
@@ -49,6 +49,10 @@ export declare type HeaderProps = {
49
49
  rootDomain?: string;
50
50
  /** 是否显示 AntV 产品卡片 */
51
51
  showAntVProductsCard?: boolean;
52
+ /**
53
+ * 当前版本
54
+ */
55
+ version?: string;
52
56
  /** 展示版本切换 */
53
57
  versions?: {
54
58
  [key: string]: string;
@@ -30,7 +30,7 @@ import { Products } from "./Products";
30
30
  import { Navs } from "./Navs";
31
31
  import { Logo } from "./Logo";
32
32
  import { LogoWhite } from "./LogoWhite";
33
- import { getLangUrl } from "./utils";
33
+ import { findVersion, getLangUrl } from "./utils";
34
34
  import { ic } from "../hooks";
35
35
  import styles from "./index.module.less";
36
36
 
@@ -78,6 +78,7 @@ var HeaderComponent = function HeaderComponent(_ref) {
78
78
  isAntVSite = _ref$isAntVSite === void 0 ? false : _ref$isAntVSite,
79
79
  _ref$rootDomain = _ref.rootDomain,
80
80
  rootDomain = _ref$rootDomain === void 0 ? '' : _ref$rootDomain,
81
+ version = _ref.version,
81
82
  versions = _ref.versions,
82
83
  internalSite = _ref.internalSite,
83
84
  ecosystems = _ref.ecosystems,
@@ -314,7 +315,7 @@ var HeaderComponent = function HeaderComponent(_ref) {
314
315
  })),
315
316
  /** 版本列表 */
316
317
  versions && /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(Select, {
317
- defaultValue: Object.keys(versions)[0],
318
+ defaultValue: versions[findVersion(version, Object.keys(versions))],
318
319
  className: styles.versions,
319
320
  bordered: false,
320
321
  size: "small",
@@ -450,6 +451,7 @@ export var Header = function Header(props) {
450
451
  showWxQrcode = themeConfig.showWxQrcode,
451
452
  defaultLanguage = themeConfig.defaultLanguage,
452
453
  showAntVProductsCard = themeConfig.showAntVProductsCard,
454
+ version = themeConfig.version,
453
455
  versions = themeConfig.versions,
454
456
  ecosystems = themeConfig.ecosystems,
455
457
  navs = themeConfig.navs,
@@ -474,6 +476,7 @@ export var Header = function Header(props) {
474
476
  showWxQrcode: showWxQrcode,
475
477
  defaultLanguage: defaultLanguage,
476
478
  showAntVProductsCard: showAntVProductsCard,
479
+ version: version,
477
480
  versions: versions,
478
481
  ecosystems: ecosystems,
479
482
  navs: navs,
@@ -7,3 +7,4 @@ export declare function getLangUrl(url: string, lang: string): string;
7
7
  * @param url
8
8
  */
9
9
  export declare function getNavCategory(url: string): string;
10
+ export declare function findVersion(v: string, versions: string[]): string;
@@ -1,4 +1,5 @@
1
1
  import URI from 'uri-parse';
2
+ import semver from 'semver';
2
3
  /*
3
4
  * parse url like this
4
5
  *
@@ -36,4 +37,10 @@ export function getNavCategory(url) {
36
37
  return (url || '').split('/').find(function (d) {
37
38
  return !['en', 'zh', 'docs', ''].includes(d);
38
39
  });
40
+ }
41
+ export function findVersion(v, versions) {
42
+ var version = versions.find(function (version) {
43
+ return semver.satisfies(v, version);
44
+ });
45
+ return version ? version : versions[0];
39
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "types": "dist/types.d.ts",
6
6
  "scripts": {
@@ -83,6 +83,7 @@
83
83
  "react-split-pane": "^0.1.92",
84
84
  "react-use": "^17.4.0",
85
85
  "reading-time": "^1.5.0",
86
+ "semver": "^7.3.8",
86
87
  "size-sensor": "^1.0.1",
87
88
  "slick-carousel": "^1.8.1",
88
89
  "uri-parse": "^1.0.0",