@antv/dumi-theme-antv 0.3.0-beta.2 → 0.3.0-beta.22

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 (89) hide show
  1. package/dist/builtins/Playground/index.d.ts +3 -6
  2. package/dist/builtins/Playground/index.js +27 -7
  3. package/dist/context.d.ts +2 -1
  4. package/dist/layouts/DocLayout.js +25 -16
  5. package/dist/layouts/entry/Index.js +21 -12
  6. package/dist/layouts/entry/Manual.js +6 -4
  7. package/dist/pages/404.js +7 -4
  8. package/dist/pages/Example/index.js +31 -55
  9. package/dist/pages/Example/index.module.less +50 -8
  10. package/dist/pages/Example/utils.d.ts +1 -0
  11. package/dist/pages/Example/utils.js +9 -0
  12. package/dist/pages/Examples/components/ExampleTopicMenu/components/LeftMenu/index.js +6 -1
  13. package/dist/pages/Examples/components/GalleryPageContent/DemoCard/index.js +11 -6
  14. package/dist/pages/Examples/index.js +24 -4
  15. package/dist/pages/Examples/index.module.less +15 -0
  16. package/dist/pages/Examples/types.d.ts +7 -6
  17. package/dist/plugin/examples.d.ts +14 -5
  18. package/dist/plugin/examples.js +17 -3
  19. package/dist/plugin/index.js +31 -8
  20. package/dist/plugin/utils.js +3 -2
  21. package/dist/slots/Article/index.d.ts +3 -0
  22. package/dist/slots/Article/index.js +11 -0
  23. package/dist/slots/Article/index.module.less +8 -0
  24. package/dist/slots/Banner/Notification.d.ts +10 -0
  25. package/dist/slots/Banner/Notification.js +43 -0
  26. package/dist/slots/Banner/Notification.module.less +120 -0
  27. package/dist/slots/Banner/index.d.ts +26 -0
  28. package/dist/slots/Banner/index.js +184 -0
  29. package/dist/slots/Banner/index.module.less +449 -0
  30. package/dist/slots/Cases/index.d.ts +1 -0
  31. package/dist/slots/Cases/index.js +13 -7
  32. package/dist/slots/Cases/index.module.less +2 -1
  33. package/dist/slots/CodeEditor/Toolbar.js +17 -22
  34. package/dist/slots/CodeEditor/index.d.ts +4 -0
  35. package/dist/slots/CodeEditor/index.js +71 -23
  36. package/dist/slots/CodeEditor/utils.js +2 -2
  37. package/dist/slots/CodePreview/CodeHeader.js +15 -14
  38. package/dist/slots/CodePreview/index.d.ts +8 -0
  39. package/dist/slots/CodePreview/index.js +15 -6
  40. package/dist/slots/CodePreview/index.module.less +17 -7
  41. package/dist/slots/CodeRunner/index.d.ts +5 -2
  42. package/dist/slots/CodeRunner/index.js +19 -8
  43. package/dist/slots/CodeRunner/utils.d.ts +3 -2
  44. package/dist/slots/CodeRunner/utils.js +1 -1
  45. package/dist/slots/Companies/index.d.ts +1 -1
  46. package/dist/slots/{TOC.d.ts → ContentTable/index.d.ts} +2 -1
  47. package/dist/slots/{TOC.js → ContentTable/index.js} +2 -1
  48. package/dist/slots/ContentTable/index.module.less +11 -0
  49. package/dist/slots/Detail/News.d.ts +1 -0
  50. package/dist/slots/Detail/News.js +3 -2
  51. package/dist/slots/Detail/index.d.ts +1 -0
  52. package/dist/slots/Detail/index.js +4 -2
  53. package/dist/slots/ExampleSider/index.d.ts +4 -38
  54. package/dist/slots/ExampleSider/index.js +28 -49
  55. package/dist/slots/ExampleSider/index.module.less +1 -1
  56. package/dist/slots/Features/FeatureCard.d.ts +1 -0
  57. package/dist/slots/Features/index.js +7 -3
  58. package/dist/slots/Features/index.module.less +1 -1
  59. package/dist/slots/Footer/index.js +34 -14
  60. package/dist/slots/Header/LogoWhite.js +1 -2
  61. package/dist/slots/Header/Navs.d.ts +10 -1
  62. package/dist/slots/Header/Navs.js +36 -19
  63. package/dist/slots/Header/Products/NavigatorBanner.js +4 -3
  64. package/dist/slots/Header/Products/Product.js +7 -3
  65. package/dist/slots/Header/Products/index.js +5 -3
  66. package/dist/slots/Header/Search.js +5 -3
  67. package/dist/slots/Header/index.d.ts +7 -2
  68. package/dist/slots/Header/index.js +135 -30
  69. package/dist/slots/Loading/index.d.ts +6 -1
  70. package/dist/slots/Loading/index.js +24 -10
  71. package/dist/slots/Loading/index.module.less +276 -9
  72. package/dist/slots/ManualContent/NavigatorBanner.js +5 -3
  73. package/dist/slots/ManualContent/ReadingTime.js +6 -2
  74. package/dist/slots/ManualContent/index.js +143 -126
  75. package/dist/slots/ManualContent/index.module.less +52 -33
  76. package/dist/slots/ManualContent/utils.d.ts +18 -0
  77. package/dist/slots/ManualContent/utils.js +64 -0
  78. package/dist/slots/SEO.d.ts +10 -0
  79. package/dist/slots/SEO.js +59 -0
  80. package/dist/slots/_.less +1 -1
  81. package/dist/slots/hooks.d.ts +4 -4
  82. package/dist/slots/hooks.js +5 -8
  83. package/dist/slots/utils.d.ts +4 -19
  84. package/dist/slots/utils.js +82 -119
  85. package/dist/types.d.ts +83 -0
  86. package/dist/typings.d.ts +0 -116
  87. package/package.json +9 -5
  88. package/dist/slots/Loading.d.ts +0 -5
  89. package/dist/slots/Loading.js +0 -8
