x-star-design 0.0.52 → 0.0.54

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.
@@ -1,7 +1,4 @@
1
1
  import React from 'react';
2
- interface Props {
3
- onReset?: () => void;
4
- homeLink?: string;
5
- }
6
- declare const ErrorPage: ({ onReset, homeLink }: Props) => React.JSX.Element;
2
+ import type { FallbackProps } from 'react-error-boundary';
3
+ declare const ErrorPage: ({ error, resetErrorBoundary }: FallbackProps) => React.JSX.Element;
7
4
  export default ErrorPage;
@@ -2,40 +2,54 @@ import classNames from 'classnames';
2
2
  import React from 'react';
3
3
  import { useLocale } from "../../locales";
4
4
  import { prefix } from "../../utils/global";
5
+ var isFetchError = function isFetchError(error) {
6
+ var _error$message;
7
+ return (_error$message = error.message) === null || _error$message === void 0 ? void 0 : _error$message.includes('Failed to fetch dynamically imported module:');
8
+ };
5
9
  var ErrorPage = function ErrorPage(_ref) {
6
- var onReset = _ref.onReset,
7
- homeLink = _ref.homeLink;
10
+ var error = _ref.error,
11
+ resetErrorBoundary = _ref.resetErrorBoundary;
8
12
  var _useLocale = useLocale('ErrorPage'),
9
13
  t = _useLocale.format;
14
+ if (isFetchError(error)) {
15
+ location.reload();
16
+ }
10
17
  return /*#__PURE__*/React.createElement("div", {
11
- className: classNames("".concat(prefix, "-errorPage")),
12
- "data-testid": 'errorPage'
18
+ className: classNames("".concat(prefix, "-errorPage"))
13
19
  }, /*#__PURE__*/React.createElement("div", {
14
- className: classNames("hello")
20
+ className: classNames('hello')
15
21
  }), /*#__PURE__*/React.createElement("div", {
16
- className: classNames("ip")
22
+ className: classNames('ip')
17
23
  }), /*#__PURE__*/React.createElement("div", {
18
- className: classNames("planets")
24
+ className: classNames('planets')
19
25
  }), /*#__PURE__*/React.createElement("div", {
20
- className: classNames("content")
21
- }, /*#__PURE__*/React.createElement("div", {
22
- className: classNames("alert")
26
+ className: classNames('content')
27
+ }, isFetchError(error) ? /*#__PURE__*/React.createElement("div", {
28
+ "data-testid": "hint",
29
+ className: classNames('hint')
23
30
  }, /*#__PURE__*/React.createElement("div", {
24
- className: classNames("alertContent")
31
+ className: classNames('description')
32
+ }, /*#__PURE__*/React.createElement("div", null, t('RELOAD_HINT')))) : /*#__PURE__*/React.createElement("div", {
33
+ "data-testid": "alert",
34
+ className: classNames('alert')
25
35
  }, /*#__PURE__*/React.createElement("h2", {
26
36
  style: {
27
37
  fontWeight: 'bold'
28
38
  }
29
39
  }, t('ERROR')), /*#__PURE__*/React.createElement("div", {
30
- className: classNames("description")
40
+ className: classNames('description')
31
41
  }, /*#__PURE__*/React.createElement("div", null, t('ERROR_BOUNDARY_TIP_1')), /*#__PURE__*/React.createElement("div", null, t('ERROR_BOUNDARY_TIP_2')), /*#__PURE__*/React.createElement("div", {
32
- className: classNames("actions")
42
+ className: classNames('actions')
33
43
  }, /*#__PURE__*/React.createElement("a", {
34
- href: homeLink || '/'
44
+ href: "/"
35
45
  }, ">> ".concat(t('RETURN_TO_HOME'))), /*#__PURE__*/React.createElement("a", {
36
- onClick: onReset
46
+ onClick: resetErrorBoundary
37
47
  }, ">> ".concat(t('RETRY')))), /*#__PURE__*/React.createElement("div", null, t('TECHNICAL_DEPARTMENT_CONTACT_EMAIL'), /*#__PURE__*/React.createElement("a", {
38
48
  href: "mailto:tech@xinyoudui.com"
39
- }, 'tech@xinyoudui.com')))))));
49
+ }, "tech@xinyoudui.com")), /*#__PURE__*/React.createElement("div", {
50
+ style: {
51
+ color: 'red'
52
+ }
53
+ }, t('ERROR_MESSAGE'), error.message)))));
40
54
  };
