@antv/dumi-theme-antv 0.5.7-beta.0 → 0.5.7-beta.1

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.
@@ -143,18 +143,27 @@
143
143
  "更多产品": "More Productions",
144
144
  "帮助改进此文档": "Edit this page",
145
145
  "文档贡献者": "Contributors",
146
- "此文档有帮助吗?": "Was this page helpful?",
146
+ "这个页面对你有帮助吗?": "Was this page helpful?",
147
147
  "如果遇到问题或发现某些功能无法正常工作,请通过": "If something is broken or if you need a reply to a problem you've encountered, please ",
148
148
  "提交问题报告": "open an issue instead",
149
149
  "来反馈。否则,团队将无法提供进一步的答复或获取更多信息。": ". Otherwise, the team won't be able to answer back or ask for more information.",
150
150
  "你觉得我们可以如何改进此页面?(可选)": "How can we improve this page? (optional)",
151
151
  "你认为这个页面有哪些做的好的地方?(可选)": "What did you like about this page? (optional)",
152
- "你认为该": "How can we improve",
153
- "部分如何改进更好?(可选)": "section? (optional)",
154
- "反馈已提交": "Feedback Submitted",
152
+ "📖 你认为": "How can we improve",
153
+ "部分如何改进更好?": "section? ",
154
+ "谢谢你的反馈意见!": "Feedback Submitted",
155
155
  "报错了,请稍后再试": "Error, please try again later",
156
- "我们会尽快处理你的反馈,感谢你的支持!": "Thank you for your feedback! We will process it as soon as possible.",
156
+ "感谢你的支持!": "Thank you for your feedback!",
157
157
  "如果问题持续,请前往 GitHub 提交 issue。": "Go head to GitHub issue if the problem persists.",
158
+ "你遇到的问题是什么?": "What kind of problem are you facing?",
159
+ "🚀 留下你的真实感受": "🚀 What is the reason for your feedback?",
160
+ "易于理解": "Easy to understand",
161
+ "解决了我的问题": "Resolved my problem",
162
+ "其它": "Other",
163
+ "缺少我需要的信息": "Missing the information I need",
164
+ "过于复杂/步骤太多": "Too complicated / Too many steps",
165
+ "内容更新不及时": "Out of date",
166
+ "示例/代码有问题": "Sample / code issue",
158
167
  "上一篇": "Previous",
159
168
  "下一篇": "Next",
160
169
  "演示代码报错,请检查": "演示代码报错,请检查",
@@ -142,18 +142,27 @@
142
142
  "更多产品": "更多产品",
143
143
  "帮助改进此文档": "帮助改进此文档",
144
144
  "文档贡献者": "文档贡献者",
145
- "此文档有帮助吗?": "此文档有帮助吗?",
145
+ "这个页面对你有帮助吗?": "这个页面对你有帮助吗?",
146
146
  "如果遇到问题或发现某些功能无法正常工作,请通过": "如果遇到问题或发现某些功能无法正常工作,请通过",
147
147
  "提交问题报告": "提交问题报告",
148
148
  "来反馈。否则,团队将无法提供进一步的答复或获取更多信息。": "来反馈。否则,团队将无法提供进一步的答复或获取更多信息。",
149
149
  "你觉得我们可以如何改进此页面?(可选)": "你觉得我们可以如何改进此页面?(可选)",
150
150
  "你认为这个页面有哪些做的好的地方?(可选)": "你认为这个页面有哪些做的好的地方?(可选)",
151
- "你认为该": "你认为",
152
- "部分如何改进更好?(可选)": "部分如何改进更好?(可选)",
153
- "反馈已提交": "反馈已提交",
151
+ "📖 你认为": "📖 你认为",
152
+ "部分如何改进更好?": "部分如何改进更好?",
153
+ "谢谢你的反馈意见!": "谢谢你的反馈意见!",
154
154
  "报错了,请稍后再试": "报错了,请稍后再试",
155
- "我们会尽快处理你的反馈,感谢你的支持!": "我们会尽快处理你的反馈,感谢你的支持!",
155
+ "感谢你的支持!": "感谢你的支持!",
156
156
  "如果问题持续,请前往 GitHub 提交 issue。": "如果问题持续,请前往 GitHub 提交 issue。",
157
+ "你遇到的问题是什么?": "你遇到的问题是什么?",
158
+ "🚀 留下你的真实感受": "🚀 留下你的真实感受",
159
+ "易于理解": "易于理解",
160
+ "解决了我的问题": "有效解决了我的问题",
161
+ "其它": "其它",
162
+ "缺少我需要的信息": "缺少我需要的信息",
163
+ "过于复杂/步骤太多": "过于复杂/步骤太多",
164
+ "内容更新不及时": "内容更新不及时",
165
+ "示例/代码有问题": "示例/代码有问题",
157
166
  "上一篇": "上一篇",
158
167
  "下一篇": "下一篇",
159
168
  "演示代码报错,请检查": "演示代码报错,请检查",
@@ -1,19 +1,18 @@
1
1
  import { proxy } from 'valtio';
2
- export var feedbackStore = proxy({
3
- show: false
4
- });
2
+ export var feedbackStore = proxy({});
5
3
  export var resetFeedbackState = function resetFeedbackState() {
6
- feedbackStore.show = false;
7
4
  feedbackStore.rating = undefined;
8
5
  feedbackStore.section = undefined;
9
6
  };
10
7
  export var invokePageFeedback = function invokePageFeedback(like) {
11
- feedbackStore.show = true;
12
8
  feedbackStore.rating = like ? '1' : '0';
13
- feedbackStore.section = undefined;
14
9
  };