@@ -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
  }
@@ -1,12 +1,21 @@
1
+ import { Example, ExampleTopic } from '../types';
1
2
  /**
2
3
  * 获取案例页面的所有主题
3
4
  *
4
- * @returns {ExamplesPage.ExampleTopic[]} 案例主题列表
5
+ * @returns {ExampleTopic[]} 案例主题列表
5
6
  * @author YuZhanglong <loveyzl1123@gmail.com>
6
7
  */
7
- export declare const getExamplesPageTopics: (exampleTopics: ExamplesPage.ExampleTopic[]) => {
8
+ export declare const getExamplesPageTopics: (exampleTopics: ExampleTopic[]) => {
8
9
  id: string;
9
- title: ExamplesPage.ExampleTopic;
10
- icon: ExamplesPage.ExampleTopic;
11
- examples: ExamplesPage.Example[];
10
+ title: {
11
+ zh: string;
12
+ en: string;
13
+ };
14
+ icon: string;
15
+ examples: Example[];
16
+ childrenKey: string;
12
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);
@@ -63,10 +64,12 @@ var getTopicExamples = (topicPath) => {
63
64
  title: {
64
65
  en: exampleMetaEnContent.attributes.title,
65
66
  zh: exampleMetaZhContent.attributes.title
66
- }
67
+ },
68
+ childrenKey: "demos",
69
+ order: exampleMetaZhContent.attributes.order || 0
67
70
  };
68
71
  return example;
69
- });
72
+ }).sort((a, b) => a.order - b.order);
70
73
  };
71
74
  var getExamplesPageTopics = (exampleTopics) => {
72
75
  return exampleTopics.map(({ id, slug, title, icon }) => {
@@ -81,11 +84,22 @@ var getExamplesPageTopics = (exampleTopics) => {
81
84
  id: nid,
82
85
  title,
83
86
  icon,
84
- examples
87
+ examples,
88
+ childrenKey: "examples"
85
89
  };
86
90
  });
87
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
+ }
88
101
  // Annotate the CommonJS export names for ESM import in node:
89
102
  0 && (module.exports = {
103
+ getExamplePaths,
90
104
  getExamplesPageTopics
91
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,29 +25,50 @@ __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}` });
33
+ api.modifyDefaultConfig((memo) => {
34
+ memo.resolve.codeBlockMode = "passive";
35
+ memo.exportStatic.extraRoutePaths = (0, import_examples.getExamplePaths)();
36
+ memo.mfsu = false;
37
+ memo.jsMinifier = "terser";
38
+ memo.favicons = ["https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*7svFR6wkPMoAAAAAAAAAAAAADmJ7AQ/original"];
39
+ return memo;
40
+ });
29
41
  const pages = [
42
+ {
43
+ id: "dumi-theme-antv-homepage",
44
+ absPath: "/"
45
+ },
46
+ {
47
+ id: "dumi-theme-antv-en-homepage",
48
+ absPath: "/en/"
49
+ },
50
+ {
51
+ id: "dumi-theme-antv-zh-homepage",
52
+ absPath: "/zh/"
53
+ },
30
54
  {
31
55
  id: "dumi-theme-antv-example-list-zh",
32
- path: "/examples/",
56
+ absPath: "/examples",
33
57
  file: (0, import_utils.myResolve)("../pages/Examples/index.tsx")
34
58
  },
35
59
  {
36
60
  id: "dumi-theme-antv-example-list-lang",
37
- path: "/:language/examples/",
61
+ absPath: "/:language/examples",
38
62
  file: (0, import_utils.myResolve)("../pages/Examples/index.tsx")
39
63
  },
40
64
  {
41
65
  id: "dumi-theme-antv-single-example-zh",
42
- path: "/examples/:topic/:example",
66
+ absPath: "/examples/:topic/:example",
43
67
  file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
44
68
  },
45
69
  {
46
70
  id: "dumi-theme-antv-single-example-lang",
47
- path: "/:language/examples/:topic/:example",
71
+ absPath: "/:language/examples/:topic/:example",
48
72
  file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
49
73
  }
50
74
  ];
@@ -60,8 +84,6 @@ import { ThemeAntVContext } from '${contextFilePath}';
60
84
 
61
85
  export default function ThemeAntVContextWrapper() {
62
86
  const outlet = useOutlet();
63
- // const { themeConfig } = useSiteData();
64
- // const exampleTopics = themeConfig?.examples || [];
65
87
 
66
88
  return (
67
89
  <ThemeAntVContext.Provider
@@ -86,8 +108,8 @@ export default function ThemeAntVContextWrapper() {
86
108
  pages.forEach((page) => {
87
109
  routes[page.id] = {
88
110
  id: page.id,
89
- path: page.path,
90
- absPath: page.path,
111
+ path: page.absPath.slice(1),
112
+ absPath: page.absPath,
91
113
  file: page.file,
92
114
  parentId: "DocLayout"
93
115
  };
@@ -95,6 +117,7 @@ export default function ThemeAntVContextWrapper() {
95
117
  routes["404"].file = (0, import_utils.myResolve)("../pages/404.tsx");
96
118
  return routes;
97
119
  });
120
+ api.addTmpGenerateWatcherPaths(() => [path.resolve(process.cwd(), "examples")]);
98
121
  };
99
122
  // Annotate the CommonJS export names for ESM import in node:
100
123
  0 && (module.exports = {});
@@ -26,7 +26,6 @@ __export(utils_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(utils_exports);
28
28
  var path = __toESM(require("path"));
29
- var fs = __toESM(require("fs"));
30
29
  function myResolve(p, alternateExts = [".js"]) {
31
30
  const extname2 = path.extname(p);
32
31
  const pathname = p.slice(0, p.length - extname2.length);
@@ -34,8 +33,10 @@ function myResolve(p, alternateExts = [".js"]) {
34
33
  for (let i = 0; i < exts.length; i++) {
35
34
  const ext = exts[i];
36
35
  const fullpath = `${pathname}${ext}`;
37
- if (fs.existsSync(require.resolve(fullpath)))
36
+ try {
38
37
  return require.resolve(fullpath);
38
+ } catch (e) {
39
+ }
39
40
  }
40
41
  return "";
41
42
  }
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const Article: React.FC<any>;
3
+ export default Article;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { Layout } from 'antd';
3
+ import styles from "./index.module.less";
4
+
5
+ var Article = function Article(props) {
6
+ return /*#__PURE__*/React.createElement(Layout.Content, {
7
+ className: styles.article
8
+ }, /*#__PURE__*/React.createElement("article", props));
9
+ };
10
+
11
+ export default Article;
@@ -0,0 +1,8 @@
1
+ .article {
2
+ padding: 0;
3
+
4
+ h2 {
5
+ font-size: 36px;
6
+ margin-top: 0;
7
+ }
8
+ }
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ export interface NotificationProps {
3
+ index?: number;
4
+ type: string;
5
+ title: string;
6
+ date: string;
7
+ link: string;
8
+ }
9
+ declare const Notification: React.FC<NotificationProps>;
10
+ export default Notification;
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { Link } from 'dumi';
3
+ import styles from "./Notification.module.less";
4
+ var numberImages = ['https://gw.alipayobjects.com/zos/antfincdn/IqREAm36K7/1.png', 'https://gw.alipayobjects.com/zos/antfincdn/3fG1Iqjfnz/2.png'];
5
+
6
+ var Notification = function Notification(_ref) {
7
+ var _ref$index = _ref.index,
8
+ index = _ref$index === void 0 ? 0 : _ref$index,
9
+ type = _ref.type,
10
+ title = _ref.title,
11
+ date = _ref.date,
12
+ _ref$link = _ref.link,
13
+ link = _ref$link === void 0 ? '' : _ref$link;
14
+ var children = /*#__PURE__*/React.createElement("div", {
15
+ className: styles.container
16
+ }, /*#__PURE__*/React.createElement("img", {
17
+ className: styles.number,
18
+ src: numberImages[index],
19
+ alt: index.toString()
20
+ }), /*#__PURE__*/React.createElement("div", {
21
+ className: styles.content
22
+ }, /*#__PURE__*/React.createElement("p", {
23
+ className: styles.description
24
+ }, type, " \u2027 ", title), /*#__PURE__*/React.createElement("p", {
25
+ className: styles.date
26
+ }, date)));
27
+
28
+ if (link.startsWith('http')) {
29
+ return /*#__PURE__*/React.createElement("a", {
30
+ href: link,
31
+ target: "_blank",
32
+ rel: "noopener noreferrer",
33
+ className: styles.notification
34
+ }, children);
35
+ }
36
+
37
+ return /*#__PURE__*/React.createElement(Link, {
38
+ to: link,
39
+ className: styles.notification
40
+ }, children);
41
+ };
42
+
43
+ export default Notification;
@@ -0,0 +1,120 @@
1
+ .notification {
2
+ width: 50%;
3
+ margin-right: 2%;
4
+
5
+ &:last-child {
6
+ margin-right: 0;
7
+ }
8
+
9
+ .container {
10
+ height: 44px;
11
+ display: flex;
12
+
13
+ .number {
14
+ height: 100%;
15
+ width: 44px;
16
+ }
17
+
18
+ .content {
19
+ padding-left: 20px;
20
+ color: rgba(49, 70, 89, 1);
21
+ text-align: left;
22
+
23
+ .description {
24
+ top: 0;
25
+ font-size: 1.14em;
26
+ margin-bottom: 0;
27
+ transition: all 0.3s;
28
+ }
29
+
30
+ .date {
31
+ color: rgba(216, 203, 249, 1);
32
+ bottom: 0;
33
+ font-size: 1em;
34
+ margin-top: 4px;
35
+ margin-bottom: 0;
36
+ }
37
+ }
38
+ }
39
+
40
+ &:hover .description {
41
+ color: rgba(89, 126, 247, 1);
42
+ }
43
+ }
44
+
45
+ @media (max-width: 900px) {
46
+ .notification {
47
+ position: absolute;
48
+ width: 100%;
49
+
50
+ &:nth-child(1) {
51
+ animation: showAndHide0 6s infinite;
52
+ }
53
+
54
+ &:nth-child(2) {
55
+ top: 44px;
56
+ animation: showAndHide1 6s infinite;
57
+ }
58
+ }
59
+ }
60
+
61
+ @media (max-width: 768px) {
62
+ .notification {
63
+ width: 100%;
64
+ }
65
+ }
66
+
67
+ @keyframes showAndHide0 {
68
+ 0% {
69
+ opacity: 1;
70
+ top: 0px;
71
+ }
72
+
73
+ 33.3% {
74
+ opacity: 1;
75
+ top: 0px;
76
+ }
77
+
78
+ 50% {
79
+ opacity: 0;
80
+ top: -30px;
81
+ }
82
+
83
+ 83.3% {
84
+ opacity: 0;
85
+ top: 30px;
86
+ }
87
+
88
+ 100% {
89
+ opacity: 1;
90
+ top: 0px;
91
+ }
92
+ }
93
+
94
+ /* Standard syntax */
95
+ @keyframes showAndHide1 {
96
+ 0% {
97
+ opacity: 0;
98
+ top: 30px;
99
+ }
100
+
101
+ 33.3% {
102
+ opacity: 0;
103
+ top: 30px;
104
+ }
105
+
106
+ 50% {
107
+ opacity: 1;
108
+ top: 0px;
109
+ }
110
+
111
+ 83.3% {
112
+ opacity: 1;
113
+ top: 0px;
114
+ }
115
+
116
+ 100% {
117
+ opacity: 0;
118
+ top: -30px;
119
+ }
120
+ }
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { NotificationProps } from './Notification';
3
+ import 'video-react/dist/video-react.css';
4
+ declare type BannerButtonShape = 'round' | 'square';
5
+ interface BannerButton {
6
+ text: string;
7
+ link: string;
8
+ style?: React.CSSProperties;
9
+ type?: string;
10
+ shape?: BannerButtonShape;
11
+ }
12
+ interface BannerProps {
13
+ coverImage?: React.ReactNode;
14
+ title: string;
15
+ description: string;
16
+ notifications?: NotificationProps[];
17
+ style?: React.CSSProperties;
18
+ className?: string;
19
+ video?: string;
20
+ showGithubStars?: boolean;
21
+ buttons?: BannerButton[];
22
+ onCloseVideo?: () => void;
23
+ onPlayVideo?: () => void;
24
+ }
25
+ declare const Banner: React.FC<BannerProps>;
26
+ export default Banner;
@@ -0,0 +1,184 @@
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
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
8
+
9
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
+
11
+ 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."); }
12
+
13
+ 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); }
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 _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
18
+
19
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
+
21
+ import React, { useEffect, useState } from 'react';
22
+ import { Modal } from 'antd';
23
+ import { CaretRightOutlined } from '@ant-design/icons';
24
+ import { FormattedMessage, Link, useLocale, useSiteData } from 'dumi';
25
+ import classNames from 'classnames';
26
+ import GitHubButton from 'react-github-button';
27
+ import gh from 'parse-github-url';
28
+ import { Player } from 'video-react';
29
+ import Notification from "./Notification";
30
+ import 'video-react/dist/video-react.css';
31
+ import styles from "./index.module.less";
32
+ var backLeftBottom = 'https://gw.alipayobjects.com/zos/basement_prod/441d5eaf-e623-47cd-b9b9-2a581d9ce1e3.svg';
33
+
34
+ var Banner = function Banner(_ref) {
35
+ var coverImage = _ref.coverImage,
36
+ title = _ref.title,
37
+ description = _ref.description,
38
+ notifications = _ref.notifications,
39
+ _ref$style = _ref.style,
40
+ style = _ref$style === void 0 ? {} : _ref$style,
41
+ className = _ref.className,
42
+ video = _ref.video,
43
+ _ref$showGithubStars = _ref.showGithubStars,
44
+ showGithubStars = _ref$showGithubStars === void 0 ? true : _ref$showGithubStars,
45
+ _ref$buttons = _ref.buttons,
46
+ buttons = _ref$buttons === void 0 ? [] : _ref$buttons,
47
+ onCloseVideo = _ref.onCloseVideo,
48
+ onPlayVideo = _ref.onPlayVideo;
49
+ var locale = useLocale();
50
+ var lang = locale.id.includes('zh') ? 'zh' : 'en';
51
+ var notificationsUrl = "https://my-json-server.typicode.com/antvis/antvis-sites-data/notifications?lang=".concat(lang);
52
+
53
+ var _useState = useState([]),
54
+ _useState2 = _slicedToArray(_useState, 2),
55
+ remoteNews = _useState2[0],
56
+ setRemoteNews = _useState2[1];
57
+
58
+ var _useSiteData = useSiteData(),
59
+ themeConfig = _useSiteData.themeConfig;
60
+
61
+ var githubUrl = themeConfig.githubUrl;
62
+ useEffect(function () {
63
+ fetch(notificationsUrl).then(function (res) {
64
+ return res.json();
65
+ }).then(function (data) {
66
+ setRemoteNews(data);
67
+ });
68
+ }, [notificationsUrl]);
69
+ var notificationsNode = (notifications || remoteNews).slice(0, 2).map(function (notification, i) {
70
+ return /*#__PURE__*/React.createElement(Notification, _extends({
71
+ index: i,
72
+ key: i
73
+ }, notification));
74
+ });
75
+
76
+ var showVideo = function showVideo() {
77
+ if (onPlayVideo) {
78
+ onPlayVideo();
79
+ }
80
+
81
+ Modal.info({
82
+ title: 'This is a notification message',
83
+ className: styles.videoModal,
84
+ onCancel: onCloseVideo,
85
+ content: /*#__PURE__*/React.createElement(Player, {
86
+ className: styles.video,
87
+ autoPlay: true,
88
+ src: video
89
+ }),
90
+ width: '70%'
91
+ });
92
+ };
93
+
94
+ var renderButtons = buttons.map(function (button, i) {
95
+ var ButtonLink = button.link.startsWith('http') || button.link.startsWith('#') ? 'a' : Link;
96
+ var buttonProps = {};
97
+
98
+ if (button.link.startsWith('http')) {
99
+ buttonProps.target = '_blank';
100
+ buttonProps.rel = 'noopener noreferrer';
101
+ }
102
+
103
+ if (ButtonLink === 'a') {
104
+ buttonProps.href = button.link;
105
+ } else {
106
+ buttonProps.to = button.link;
107
+ }
108
+
109
+ var _button$shape = button.shape,
110
+ shape = _button$shape === void 0 ? 'round' : _button$shape;
111
+ return /*#__PURE__*/React.createElement(ButtonLink, _extends({}, buttonProps, {
112
+ className: classNames(styles.buttonLink, styles[button.type || ''], button.type === 'primary' ? 'primary-button' : 'common-button'),
113
+ key: i,
114
+ style: _objectSpread({
115
+ borderRadius: shape === 'round' ? '1000px' : '4px'
116
+ }, button.style)
117
+ }), /*#__PURE__*/React.createElement("span", {
118
+ className: styles.button
119
+ }, button.text));
120
+ });
121
+
122
+ if (video) {
123
+ renderButtons.push( /*#__PURE__*/React.createElement("div", {
124
+ key: "video",
125
+ onClick: showVideo,
126
+ className: styles.videoButtonWrapper
127
+ }, /*#__PURE__*/React.createElement("div", {
128
+ className: styles.videoButton
129
+ }, /*#__PURE__*/React.createElement(CaretRightOutlined, {
130
+ className: styles.videoButtonIcon
131
+ }), /*#__PURE__*/React.createElement("p", {
132
+ className: styles.videoButtonText,
133
+ style: {
134
+ fontSize: '14px',
135
+ lineHeight: '40px'
136
+ }
137
+ }, /*#__PURE__*/React.createElement(FormattedMessage, {
138
+ id: "\u77E5\u6E90\u30FB\u81F4\u8FDC"
139
+ })))));
140
+ }
141
+
142
+ if (showGithubStars) {
143
+ var githubObj = gh(githubUrl);
144
+
145
+ if (githubObj && githubObj.owner && githubObj.name) {
146
+ renderButtons.push( /*#__PURE__*/React.createElement("div", {
147
+ key: "github",
148
+ className: styles.githubWrapper
149
+ }, /*#__PURE__*/React.createElement(GitHubButton, {
150
+ type: "stargazers",
151
+ size: "large",
152
+ namespace: githubObj.owner,
153
+ repo: githubObj.name
154
+ })));
155
+ }
156
+ }
157
+
158
+ return /*#__PURE__*/React.createElement("section", {
159
+ className: classNames(styles.wrapper, className),
160
+ style: style
161
+ }, /*#__PURE__*/React.createElement("div", {
162
+ className: styles.content
163
+ }, /*#__PURE__*/React.createElement("div", {
164
+ className: styles.text
165
+ }, /*#__PURE__*/React.createElement("div", {
166
+ className: classNames(styles.title, 'banner-title')
167
+ }, title), /*#__PURE__*/React.createElement("p", {
168
+ className: classNames(styles.description, 'banner-description')
169
+ }, description), /*#__PURE__*/React.createElement("div", {
170
+ className: classNames(styles.buttons, 'banner-buttons')
171
+ }, renderButtons)), /*#__PURE__*/React.createElement("div", {
172
+ className: classNames(styles.notifications, 'notifications')
173
+ }, notificationsNode), /*#__PURE__*/React.createElement("div", {
174
+ className: classNames(styles.teaser, 'teaser')
175
+ }, /*#__PURE__*/React.createElement("div", {
176
+ className: classNames(styles.teaserimg, 'teaser-img')
177
+ }, coverImage)), /*#__PURE__*/React.createElement("img", {
178
+ className: styles.backLeftBottom,
179
+ src: backLeftBottom,
180
+ alt: "back"
181
+ })));
182
+ };
183
+
184
+ export default Banner;