41
55
  export default ErrorPage;
@@ -1,30 +1,4 @@
1
1
  import React from 'react';
2
- type FallbackElement = React.ReactElement<unknown, string | React.FC | typeof React.Component> | null;
3
- export interface FallbackProps {
4
- error: Error;
5
- resetErrorBoundary: () => void;
6
- }
7
- interface ErrorBoundaryState {
8
- error: Error | null;
9
- }
10
- export declare function FallbackRender(props: FallbackProps): FallbackElement;
11
- interface ErrorBoundaryProps {
12
- fallback?: FallbackElement;
13
- fallbackRender?: typeof FallbackRender;
14
- onError?: (error: Error, info: string) => void;
15
- onReset?: () => void;
16
- homeLink?: string;
17
- }
18
- /**
19
- * 错误边界捕获
20
- */
21
- declare class ErrorBoundary extends React.Component<React.PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> {
22
- state: ErrorBoundaryState;
23
- updatedWithError: boolean;
24
- componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
25
- componentDidUpdate(): void;
26
- reset: () => void;
27
- resetErrorBoundary: () => void;
28
- render(): string | number | boolean | React.JSX.Element | Iterable<React.ReactNode> | null | undefined;
29
- }
2
+ import type { ErrorBoundaryProps as ReactErrorBoundaryProps } from 'react-error-boundary';
3
+ declare const ErrorBoundary: ({ fallback, fallbackRender, FallbackComponent, ...rest }: Partial<ReactErrorBoundaryProps>) => React.JSX.Element;
30
4
  export default ErrorBoundary;
@@ -1,145 +1,22 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/esm/inherits";
5
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
- // 本组件代码参考自 https://juejin.cn/post/6937474904375689224
8
- import { message } from 'antd';
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["fallback", "fallbackRender", "FallbackComponent"];
9
4
  import React from 'react';