15
- export var invokeSectionFeedback = function invokeSectionFeedback(section) {
16
- feedbackStore.show = true;
10
+ export var resetPageFeedback = function resetPageFeedback() {
17
11
  feedbackStore.rating = undefined;
12
+ };
13
+ export var invokeSectionFeedback = function invokeSectionFeedback(section) {
18
14
  feedbackStore.section = section;
15
+ };
16
+ export var resetSectionFeedback = function resetSectionFeedback() {
17
+ feedbackStore.section = undefined;
19
18
  };
@@ -36,7 +36,7 @@ var visit;
36
36
  (async () => {
37
37
  ({ visit } = await import("unist-util-visit"));
38
38
  })();
39
- var icon = '<span role="img" aria-label="message" class="anticon anticon-message"><svg viewBox="64 64 896 896" focusable="false" data-icon="message" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M924.3 338.4a447.57 447.57 0 00-96.1-143.3 443.09 443.09 0 00-143-96.3A443.91 443.91 0 00512 64h-2c-60.5.3-119 12.3-174.1 35.9a444.08 444.08 0 00-141.7 96.5 445 445 0 00-95 142.8A449.89 449.89 0 0065 514.1c.3 69.4 16.9 138.3 47.9 199.9v152c0 25.4 20.6 46 45.9 46h151.8a447.72 447.72 0 00199.5 48h2.1c59.8 0 117.7-11.6 172.3-34.3A443.2 443.2 0 00827 830.5c41.2-40.9 73.6-88.7 96.3-142 23.5-55.2 35.5-113.9 35.8-174.5.2-60.9-11.6-120-34.8-175.6zM312.4 560c-26.4 0-47.9-21.5-47.9-48s21.5-48 47.9-48 47.9 21.5 47.9 48-21.4 48-47.9 48zm199.6 0c-26.4 0-47.9-21.5-47.9-48s21.5-48 47.9-48 47.9 21.5 47.9 48-21.5 48-47.9 48zm199.6 0c-26.4 0-47.9-21.5-47.9-48s21.5-48 47.9-48 47.9 21.5 47.9 48-21.5 48-47.9 48z"></path></svg></span>';
39
+ var icon = '<span role="img" aria-label="edit" class="anticon anticon-edit"><svg viewBox="64 64 896 896" focusable="false" data-icon="edit" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M257.7 752c2 0 4-.2 6-.5L431.9 722c2-.4 3.9-1.3 5.3-2.8l423.9-423.9a9.96 9.96 0 000-14.1L694.9 114.9c-1.9-1.9-4.4-2.9-7.1-2.9s-5.2 1-7.1 2.9L256.8 538.8c-1.5 1.5-2.4 3.3-2.8 5.3l-29.5 168.2a33.5 33.5 0 009.4 29.8c6.6 6.4 14.9 9.9 23.8 9.9zm67.4-174.4L687.8 215l73.3 73.3-362.7 362.6-88.9 15.7 15.6-89zM880 836H144c-17.7 0-32 14.3-32 32v36c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-36c0-17.7-14.3-32-32-32z"></path></svg></span>';
40
40
  function remarkFeedback() {
41
41
  return (tree) => {
42
42
  visit(tree, "heading", (node) => {
@@ -1,4 +1,4 @@
1
- import { GithubOutlined } from '@ant-design/icons';
1
+ import { EditOutlined } from '@ant-design/icons';
2
2
  import { Button } from 'antd';
3
3
  import { useIntl, useRouteMeta, useSiteData } from 'dumi';
4
4
  import path from 'path';
@@ -7,7 +7,7 @@ import { styled } from 'styled-components';
7
7
  var StyledWrapper = styled.div.withConfig({
8
8
  displayName: "StyledWrapper",
9
9
  componentId: "dumi-theme-antv-c7ef__sc-lci7vy-0"
10
- })([".button{color:rgba(0,0,0,0.8);&-text{color:rgba(0,0,0,0.65);}}"]);
10
+ })([".button{color:rgba(0,0,0,0.65);}"]);
11
11
  export var EditButton = function EditButton(_ref) {
12
12
  var style = _ref.style;
13
13
  var meta = useRouteMeta();
@@ -25,9 +25,9 @@ export var EditButton = function EditButton(_ref) {
25
25
  type: "text",
26
26
  className: "button",
27
27
  style: style,
28
- icon: /*#__PURE__*/React.createElement(GithubOutlined, {
28
+ icon: /*#__PURE__*/React.createElement(EditOutlined, {
29
29
  style: {
30
- fontSize: 20,
30
+ fontSize: 16,
31
31
  transform: 'translateY(2px)'
32
32
  }
33
33
  }),
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { styled } from 'styled-components';
3
+ import { PageFeedbackReasonForm } from "./PageFeedbackReasonForm";
4
+ import { PageFeedbackVoteButtons } from "./PageFeedbackVoteButtons";
5
+ var StyledWrapper = styled.div.withConfig({
6
+ displayName: "StyledWrapper",
7
+ componentId: "dumi-theme-antv-c7ef__sc-1vamzhw-0"
8
+ })(["background-color:#fff;border-radius:12px;bottom:24px;box-shadow:0 0.5rem 1.2rem #f0f1f2;padding:10px 18px;position:fixed;right:12px;width:262px;z-index:1000;"]);
9
+ export var PageFeedback = function PageFeedback() {
10
+ return /*#__PURE__*/React.createElement(StyledWrapper, null, /*#__PURE__*/React.createElement(PageFeedbackVoteButtons, null), /*#__PURE__*/React.createElement(PageFeedbackReasonForm, null));
11
+ };
@@ -0,0 +1,163 @@
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 { Alert, Button, Divider, Form, Select } from 'antd';
8
+ import { useIntl, useLocale } from 'dumi';
9
+ import React, { useEffect } from 'react';
10
+ import { styled } from 'styled-components';
11
+ import { useSnapshot } from 'valtio';
12
+ import { feedbackStore, resetPageFeedback } from "../../model/feedback";
13
+ import { useGithubRepo } from "../../utils/github";
14
+ import { useFeedbackService } from "./service";
15
+ var StyledFeedbackMessageWrapper = styled.div.withConfig({
16
+ displayName: "StyledFeedbackMessageWrapper",
17
+ componentId: "dumi-theme-antv-c7ef__sc-1xff90d-0"
18
+ })(["display:", ";.ant-divider-horizontal{margin:16px 0;}.alert{margin:12px 0 16px;padding:16px;font-size:13px;line-height:1.8;background-color:rgba(255,251,235,0.5);border:1px solid rgba(173,104,0,0.15);border-radius:8px;.ant-alert-icon{color:#cc8800;}}.alert-link{color:#56390c;font-weight:bold;text-decoration:underline;}.ant-form-item:last-child{margin-bottom:8px;}"], function (props) {
19
+ return props.$rating ? 'block' : 'none';
20
+ });
21
+ export var PageFeedbackReasonForm = function PageFeedbackReasonForm() {
22
+ var _useIntl = useIntl(),
23
+ formatMessage = _useIntl.formatMessage;
24
+ var _Form$useForm = Form.useForm(),
25
+ _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
26
+ form = _Form$useForm2[0];
27
+ var feedbackState = useSnapshot(feedbackStore);
28
+ var _useGithubRepo = useGithubRepo(),
29
+ owner = _useGithubRepo.owner,
30
+ repo = _useGithubRepo.repo;
31
+ var pageUrl = window.location.href;
32
+ var locale = useLocale();
33
+ var currentLocale = locale.id;
34
+ var issueUrl = "https://github.com/".concat(owner, "/").concat(repo, "/issues/new?labels=status%3A+waiting+for+maintainer%2Cdocs-feedback&template=docs-feedback.yml&title=[docs]+&page-url=").concat(pageUrl);
35
+ var alertMsg = /*#__PURE__*/React.createElement("div", null, formatMessage({
36
+ id: '如果遇到问题或发现某些功能无法正常工作,请通过'
37
+ }), /*#__PURE__*/React.createElement("a", {
38
+ onClick: function onClick() {
39
+ return window.open(issueUrl, '_blank');
40
+ },
41
+ className: "alert-link"
42
+ }, formatMessage({
43
+ id: '提交问题报告'
44
+ })), formatMessage({
45
+ id: '来反馈。否则,团队将无法提供进一步的答复或获取更多信息。'
46
+ }));
47
+ var _useFeedbackService = useFeedbackService(),
48
+ submitFeedback = _useFeedbackService.submitFeedback,
49
+ showFeedbackResult = _useFeedbackService.showFeedbackResult;
50
+ var onFinish = function onFinish(values) {
51
+ var params = {
52
+ rating: feedbackState.rating,
53
+ reason: values.reason
54
+ };
55
+ submitFeedback(params).then(function (f) {
56
+ onCancel();
57
+ showFeedbackResult(true);
58
+ }).catch(function () {
59
+ showFeedbackResult(false);
60
+ });
61
+ };
62
+ var onCancel = function onCancel() {
63
+ form.resetFields();
64
+ resetPageFeedback();
65
+ };
66
+ useEffect(function () {
67
+ if (!feedbackState.rating) onCancel();
68
+ }, [feedbackState.rating]);
69
+ var likeReasons = [{
70
+ label: formatMessage({
71
+ id: '容易理解'
72
+ }),
73
+ value: 'easy_to_understand'
74
+ }, {
75
+ label: formatMessage({
76
+ id: '解决了我的问题'
77
+ }),
78
+ value: 'solved_my_problem'
79
+ }, {
80
+ label: formatMessage({
81
+ id: '其它'
82
+ }),
83
+ value: 'other'
84
+ }];
85
+ var dislikeReasons = [{
86
+ label: formatMessage({
87
+ id: '缺少我需要的信息'
88
+ }),
89
+ value: 'missing_information'
90
+ }, {
91
+ label: formatMessage({
92
+ id: '过于复杂/步骤太多'
93
+ }),
94
+ value: 'too_complicated'
95
+ }, {
96
+ label: formatMessage({
97
+ id: '内容更新不及时'
98
+ }),
99
+ value: 'out_of_date'
100
+ }, {
101
+ label: formatMessage({
102
+ id: '示例/代码有问题'
103
+ }),
104
+ value: 'code_issue'
105
+ }, {
106
+ label: formatMessage({
107
+ id: '其它'
108
+ }),
109
+ value: 'other'
110
+ }];
111
+ var reasons = feedbackState.rating === '1' ? likeReasons : dislikeReasons;
112
+ useEffect(function () {
113
+ // 默认选中第一个原因
114
+ form === null || form === void 0 || form.setFieldsValue({
115
+ reason: reasons[0].value
116
+ });
117
+ }, [feedbackState.rating, currentLocale]);
118
+ var dislike = feedbackState.rating !== '1';
119
+ return /*#__PURE__*/React.createElement(StyledFeedbackMessageWrapper, {
120
+ $rating: feedbackState.rating
121
+ }, /*#__PURE__*/React.createElement(Divider, {
122
+ dashed: true
123
+ }), /*#__PURE__*/React.createElement("div", {
124
+ className: "form"
125
+ }, /*#__PURE__*/React.createElement(Form, {
126
+ form: form,
127
+ name: "page-feedback-form",
128
+ onFinish: onFinish,
129
+ layout: "vertical"
130
+ }, /*#__PURE__*/React.createElement(Form.Item, {
131
+ name: "reason",
132
+ label: formatMessage({
133
+ id: '🚀 留下你的真实感受'
134
+ })
135
+ }, /*#__PURE__*/React.createElement(Select, {
136
+ options: reasons
137
+ })), dislike && /*#__PURE__*/React.createElement(Alert, {
138
+ type: "warning",
139
+ className: "alert",
140
+ message: alertMsg,
141
+ showIcon: true
142
+ }), /*#__PURE__*/React.createElement(Form.Item, {
143
+ style: {
144
+ textAlign: 'right'
145
+ }
146
+ }, /*#__PURE__*/React.createElement(Button, {
147
+ htmlType: "button",
148
+ type: "text",
149
+ size: "small",
150
+ onClick: onCancel,
151
+ style: {
152
+ marginRight: 8
153
+ }
154
+ }, formatMessage({
155
+ id: '取消'
156
+ })), /*#__PURE__*/React.createElement(Button, {
157
+ type: "primary",
158
+ htmlType: "submit",
159
+ size: "small"
160
+ }, formatMessage({
161
+ id: '提交'
162
+ }))))));
163
+ };
@@ -4,12 +4,12 @@ import { useIntl } from 'dumi';
4
4
  import React from 'react';
5
5
  import { styled } from 'styled-components';
6
6
  import { useSnapshot } from 'valtio';
7
- import { feedbackStore, invokePageFeedback } from "../../model/feedback";
7
+ import { feedbackStore, invokePageFeedback, resetPageFeedback } from "../../model/feedback";
8
8
  var StyledVoteButtonsWrapper = styled.div.withConfig({
9
9
  displayName: "StyledVoteButtonsWrapper",
10
- componentId: "dumi-theme-antv-c7ef__sc-1dcmgu-0"
11
- })(["color:rgba(0,0,0,0.65);display:flex;align-items:center;gap:4px;.button{color:rgba(0,0,0,0.8);}.active-button{color:#873bf4;background-color:#f8f1ff;}"]);
12
- export var VoteButtons = function VoteButtons() {
10
+ componentId: "dumi-theme-antv-c7ef__sc-1x5fro0-0"
11
+ })(["color:rgba(0,0,0,0.65);display:flex;align-items:center;gap:4px;font-weight:500;.button{color:rgba(0,0,0,0.65);}.active-button{color:#873bf4;background-color:#f8f1ff;}"]);
12
+ export var PageFeedbackVoteButtons = function PageFeedbackVoteButtons() {
13
13
  var _useIntl = useIntl(),
14
14
  formatMessage = _useIntl.formatMessage;
15
15
  var feedbackState = useSnapshot(feedbackStore);
@@ -19,7 +19,11 @@ export var VoteButtons = function VoteButtons() {
19
19
  }),
20
20
  icon: /*#__PURE__*/React.createElement(LikeFilled, null),
21
21
  onClick: function onClick() {
22
- return invokePageFeedback(true);
22
+ if (feedbackState.rating === '1') {
23
+ resetPageFeedback();
24
+ } else {
25
+ invokePageFeedback(true);
26
+ }
23
27
  },
24
28
  isActive: feedbackState.rating === '1'
25
29
  }, {
@@ -28,12 +32,16 @@ export var VoteButtons = function VoteButtons() {
28
32
  }),
29
33
  icon: /*#__PURE__*/React.createElement(DislikeFilled, null),
30
34
  onClick: function onClick() {
31
- return invokePageFeedback(false);
35
+ if (feedbackState.rating === '0') {
36
+ resetPageFeedback();
37
+ } else {
38
+ invokePageFeedback(false);
39
+ }
32
40
  },
33
41
  isActive: feedbackState.rating === '0'
34
42
  }];
35
43
  return /*#__PURE__*/React.createElement(StyledVoteButtonsWrapper, null, /*#__PURE__*/React.createElement("span", null, formatMessage({
36
- id: '此文档有帮助吗?'
44
+ id: '这个页面对你有帮助吗?'
37
45
  })), items.map(function (_ref) {
38
46
  var title = _ref.title,
39
47
  icon = _ref.icon,
@@ -0,0 +1,97 @@
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, { useEffect, useState } from 'react';
8
+ import { useLocation } from 'react-router-dom';
9
+ import { styled } from 'styled-components';
10
+ import { useSnapshot } from 'valtio';
11
+ import { feedbackStore, invokeSectionFeedback, resetSectionFeedback } from "../../model/feedback";
12
+ import { SectionFeedbackCommentForm } from "./SectionFeedbackCommentForm";
13
+ var StyledWrapper = styled.div.withConfig({
14
+ displayName: "StyledWrapper",
15
+ componentId: "dumi-theme-antv-c7ef__sc-vcamqv-0"
16
+ })(["background-color:#fff;border-radius:12px;box-shadow:0 0.5rem 1.2rem #f0f1f2;transition:height 0.3s ease-in-out;width:262px;position:fixed;z-index:1001;padding:10px 18px;border-radius:8px;transition:top 0.3s ease-in-out,right 0.3s ease-in-out;"]);
17
+ export var SectionFeedback = function SectionFeedback() {
18
+ var feedbackState = useSnapshot(feedbackStore);
19
+ var location = useLocation();
20
+ useEffect(function () {
21
+ var observer = new MutationObserver(function () {
22
+ var buttons = document.querySelectorAll('.comment-link');
23
+ if (!buttons || buttons.length === 0) return;
24
+ var focusCommentInput = function focusCommentInput(e) {
25
+ var button = e.target.closest('.comment-link');
26
+ invokeSectionFeedback(button.getAttribute('data-feedback-hash'));
27
+ };
28
+ buttons.forEach(function (button) {
29
+ button.addEventListener('click', focusCommentInput);
30
+ });
31
+ return function () {
32
+ buttons.forEach(function (button) {
33
+ button.removeEventListener('click', focusCommentInput);
34
+ });
35
+ };
36
+ });
37
+ observer.observe(document.body, {
38
+ childList: true,
39
+ subtree: true
40
+ });
41
+ return function () {
42
+ observer.disconnect();
43
+ };
44
+ }, []);
45
+ var _useState = useState({
46
+ top: 0,
47
+ right: 12
48
+ }),
49
+ _useState2 = _slicedToArray(_useState, 2),
50
+ position = _useState2[0],
51
+ setPosition = _useState2[1];
52
+ useEffect(function () {
53
+ var handleClick = function handleClick(e) {
54
+ var target = e.target;
55
+ var closestCommentLink = target.closest('.comment-link');
56
+ if (!feedbackState.section || !closestCommentLink) return;
57
+ var escapedSection = CSS.escape(feedbackState.section);
58
+ var elements = document.querySelectorAll(".comment-link[data-feedback-hash=".concat(escapedSection, "]"));
59
+ var closestElement = findClosetElement(e, elements);
60
+ if (closestElement) {
61
+ var rect = closestElement.getBoundingClientRect();
62
+ var top = Math.min(Math.max(rect.top, 0), window.innerHeight - 380);
63
+ setPosition({
64
+ top: top,
65
+ right: 12
66
+ });
67
+ }
68
+ };
69
+ window.addEventListener('click', handleClick);
70
+ return function () {
71
+ window.removeEventListener('click', handleClick);
72
+ };
73
+ }, [feedbackState.section]);
74
+ useEffect(function () {
75
+ resetSectionFeedback();
76
+ }, [location.pathname]);
77
+ if (!feedbackState.section) return null;
78
+ return /*#__PURE__*/React.createElement(StyledWrapper, {
79
+ style: {
80
+ top: position.top,
81
+ right: position.right
82
+ }
83
+ }, /*#__PURE__*/React.createElement(SectionFeedbackCommentForm, null));
84
+ };
85
+ var findClosetElement = function findClosetElement(e, elements) {
86
+ var closestElement = null;
87
+ var closestDistance = Infinity;
88
+ elements.forEach(function (element) {
89
+ var rect = element.getBoundingClientRect();
90
+ var distance = Math.sqrt(Math.pow(rect.left + rect.width / 2 - e.clientX, 2) + Math.pow(rect.top + rect.height / 2 - e.clientY, 2));
91
+ if (distance < closestDistance) {
92
+ closestDistance = distance;
93
+ closestElement = element;
94
+ }
95
+ });
96
+ return closestElement;
97
+ };
@@ -0,0 +1,84 @@
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 { Button, Form, Input } from 'antd';
8
+ import { useIntl, useLocale } from 'dumi';
9
+ import React from 'react';
10
+ import { styled } from 'styled-components';
11
+ import { useSnapshot } from 'valtio';
12
+ import { feedbackStore, resetSectionFeedback } from "../../model/feedback";
13
+ import { useFeedbackService } from "./service";
14
+ var StyledForm = styled(Form).withConfig({
15
+ displayName: "StyledForm",
16
+ componentId: "dumi-theme-antv-c7ef__sc-1e7udwn-0"
17
+ })([".ant-form-item:last-child{margin-bottom:8px;}"]);
18
+ export var SectionFeedbackCommentForm = function SectionFeedbackCommentForm() {
19
+ var _useIntl = useIntl(),
20
+ formatMessage = _useIntl.formatMessage;
21
+ var _Form$useForm = Form.useForm(),
22
+ _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
23
+ form = _Form$useForm2[0];
24
+ var feedbackState = useSnapshot(feedbackStore);
25
+ var locale = useLocale();
26
+ var currentLocale = locale.id;
27
+ var onCancel = function onCancel() {
28
+ form.resetFields();
29
+ resetSectionFeedback();
30
+ };
31
+ var _useFeedbackService = useFeedbackService(),
32
+ submitFeedback = _useFeedbackService.submitFeedback,
33
+ showFeedbackResult = _useFeedbackService.showFeedbackResult;
34
+ var onFinish = function onFinish(values) {
35
+ submitFeedback({
36
+ comment: values.comment
37
+ }).then(function () {
38
+ onCancel();
39
+ showFeedbackResult(true);
40
+ }).catch(function () {
41
+ showFeedbackResult(false);
42
+ });
43
+ };
44
+ var getCommentFieldLabel = function getCommentFieldLabel() {
45
+ var leftQuote = currentLocale === 'zh' ? '「' : '"';
46
+ var rightQuote = currentLocale === 'zh' ? '」' : '"';
47
+ return /*#__PURE__*/React.createElement("div", null, formatMessage({
48
+ id: '📖 你认为'
49
+ }), ' ', /*#__PURE__*/React.createElement("b", null, leftQuote, feedbackState.section, rightQuote), ' ', formatMessage({
50
+ id: '部分如何改进更好?'
51
+ }));
52
+ };
53
+ return /*#__PURE__*/React.createElement(StyledForm, {
54
+ name: "section-feedback-form",
55
+ form: form,
56
+ layout: "vertical",
57
+ onFinish: onFinish
58
+ }, /*#__PURE__*/React.createElement(Form.Item, {
59
+ name: "comment",
60
+ label: getCommentFieldLabel()
61
+ }, /*#__PURE__*/React.createElement(Input.TextArea, {
62
+ rows: 3
63
+ })), /*#__PURE__*/React.createElement(Form.Item, {
64
+ style: {
65
+ textAlign: 'right'
66
+ }
67
+ }, /*#__PURE__*/React.createElement(Button, {
68
+ htmlType: "button",
69
+ type: "text",
70
+ size: "small",
71
+ onClick: onCancel,
72
+ style: {
73
+ marginRight: 8
74
+ }
75
+ }, formatMessage({
76
+ id: '取消'
77
+ })), /*#__PURE__*/React.createElement(Button, {
78
+ type: "primary",
79
+ htmlType: "submit",
80
+ size: "small"
81
+ }, formatMessage({
82
+ id: '提交'
83
+ }))));
84
+ };
@@ -3,24 +3,20 @@ import React from 'react';
3
3
  import { styled } from 'styled-components';
4
4
  import { Contributors } from "./Contributors";
5
5
  import { EditButton } from "./EditButton";
6
- import { FeedbackMessage } from "./FeedbackMessage";
7
- import { VoteButtons } from "./VoteButtons";
6
+ import { PageFeedback } from "./PageFeedback";
7
+ import { SectionFeedback } from "./SectionFeedback";
8
8
  var StyledWrapper = styled.div.withConfig({
9
9
  displayName: "StyledWrapper",
10
10
  componentId: "dumi-theme-antv-c7ef__sc-yubwx0-0"
11
- })(["margin-top:40px;.buttons{display:flex;justify-content:space-between;}"]);
11
+ })(["margin-top:40px;"]);
12
12
  export var Feedback = function Feedback() {
13
13
  var meta = useRouteMeta();
14
- if (meta.frontmatter.readonly) {
15
- return null;
16
- }
17
- return /*#__PURE__*/React.createElement(StyledWrapper, null, /*#__PURE__*/React.createElement("div", {
18
- className: "buttons"
19
- }, /*#__PURE__*/React.createElement(EditButton, {
14
+ var editable = !meta.frontmatter.readonly;
15
+ return /*#__PURE__*/React.createElement(StyledWrapper, null, editable && /*#__PURE__*/React.createElement(EditButton, {
20
16
  style: {
21
17
  transform: 'translateX(-12px)'
22
18
  }
23
- }), /*#__PURE__*/React.createElement(VoteButtons, null)), /*#__PURE__*/React.createElement(FeedbackMessage, null), /*#__PURE__*/React.createElement(Contributors, {
19
+ }), editable && /*#__PURE__*/React.createElement(Contributors, {
24
20
  filename: meta.frontmatter.filename
25
- }));
21
+ }), /*#__PURE__*/React.createElement(SectionFeedback, null), /*#__PURE__*/React.createElement(PageFeedback, null));
26
22
  };
@@ -1,27 +1,75 @@
1
+ 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); }
1
2
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
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."); }
3
4
  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
5
  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
6
  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
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
13
  /**
8
14
  * 服务模块
9
15
  * https://docs.leancloud.cn/sdk/storage/guide/js/
10
16
  */
17
+ import { MehOutlined, SmileOutlined } from '@ant-design/icons';
18
+ import { notification } from 'antd';
19
+ import { useIntl, useLocale, useRouteMeta, useSiteData } from 'dumi';
11
20
  import AV from 'leancloud-storage';
21
+ import React from 'react';
22
+ import { useGithubRepo } from "../../utils/github";
12
23
  AV.init({
13
- appId: 'iHqYaIUSgLOlOTkQxnqicMax-gzGzoHsz',
14
- appKey: 'fyjYpAT54tFGui2Vn6CYDMaf',
15
- serverURL: 'https://ihqyaius.lc-cn-n1-shared.com'
24
+ appId: 'mAckVaWaCleA1L1tRu0vDkkl-gzGzoHsz',
25
+ appKey: '5BCFPGawWnS37eHVnzSptNa5',
26
+ serverURL: 'https://mackvawa.lc-cn-n1-shared.com'
16
27
  });
17
- export function submitFeedback(params) {
28
+ export var useFeedbackService = function useFeedbackService() {
29
+ var _useIntl = useIntl(),
30
+ formatMessage = _useIntl.formatMessage;
31
+ var _useGithubRepo = useGithubRepo(),
32
+ owner = _useGithubRepo.owner,
33
+ repo = _useGithubRepo.repo;
34
+ var meta = useRouteMeta();
35
+ var version = useSiteData().themeConfig.version;
36
+ var locale = useLocale().id;
37
+ var commonParams = {
38
+ locale: locale,
39
+ repo: "".concat(owner, "/").concat(repo),
40
+ ua: navigator.userAgent,
41
+ url: window.location.href,
42
+ userId: 'anonymous',
43
+ version: version,
44
+ title: meta.frontmatter.title
45
+ };
18
46
  var Feedback = AV.Object.extend('UserFeedback');
19
- var f = new Feedback();
20
- Object.entries(params).forEach(function (_ref) {
21
- var _ref2 = _slicedToArray(_ref, 2),
22
- key = _ref2[0],
23
- value = _ref2[1];
24
- f.set(key, value);
25
- });
26
- return f.save();
27
- }
47
+ var submitFeedback = function submitFeedback(params) {
48
+ var f = new Feedback();
49
+ Object.entries(_objectSpread(_objectSpread({}, commonParams), params)).forEach(function (_ref) {
50
+ var _ref2 = _slicedToArray(_ref, 2),
51
+ key = _ref2[0],
52
+ value = _ref2[1];
53
+ f.set(key, value);
54
+ });
55
+ return f.save();
56
+ };
57
+ var showFeedbackResult = function showFeedbackResult(success) {
58
+ var Icon = success ? SmileOutlined : MehOutlined;
59
+ notification.info({
60
+ message: formatMessage({
61
+ id: success ? '谢谢你的反馈意见!' : '报错了,请稍后再试'
62
+ }),
63
+ icon: /*#__PURE__*/React.createElement(Icon, {
64
+ style: {
65
+ color: '#873bf4'
66
+ }
67
+ }),
68
+ placement: 'bottomRight'
69
+ });
70
+ };
71
+ return {
72
+ submitFeedback: submitFeedback,
73
+ showFeedbackResult: showFeedbackResult
74
+ };
75
+ };
@@ -46,7 +46,8 @@ export var Main = function Main(_ref) {
46
46
  className: styles.markdown
47
47
  }, children), /*#__PURE__*/React.createElement(Feedback, null), /*#__PURE__*/React.createElement(PrevAndNext, null)), /*#__PURE__*/React.createElement(BackTop, {
48
48
  style: {
49
- right: 32
49
+ right: 32,
50
+ bottom: 100
50
51
  }
51
52
  }, /*#__PURE__*/React.createElement("div", {
52
53
  className: styles.backTop
package/dist/slots/_.less CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  .ant-btn,
6
6
  .ant-input,
7
- .ant-notification-notice {
7
+ .ant-notification-notice,
8
+ .ant-select-selector {
8
9
  border-radius: 8px !important;
9
10
  }
10
11
 
@@ -22,6 +23,36 @@
22
23
  }
23
24
  }
24
25
 
26
+ h1,
27
+ h2,
28
+ h3,
29
+ h4,
30
+ h5,
31
+ h6 {
32
+ > a[aria-hidden]:first-child {
33
+ float: left;
34
+ width: 20px;
35
+ font-size: 0;
36
+ line-height: inherit;
37
+ text-align: right;
38
+ padding-inline-end: 6px;
39
+ margin-inline-start: -20px;
40
+
41
+ &:hover {
42
+ border: 0;
43
+ }
44
+
45
+ > .icon-link::before {
46
+ font-size: 20px;
47
+ content: '#';
48
+ }
49
+ }
50
+
51
+ &:not(:hover) > a[aria-hidden]:first-child > .icon-link {
52
+ visibility: hidden;
53
+ }
54
+ }
55
+
25
56
  .container1440() {
26
57
  width: 1440px;
27
58
  max-width: calc(100% - 80px);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.5.7-beta.0",
3
+ "version": "0.5.7-beta.1",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "keywords": [
6
6
  "dumi",
@@ -1,234 +0,0 @@
1
- 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); }
2
- 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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
- 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); } }
4
- 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); }); }; }
5
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
- 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."); }
7
- 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); }
8
- 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; }
9
- 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; } }
10
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- import { MehOutlined, SmileOutlined } from '@ant-design/icons';
12
- import { Alert, Button, Divider, Form, Input, notification, Switch } from 'antd';
13
- import { useIntl, useLocale, useRouteMeta } from 'dumi';
14
- import React, { useEffect, useState } from 'react';
15
- import { Link } from 'react-router-dom';
16
- import { styled } from 'styled-components';
17
- import useSWR from 'swr';
18
- import { useSnapshot } from 'valtio';
19
- import { feedbackStore, invokeSectionFeedback, resetFeedbackState } from "../../model/feedback";
20
- import { getLatestVersion, useGithubRepo } from "../../utils/github";
21
- import { submitFeedback } from "./service";
22
- var StyledFeedbackMessageWrapper = styled.div.withConfig({
23
- displayName: "StyledFeedbackMessageWrapper",
24
- componentId: "dumi-theme-antv-c7ef__sc-3o22sl-0"
25
- })(["display:", ";.alert{margin:12px 0 16px;padding:16px;line-height:1.8;background-color:rgba(255,251,235,0.5);border:1px solid rgba(173,104,0,0.15);border-radius:8px;.ant-alert-icon{color:#cc8800;}}.alert-link{color:#56390c;font-weight:bold;text-decoration:underline;}"], function (props) {
26
- return props.$show ? 'block' : 'none';
27
- });
28
- export var FeedbackMessage = function FeedbackMessage() {
29
- var _useIntl = useIntl(),
30
- formatMessage = _useIntl.formatMessage;
31
- var _Form$useForm = Form.useForm(),
32
- _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
33
- form = _Form$useForm2[0];
34
- var feedbackState = useSnapshot(feedbackStore);
35
- var _useGithubRepo = useGithubRepo(),
36
- owner = _useGithubRepo.owner,
37
- repo = _useGithubRepo.repo;
38
- var meta = useRouteMeta();
39
- var _useState = useState(false),
40
- _useState2 = _slicedToArray(_useState, 2),
41
- enableRealName = _useState2[0],
42
- setEnableRealName = _useState2[1];
43
- var pageUrl = window.location.href;
44
- var locale = useLocale();
45
- var currentLocale = locale.id;
46
- var issueUrl = "https://github.com/".concat(owner, "/").concat(repo, "/issues/new?labels=status%3A+waiting+for+maintainer%2Cdocs-feedback&template=docs-feedback.yml&title=[docs]+&page-url=").concat(pageUrl);
47
- var alertMsg = /*#__PURE__*/React.createElement("div", null, formatMessage({
48
- id: '如果遇到问题或发现某些功能无法正常工作,请通过'
49
- }), /*#__PURE__*/React.createElement(Link, {
50
- to: issueUrl,
51
- className: "alert-link"
52
- }, formatMessage({
53
- id: '提交问题报告'
54
- })), formatMessage({
55
- id: '来反馈。否则,团队将无法提供进一步的答复或获取更多信息。'
56
- }));
57
- var openNotification = function openNotification(success) {
58
- notification.info({
59
- message: formatMessage({
60
- id: success ? '反馈已提交' : '报错了,请稍后再试'
61
- }),
62
- description: formatMessage({
63
- id: success ? '我们会尽快处理你的反馈,感谢你的支持!' : '如果问题持续,请前往 GitHub 提交 issue。'
64
- }),
65
- icon: success ? /*#__PURE__*/React.createElement(SmileOutlined, {
66
- style: {
67
- color: '#873bf4'
68
- }
69
- }) : /*#__PURE__*/React.createElement(MehOutlined, {
70
- style: {
71
- color: '#873bf4'
72
- }
73
- }),
74
- placement: 'bottomLeft'
75
- });
76
- };
77
- var _useSWR = useSWR("https://api.github.com/repos/".concat(owner, "/").concat(repo, "/releases/latest"), function () {
78
- return getLatestVersion(owner, repo);
79
- }),
80
- lastVersion = _useSWR.data;
81
- var onFinish = /*#__PURE__*/function () {
82
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(values) {
83
- var params;
84
- return _regeneratorRuntime().wrap(function _callee$(_context) {
85
- while (1) switch (_context.prev = _context.next) {
86
- case 0:
87
- params = {
88
- comment: values.comment,
89
- locale: currentLocale,
90
- url: pageUrl,
91
- rating: feedbackState.rating,
92
- repo: "".concat(owner, "/").concat(repo),
93
- section: feedbackState.section,
94
- ua: navigator.userAgent,
95
- userId: enableRealName ? values.userId : 'anonymous',
96
- version: lastVersion,
97
- title: meta.frontmatter.title
98
- };
99
- submitFeedback(params).then(function (f) {
100
- form.setFieldValue('comment', '');
101
- openNotification(true);
102
- }).catch(function () {
103
- openNotification(false);
104
- });
105
- case 2:
106
- case "end":
107
- return _context.stop();
108
- }
109
- }, _callee);
110
- }));
111
- return function onFinish(_x) {
112
- return _ref.apply(this, arguments);
113
- };
114
- }();
115
- var onCancel = function onCancel() {
116
- resetFeedbackState();
117
- };
118
- useEffect(function () {
119
- var observer = new MutationObserver(function () {
120
- var buttons = document.querySelectorAll('.comment-link');
121
- if (!buttons || buttons.length === 0) return;
122
- var focusCommentInput = function focusCommentInput(e) {
123
- var button = e.target.closest('.comment-link');
124
- invokeSectionFeedback(button.getAttribute('data-feedback-hash'));
125
- };
126
- buttons.forEach(function (button) {
127
- button.addEventListener('click', focusCommentInput);
128
- });
129
- return function () {
130
- buttons.forEach(function (button) {
131
- button.removeEventListener('click', focusCommentInput);
132
- });
133
- };
134
- });
135
- observer.observe(document.body, {
136
- childList: true,
137
- subtree: true
138
- });
139
- return function () {
140
- observer.disconnect();
141
- };
142
- }, []);
143
- useEffect(function () {
144
- if (!feedbackState.show) {
145
- form.setFieldValue('comment', '');
146
- setEnableRealName(false);
147
- }
148
- }, [feedbackState.show]);
149
- useEffect(function () {
150
- if (feedbackState.section) {
151
- form.scrollToField('comment', {
152
- behavior: 'smooth',
153
- block: 'center'
154
- });
155
- }
156
- }, [feedbackState.section]);
157
- var showAlert = feedbackState.rating !== '1';
158
- var getCommentFieldLabel = function getCommentFieldLabel() {
159
- if (feedbackState.rating === '1') {
160
- return formatMessage({
161
- id: '你认为这个页面有哪些做的好的地方?(可选)'
162
- });
163
- } else if (feedbackState.rating === '0') {
164
- return formatMessage({
165
- id: '你觉得我们可以如何改进此页面?(可选)'
166
- });
167
- } else {
168
- var leftQuote = currentLocale === 'zh' ? '「' : '"';
169
- var rightQuote = currentLocale === 'zh' ? '」' : '"';
170
- return /*#__PURE__*/React.createElement("div", null, formatMessage({
171
- id: '你认为该'
172
- }), ' ', /*#__PURE__*/React.createElement("b", null, leftQuote, feedbackState.section, rightQuote), ' ', formatMessage({
173
- id: '部分如何改进更好?(可选)'
174
- }));
175
- }
176
- };
177
- return /*#__PURE__*/React.createElement(StyledFeedbackMessageWrapper, {
178
- $show: feedbackState.show
179
- }, /*#__PURE__*/React.createElement(Divider, {
180
- dashed: true
181
- }), /*#__PURE__*/React.createElement("div", {
182
- className: "form"
183
- }, /*#__PURE__*/React.createElement(Form, {
184
- form: form,
185
- name: "comment",
186
- onFinish: onFinish,
187
- layout: "vertical"
188
- }, /*#__PURE__*/React.createElement(Switch, {
189
- checkedChildren: "\u5B9E\u540D",
190
- unCheckedChildren: "\u533F\u540D",
191
- checked: enableRealName,
192
- onChange: setEnableRealName,
193
- style: {
194
- marginBottom: 16
195
- }
196
- }), enableRealName && /*#__PURE__*/React.createElement(Form.Item, {
197
- name: "userId",
198
- label: formatMessage({
199
- id: 'Github ID'
200
- })
201
- }, /*#__PURE__*/React.createElement(Input, {
202
- style: {
203
- width: '220px'
204
- }
205
- })), /*#__PURE__*/React.createElement(Form.Item, {
206
- name: "comment",
207
- label: getCommentFieldLabel()
208
- }, /*#__PURE__*/React.createElement(Input.TextArea, {
209
- rows: 5
210
- })), showAlert && /*#__PURE__*/React.createElement(Alert, {
211
- type: "warning",
212
- className: "alert",
213
- message: alertMsg,
214
- showIcon: true
215
- }), /*#__PURE__*/React.createElement(Form.Item, {
216
- style: {
217
- textAlign: 'right'
218
- }
219
- }, /*#__PURE__*/React.createElement(Button, {
220
- htmlType: "button",
221
- type: "text",
222
- onClick: onCancel,
223
- style: {
224
- marginRight: 8
225
- }
226
- }, formatMessage({
227
- id: '取消'
228
- })), /*#__PURE__*/React.createElement(Button, {
229
- type: "primary",
230
- htmlType: "submit"
231
- }, formatMessage({
232
- id: '提交'
233
- }))))));
234
- };