5
+ import { ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary';
10
6
  import ErrorPage from "./error-page";
11
-
12
- // 出错后显示的元素类型
13
-
14
- // 出错显示组件的 props
15
-
16
- // 本组件 ErrorBoundary 的 props
17
-
18
- // 初始状态
19
- var initialState = {
20
- error: null
7
+ var ErrorBoundary = function ErrorBoundary(_ref) {
8
+ var fallback = _ref.fallback,
9
+ fallbackRender = _ref.fallbackRender,
10
+ _ref$FallbackComponen = _ref.FallbackComponent,
11
+ FallbackComponent = _ref$FallbackComponen === void 0 ? ErrorPage : _ref$FallbackComponen,
12
+ rest = _objectWithoutProperties(_ref, _excluded);
13
+ var props = fallback !== undefined ? _objectSpread({
14
+ fallback: fallback
15
+ }, rest) : fallbackRender !== undefined ? _objectSpread({
16
+ fallbackRender: fallbackRender
17
+ }, rest) : _objectSpread({
18
+ FallbackComponent: FallbackComponent
19
+ }, rest);
20
+ return /*#__PURE__*/React.createElement(ReactErrorBoundary, props);
21
21
  };
22
-
23
- // 本组件 ErrorBoundary 的 props
24
- /**
25
- * 错误边界捕获
26
- */
27
- var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
28
- _inherits(ErrorBoundary, _React$Component);
29
- var _super = _createSuper(ErrorBoundary);
30
- function ErrorBoundary() {
31
- var _this;
32
- _classCallCheck(this, ErrorBoundary);
33
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
34
- args[_key] = arguments[_key];
35
- }
36
- _this = _super.call.apply(_super, [this].concat(args));
37
- _defineProperty(_assertThisInitialized(_this), "state", initialState);
38
- // 是否已经由于 error 而引发的 render/update
39
- _defineProperty(_assertThisInitialized(_this), "updatedWithError", false);
40
- // 重置该组件状态,将 error 设置 null
41
- _defineProperty(_assertThisInitialized(_this), "reset", function () {
42
- _this.updatedWithError = false;
43
- _this.setState(initialState);
44
- });
45
- // 执行自定义重置逻辑,并重置组件状态
46
- _defineProperty(_assertThisInitialized(_this), "resetErrorBoundary", function () {
47
- var _this$props$onReset = _this.props.onReset,
48
- onReset = _this$props$onReset === void 0 ? function () {
49
- message.info('开发人员正在解救陷入黑洞的代码,请耐心等待和尝试。Developers are rescuing code trapped in a black hole. Please be patient and try again');
50
- } : _this$props$onReset;
51
- onReset();
52
- _this.reset();
53
- });
54
- return _this;
55
- }
56
- _createClass(ErrorBoundary, [{
57
- key: "componentDidCatch",
58
- value: function componentDidCatch(error, errorInfo) {
59
- if (this.props.onError) {
60
- this.props.onError(error, errorInfo.componentStack);
61
- } else {
62
- console.error('Page Crash! Have been captured by error boundary.');
63
- }
64
- this.setState({
65
- error: error
66
- });
67
- }
68
- }, {
69
- key: "componentDidUpdate",
70
- value: function componentDidUpdate() {
71
- var error = this.state.error;
72
-
73
- // 已经存在错误,并且是第一次由于 error 而引发的 render/update,那么设置 flag=true,不会重置
74
- if (error !== null && !this.updatedWithError) {
75
- this.updatedWithError = true;
76
- return;
77
- }
78
- }
79
- }, {
80
- key: "render",
81
- value: function render() {
82
- var _this2 = this;
83
- var _this$props = this.props,
84
- fallback = _this$props.fallback,
85
- _this$props$fallbackR = _this$props.fallbackRender,
86
- fallbackRender = _this$props$fallbackR === void 0 ? function (props) {
87
- // fallback 组件的渲染函数 ErrorPage需要自己定义该组件
88
- return /*#__PURE__*/React.createElement(ErrorPage, {
89
- onReset: props.resetErrorBoundary,
90
- homeLink: _this2.props.homeLink
91
- });
92
- } : _this$props$fallbackR;
93
- var error = this.state.error;
94
- if (error !== null) {
95
- var fallbackProps = {
96
- error: error,
97
- resetErrorBoundary: this.resetErrorBoundary // 将 resetErrorBoundary 传入 fallback
98
- };
99
-
100
- if ( /*#__PURE__*/React.isValidElement(fallback)) {
101
- return fallback;
102
- }
103
- return fallbackRender(fallbackProps);
104
- }
105
- return this.props.children;
106
- }
107
- }]);
108
- return ErrorBoundary;
109
- }(React.Component);
110
- export default ErrorBoundary;
111
-
112
- // [example for ErrorBoundary]
113
- {
114
- /*
115
- const onError = () => console.error('页面崩溃');
116
- const onReset = () => {
117
- console.log('已重置');
118
- message.info('刚刚出错了,不好意思,现在已经重置好了,请找老板锤这个开发');
119
- };
120
- const renderFallback = (props: FallbackProps) => {
121
- // fallback 组件的渲染函数
122
- return (
123
- <Alert
124
- className={styles.alert}
125
- message="出错啦"
126
- showIcon
127
- description="不好意思,页面因为一些原因崩溃了,您可以尝试重置"
128
- type="error"
129
- action={
130
- <Button size="small" danger onClick={props.resetErrorBoundary}>
131
- {'重置'}
132
- </Button>
133
- }
134
- />
135
- );
136
- };
137
- <ErrorBoundary
138
- fallbackRender={renderFallback}
139
- onError={onError}
140
- onReset={onReset}
141
- >
142
- <Routes />
143
- </ErrorBoundary>;
144
- */
145
- }
22
+ export default ErrorBoundary;
@@ -3,7 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import { CoffeeOutlined, DislikeFilled, DislikeOutlined, LikeFilled, LikeOutlined } from '@ant-design/icons';
4
4
  import { Button, Checkbox, Col, Form, Input, Popover, Radio, Row, Space, Typography } from 'antd';
5
5
  import classNames from 'classnames';
6
- import React, { useRef, useState } from 'react';
6
+ import React, { useEffect, useRef, useState } from 'react';
7
7
  import ConfigProviderWrapper from "../config-provider-wrapper";
8
8
  import { useLocale } from "../locales";
9
9
  import { prefix } from "../utils/global";
@@ -43,6 +43,9 @@ var Feedback = function Feedback(_ref) {
43
43
  return feedbackListBad;
44
44
  }
45
45
  };
46
+ useEffect(function () {
47
+ form.setFieldsValue(_defineProperty({}, "".concat(feedbackTypeKey), undefined));
48
+ }, [choiceType]);
46
49
  var submittedContent = function submittedContent() {
47
50
  return /*#__PURE__*/React.createElement(Space, {
48
51
  direction: "vertical",
@@ -151,9 +154,6 @@ var Feedback = function Feedback(_ref) {
151
154
  }))))), /*#__PURE__*/React.createElement(Form.Item, {
152
155
  name: feedbackTextAreaKey,
153
156
  rules: [{
154
- required: true,
155
- message: t('FEEDBACK_MESSAGE_3')
156
- }, {
157
157
  validator: function validator(_, value) {
158
158
  //空格字符串校验
159
159
  if (/^\s+$/g.test(value)) {
@@ -196,6 +196,7 @@ var Feedback = function Feedback(_ref) {
196
196
  content: content,
197
197
  title: title !== null && title !== void 0 ? title : t('FEEDBACK_ON_THE_PROBLEM'),
198
198
  placement: "bottom",
199
+ forceRender: true,
199
200
  trigger: ['click'],
200
201
  getPopupContainer: function getPopupContainer() {
201
202
  return mainContainer.current;
@@ -207,6 +208,7 @@ var Feedback = function Feedback(_ref) {
207
208
  setOpen(true);
208
209
  } else {
209
210
  form.resetFields();
211
+ setChoiceType(undefined);
210
212
  setOpen(false);
211
213
  }
212
214
  },
@@ -55,12 +55,14 @@ declare const _default: {
55
55
  readonly CONTACT_US: "Contact Us";
56
56
  };
57
57
  readonly ErrorPage: {
58
- readonly ERROR: " Error";
58
+ readonly RELOAD_HINT: "Page update detected, reloading the page...";
59
+ readonly ERROR: "💔 Error";
59
60
  readonly ERROR_BOUNDARY_TIP_1: "Sorry, the code accidentally got caught in a black hole and the page crashed.";
60
61
  readonly ERROR_BOUNDARY_TIP_2: "You can try accessing the page again, or you can visit another page first.";
61
62
  readonly RETURN_TO_HOME: "Return to home";
62
63
  readonly RETRY: "Retry";
63
64
  readonly TECHNICAL_DEPARTMENT_CONTACT_EMAIL: "Technical department contact email: ";
65
+ readonly ERROR_MESSAGE: "Error message: ";
64
66
  };
65
67
  readonly Feedback: {
66
68
  readonly FEEDBACK_RESPONSE: "Thank you for your valuable comments, we will continue to improve~";
@@ -55,12 +55,14 @@ export default {
55
55
  CONTACT_US: 'Contact Us'
56
56
  },
57
57
  ErrorPage: {
58
- ERROR: ' Error',
58
+ RELOAD_HINT: 'Page update detected, reloading the page...',
59
+ ERROR: '💔 Error',
59
60
  ERROR_BOUNDARY_TIP_1: 'Sorry, the code accidentally got caught in a black hole and the page crashed.',
60
61
  ERROR_BOUNDARY_TIP_2: 'You can try accessing the page again, or you can visit another page first.',
61
62
  RETURN_TO_HOME: 'Return to home',
62
63
  RETRY: 'Retry',
63
- TECHNICAL_DEPARTMENT_CONTACT_EMAIL: 'Technical department contact email: '
64
+ TECHNICAL_DEPARTMENT_CONTACT_EMAIL: 'Technical department contact email: ',
65
+ ERROR_MESSAGE: 'Error message: '
64
66
  },
65
67
  Feedback: {
66
68
  FEEDBACK_RESPONSE: 'Thank you for your valuable comments, we will continue to improve~',
@@ -66,12 +66,14 @@ export declare const useLocale: <T extends "VisualDataConfig" | "TranslateButton
66
66
  readonly CONTACT_US: "联系我们";
67
67
  };
68
68
  readonly ErrorPage: {
69
- readonly ERROR: "☹ 出错啦";
69
+ readonly RELOAD_HINT: "监测到页面更新,正在刷新页面...";
70
+ readonly ERROR: "💔 出错啦";
70
71
  readonly ERROR_BOUNDARY_TIP_1: "不好意思,代码意外卷入了黑洞,页面发生了崩溃。";
71
72
  readonly ERROR_BOUNDARY_TIP_2: "您可以重试访问该页面,或可以先访问其他页面。";
72
73
  readonly RETURN_TO_HOME: "回到首页";
73
74
  readonly RETRY: "重试";
74
75
  readonly TECHNICAL_DEPARTMENT_CONTACT_EMAIL: "技术部联系邮箱:";
76
+ readonly ERROR_MESSAGE: "错误信息:";
75
77
  };
76
78
  readonly Feedback: {
77
79
  readonly FEEDBACK_RESPONSE: "感谢您宝贵的意见,我们会持续改进~";
@@ -143,12 +145,14 @@ export declare const useLocale: <T extends "VisualDataConfig" | "TranslateButton
143
145
  readonly CONTACT_US: "Contact Us";
144
146
  };
145
147
  readonly ErrorPage: {
146
- readonly ERROR: " Error";
148
+ readonly RELOAD_HINT: "Page update detected, reloading the page...";
149
+ readonly ERROR: "💔 Error";
147
150
  readonly ERROR_BOUNDARY_TIP_1: "Sorry, the code accidentally got caught in a black hole and the page crashed.";
148
151
  readonly ERROR_BOUNDARY_TIP_2: "You can try accessing the page again, or you can visit another page first.";
149
152
  readonly RETURN_TO_HOME: "Return to home";
150
153
  readonly RETRY: "Retry";
151
154
  readonly TECHNICAL_DEPARTMENT_CONTACT_EMAIL: "Technical department contact email: ";
155
+ readonly ERROR_MESSAGE: "Error message: ";
152
156
  };
153
157
  readonly Feedback: {
154
158
  readonly FEEDBACK_RESPONSE: "Thank you for your valuable comments, we will continue to improve~";
@@ -55,12 +55,14 @@ declare const _default: {
55
55
  readonly CONTACT_US: "联系我们";
56
56
  };
57
57
  readonly ErrorPage: {
58
- readonly ERROR: "☹ 出错啦";
58
+ readonly RELOAD_HINT: "监测到页面更新,正在刷新页面...";
59
+ readonly ERROR: "💔 出错啦";
59
60
  readonly ERROR_BOUNDARY_TIP_1: "不好意思,代码意外卷入了黑洞,页面发生了崩溃。";
60
61
  readonly ERROR_BOUNDARY_TIP_2: "您可以重试访问该页面,或可以先访问其他页面。";
61
62
  readonly RETURN_TO_HOME: "回到首页";
62
63
  readonly RETRY: "重试";
63
64
  readonly TECHNICAL_DEPARTMENT_CONTACT_EMAIL: "技术部联系邮箱:";
65
+ readonly ERROR_MESSAGE: "错误信息:";
64
66
  };
65
67
  readonly Feedback: {
66
68
  readonly FEEDBACK_RESPONSE: "感谢您宝贵的意见,我们会持续改进~";
@@ -55,12 +55,14 @@ export default {
55
55
  CONTACT_US: '联系我们'
56
56
  },
57
57
  ErrorPage: {
58
- ERROR: '☹ 出错啦',
58
+ RELOAD_HINT: '监测到页面更新,正在刷新页面...',
59
+ ERROR: '💔 出错啦',
59
60
  ERROR_BOUNDARY_TIP_1: '不好意思,代码意外卷入了黑洞,页面发生了崩溃。',
60
61
  ERROR_BOUNDARY_TIP_2: '您可以重试访问该页面,或可以先访问其他页面。',
61
62
  RETURN_TO_HOME: '回到首页',
62
63
  RETRY: '重试',
63
- TECHNICAL_DEPARTMENT_CONTACT_EMAIL: '技术部联系邮箱:'
64
+ TECHNICAL_DEPARTMENT_CONTACT_EMAIL: '技术部联系邮箱:',
65
+ ERROR_MESSAGE: '错误信息:'
64
66
  },
65
67
  Feedback: {
66
68
  FEEDBACK_RESPONSE: '感谢您宝贵的意见,我们会持续改进~',
@@ -118,40 +118,39 @@
118
118
  position: absolute;
119
119
  top: 50%;
120
120
  left: 50%;
121
- display: flex;
122
- justify-content: space-around;
123
- align-items: center;
124
121
  color: rgba(0, 0, 0, 0.88);
125
122
  transform: translate(-50%, -50%);
126
- flex-direction: column;
127
123
  }
124
+ .x-star-design-errorPage .content .hint,
128
125
  .x-star-design-errorPage .content .alert {
129
126
  position: relative;
130
- display: flex;
131
- align-items: flex-start;
132
127
  margin: 0;
133
128
  padding: 8px 12px;
134
- border: 1px solid #ffccc7;
135
129
  border-radius: 8px;
136
130
  font-size: 16px;
137
131
  color: rgba(0, 0, 0, 0.88);
138
- background-color: #fff2f0;
139
132
  padding-inline: 24px;
140
133
  padding-block: 20px;
141
134
  box-sizing: border-box;
142
135
  }
143
- .x-star-design-errorPage .content .alert .description {
144
- display: flex;
145
- flex-direction: column;
146
- }
136
+ .x-star-design-errorPage .content .hint .description div,
147
137
  .x-star-design-errorPage .content .alert .description div {
148
138
  line-height: 2.5rem;
149
139
  }
140
+ .x-star-design-errorPage .content .hint .description .actions,
150
141
  .x-star-design-errorPage .content .alert .description .actions {
151
142
  display: flex;
152
143
  justify-content: space-between;
153
144
  width: 50%;
154
145
  }
146
+ .x-star-design-errorPage .content .hint {
147
+ border: 1px solid #ccffc7;
148
+ background-color: #f2fff0;
149
+ }
150
+ .x-star-design-errorPage .content .alert {
151
+ border: 1px solid #ffccc7;
152
+ background-color: #fff2f0;
153
+ }
155
154
  .x-star-design-errorPage .content a {
156
155
  color: #1890ff;
157
156
  text-decoration: none;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-star-design",
3
- "version": "0.0.52",
3
+ "version": "0.0.54",
4
4
  "description": "A react component library developed by turingstar",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -62,6 +62,7 @@
62
62
  "dayjs": "^1.11.10",
63
63
  "randomcolor": "^0.6.2",
64
64
  "rc-resize-observer": "^1.3.1",
65
+ "react-error-boundary": "^4.0.13",
65
66
  "react-sortable-hoc": "^2.0.0",
66
67
  "react-window": "^1.8.9",
67
68
  "x-star-utils": "^0.0.9"