@zohodesk/i18n 1.0.0-beta.4 → 1.0.0-beta.41-murphy
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.
- package/README.md +130 -4
- package/docs/murphy/01-MURPHY_OVERVIEW.md +148 -0
- package/docs/murphy/02-MURPHY_ARCHITECTURE.md +283 -0
- package/docs/murphy/03-MURPHY_BACKEND_CONFIG.md +337 -0
- package/docs/murphy/04-MURPHY_FRONTEND_INIT.md +437 -0
- package/docs/murphy/05-MURPHY_DESK_CLIENT_USAGE.md +467 -0
- package/docs/murphy/06-MURPHY_I18N_INTEGRATION.md +402 -0
- package/docs/murphy/07-MURPHY_WHY_I18N_APPROACH.md +391 -0
- package/es/I18NContext.js +1 -2
- package/es/components/DateTimeDiffFormat.js +185 -209
- package/es/components/FormatText.js +7 -27
- package/es/components/HOCI18N.js +35 -58
- package/es/components/I18N.js +48 -74
- package/es/components/I18NProvider.js +59 -93
- package/es/components/PluralFormat.js +28 -51
- package/es/components/UserTimeDiffFormat.js +66 -81
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +810 -663
- package/es/components/__tests__/FormatText.spec.js +22 -19
- package/es/components/__tests__/HOCI18N.spec.js +19 -25
- package/es/components/__tests__/I18N.spec.js +23 -21
- package/es/components/__tests__/I18NProvider.spec.js +38 -47
- package/es/components/__tests__/PluralFormat.spec.js +23 -20
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +1259 -1110
- package/es/index.js +13 -15
- package/es/utils/__tests__/jsxTranslations.spec.js +170 -0
- package/es/utils/errorReporter.js +41 -0
- package/es/utils/index.js +543 -0
- package/es/utils/jsxTranslations.js +185 -0
- package/lib/I18NContext.js +5 -10
- package/lib/components/DateTimeDiffFormat.js +131 -146
- package/lib/components/FormatText.js +29 -42
- package/lib/components/HOCI18N.js +34 -45
- package/lib/components/I18N.js +46 -57
- package/lib/components/I18NProvider.js +72 -95
- package/lib/components/PluralFormat.js +39 -55
- package/lib/components/UserTimeDiffFormat.js +76 -84
- package/lib/components/__tests__/DateTimeDiffFormat.spec.js +751 -635
- package/lib/components/__tests__/FormatText.spec.js +21 -30
- package/lib/components/__tests__/HOCI18N.spec.js +22 -41
- package/lib/components/__tests__/I18N.spec.js +20 -33
- package/lib/components/__tests__/I18NProvider.spec.js +40 -63
- package/lib/components/__tests__/PluralFormat.spec.js +23 -35
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1195 -1046
- package/lib/index.js +83 -104
- package/lib/utils/__tests__/jsxTranslations.spec.js +172 -0
- package/lib/utils/errorReporter.js +49 -0
- package/lib/utils/index.js +583 -0
- package/lib/utils/jsxTranslations.js +216 -0
- package/package.json +4 -3
- package/src/components/DateTimeDiffFormat.js +84 -55
- package/src/components/I18N.js +2 -0
- package/src/components/I18NProvider.js +44 -33
- package/src/components/UserTimeDiffFormat.js +22 -18
- package/src/index.js +12 -9
- package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
- package/src/utils/errorReporter.js +48 -0
- package/src/utils/index.js +644 -0
- package/src/utils/jsxTranslations.js +199 -0
- package/es/components/NewDateFormat.js +0 -50
- package/es/offset.js +0 -629
- package/es/timezones.js +0 -118
- package/es/utils.js +0 -621
- package/lib/components/NewDateFormat.js +0 -68
- package/lib/offset.js +0 -634
- package/lib/timezones.js +0 -129
- package/lib/utils.js +0 -651
- package/src/components/NewDateFormat.js +0 -60
- package/src/offset.js +0 -629
- package/src/timezones.js +0 -113
- package/src/utils.js +0 -648
package/es/components/I18N.js
CHANGED
|
@@ -1,89 +1,63 @@
|
|
|
1
|
-
import _Object$assign from 'babel-runtime/core-js/object/assign';
|
|
2
|
-
import _Object$keys from 'babel-runtime/core-js/object/keys';
|
|
3
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
4
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
5
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
6
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
7
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
8
1
|
import React, { Children } from 'react';
|
|
9
2
|
import PropTypes from 'prop-types';
|
|
10
|
-
import { replaceI18NValuesWithRegex, unescapeUnicode } from
|
|
3
|
+
import { replaceI18NValuesWithRegex, unescapeUnicode } from "../utils";
|
|
11
4
|
import { HTMLPurifier } from '@zoho/SecurityJS';
|
|
12
|
-
import { I18NContext } from
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
_classCallCheck(this, I18N);
|
|
19
|
-
|
|
20
|
-
var _this = _possibleConstructorReturn(this, (I18N.__proto__ || _Object$getPrototypeOf(I18N)).call(this, props));
|
|
21
|
-
|
|
22
|
-
_this.getI18NValue = _this.getI18NValue.bind(_this);
|
|
23
|
-
_this.createElement = _this.createElement.bind(_this);
|
|
24
|
-
return _this;
|
|
5
|
+
import { I18NContext } from "../I18NContext";
|
|
6
|
+
export default class I18N extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.getI18NValue = this.getI18NValue.bind(this);
|
|
10
|
+
this.createElement = this.createElement.bind(this);
|
|
25
11
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (typeof i18n === 'undefined') {
|
|
38
|
-
return key;
|
|
39
|
-
}
|
|
40
|
-
var i18nStr = i18n[key];
|
|
41
|
-
if (i18nStr === undefined) {
|
|
42
|
-
return key;
|
|
43
|
-
}
|
|
44
|
-
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
45
|
-
return unescapeUnicode(i18nStr);
|
|
12
|
+
getI18NValue() {
|
|
13
|
+
const {
|
|
14
|
+
i18NKey: key,
|
|
15
|
+
values
|
|
16
|
+
} = this.props;
|
|
17
|
+
const {
|
|
18
|
+
i18n
|
|
19
|
+
} = this.context || {};
|
|
20
|
+
if (typeof i18n === 'undefined') {
|
|
21
|
+
return key;
|
|
46
22
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//const child=this.getI18NValue();
|
|
59
|
-
if (this.props.dataId) {
|
|
60
|
-
props['data-id'] = this.props.dataId;
|
|
61
|
-
}
|
|
62
|
-
if (this.props.isHtml) {
|
|
63
|
-
var dangerouslySetInnerHTML = {
|
|
64
|
-
__html: HTMLPurifier.sanitize(this.getI18NValue())
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
return React.createElement(this.props.tag, _Object$assign(props, { dangerouslySetInnerHTML: dangerouslySetInnerHTML }));
|
|
23
|
+
let i18nStr = i18n[key];
|
|
24
|
+
if (i18nStr === undefined) {
|
|
25
|
+
return key;
|
|
26
|
+
}
|
|
27
|
+
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
28
|
+
return unescapeUnicode(i18nStr);
|
|
29
|
+
}
|
|
30
|
+
createElement() {
|
|
31
|
+
const props = Object.keys(this.props).reduce((result, nextKey) => {
|
|
32
|
+
if (nextKey != 'i18NKey' && nextKey != 'tag' && nextKey != 'values' && nextKey != 'isHtml' && nextKey != 'dataId') {
|
|
33
|
+
result[nextKey] = this.props[nextKey];
|
|
68
34
|
}
|
|
69
|
-
return
|
|
35
|
+
return result;
|
|
36
|
+
}, {});
|
|
37
|
+
//const child=this.getI18NValue();
|
|
38
|
+
if (this.props.dataId) {
|
|
39
|
+
props['data-id'] = this.props.dataId;
|
|
40
|
+
props['data-test-id'] = this.props.dataId;
|
|
70
41
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
42
|
+
if (this.props.isHtml) {
|
|
43
|
+
let dangerouslySetInnerHTML = {
|
|
44
|
+
__html: HTMLPurifier.sanitize(this.getI18NValue())
|
|
45
|
+
};
|
|
46
|
+
return /*#__PURE__*/React.createElement(this.props.tag, Object.assign(props, {
|
|
47
|
+
dangerouslySetInnerHTML
|
|
48
|
+
}));
|
|
75
49
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
50
|
+
return /*#__PURE__*/React.createElement(this.props.tag, props, this.getI18NValue());
|
|
51
|
+
}
|
|
52
|
+
render() {
|
|
53
|
+
return this.createElement();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
83
56
|
I18N.propTypes = {
|
|
84
57
|
i18NKey: PropTypes.string.isRequired,
|
|
85
58
|
isHtml: PropTypes.bool,
|
|
86
59
|
tag: PropTypes.string,
|
|
60
|
+
dataId: PropTypes.string,
|
|
87
61
|
values: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
|
|
88
62
|
};
|
|
89
63
|
I18N.defaultProps = {
|
|
@@ -1,116 +1,82 @@
|
|
|
1
|
-
import _Promise from 'babel-runtime/core-js/promise';
|
|
2
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
3
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
4
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
5
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
6
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
7
1
|
import React from 'react';
|
|
8
2
|
import PropTypes from 'prop-types';
|
|
9
|
-
import { getI18NValue, userDateFormat } from
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var dummy = function dummy(key, values) {
|
|
16
|
-
return key;
|
|
17
|
-
};
|
|
18
|
-
var getTzData = createSelector([function (tzStr) {
|
|
19
|
-
return tzStr;
|
|
20
|
-
}], function (tzStr) {
|
|
21
|
-
return unpack(tzStr);
|
|
22
|
-
});
|
|
23
|
-
export var i18NProviderUtils = {
|
|
3
|
+
import { getI18NValue, userDateFormat } from "../utils";
|
|
4
|
+
import { getI18NComponent } from "../utils/jsxTranslations";
|
|
5
|
+
import { I18NContext } from "../I18NContext";
|
|
6
|
+
const emptyObj = {};
|
|
7
|
+
const dummy = (key, values) => key;
|
|
8
|
+
export const i18NProviderUtils = {
|
|
24
9
|
getI18NValue: dummy,
|
|
25
|
-
userDateFormat: dummy
|
|
10
|
+
userDateFormat: dummy,
|
|
11
|
+
getI18NComponent: dummy
|
|
26
12
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
function I18NProvider(props, context) {
|
|
32
|
-
_classCallCheck(this, I18NProvider);
|
|
33
|
-
|
|
34
|
-
var _this = _possibleConstructorReturn(this, (I18NProvider.__proto__ || _Object$getPrototypeOf(I18NProvider)).call(this, props, context));
|
|
35
|
-
|
|
13
|
+
export default class I18NProvider extends React.Component {
|
|
14
|
+
constructor(props, context) {
|
|
15
|
+
super(props, context);
|
|
36
16
|
i18NProviderUtils.getI18NValue = getI18NValue(props.i18n);
|
|
37
|
-
i18NProviderUtils.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
_createClass(I18NProvider, [{
|
|
42
|
-
key: 'componentDidUpdate',
|
|
43
|
-
value: function componentDidUpdate(next) {
|
|
44
|
-
var _this2 = this;
|
|
45
|
-
|
|
46
|
-
var _props = this.props,
|
|
47
|
-
i18n = _props.i18n,
|
|
48
|
-
timeZone = _props.timeZone,
|
|
49
|
-
datePattern = _props.datePattern,
|
|
50
|
-
timeFormat = _props.timeFormat,
|
|
51
|
-
dateTimeFormat = _props.dateTimeFormat,
|
|
52
|
-
direction = _props.direction,
|
|
53
|
-
onChange = _props.onChange,
|
|
54
|
-
tzData = _props.tzData;
|
|
55
|
-
|
|
56
|
-
if (i18n !== next.i18n || timeZone !== next.timeZone || datePattern !== next.datePattern || timeFormat !== next.timeFormat || dateTimeFormat !== next.dateTimeFormat || direction !== next.direction || tzData !== next.tzData) {
|
|
57
|
-
this.promise = new _Promise(function (res, rej) {
|
|
58
|
-
_this2.resolve = res;
|
|
59
|
-
_this2.reject = rej;
|
|
60
|
-
}).then(function () {
|
|
61
|
-
i18NProviderUtils.getI18NValue = getI18NValue(nextProps.i18n);
|
|
62
|
-
i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, unpack(tzData));
|
|
63
|
-
_this2.promise = null;
|
|
64
|
-
}, function () {
|
|
65
|
-
_this2.promise = null;
|
|
66
|
-
});
|
|
67
|
-
onChange && onChange(this.resolve, this.reject);
|
|
68
|
-
}
|
|
17
|
+
i18NProviderUtils.getI18NComponent = getI18NComponent(props.i18n);
|
|
18
|
+
if (props.tzData) {
|
|
19
|
+
i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, props.isEnabledCurrentYear);
|
|
69
20
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
21
|
+
}
|
|
22
|
+
componentDidUpdate(prevProps) {
|
|
23
|
+
let {
|
|
24
|
+
i18n,
|
|
25
|
+
timeZone,
|
|
26
|
+
datePattern,
|
|
27
|
+
timeFormat,
|
|
28
|
+
direction,
|
|
29
|
+
onChange,
|
|
30
|
+
tzData,
|
|
31
|
+
isEnabledCurrentYear
|
|
32
|
+
} = this.props;
|
|
33
|
+
if (i18n !== prevProps.i18n || timeZone !== prevProps.timeZone || datePattern !== prevProps.datePattern || timeFormat !== prevProps.timeFormat || direction !== prevProps.direction || tzData !== prevProps.tzData || isEnabledCurrentYear !== prevProps.isEnabledCurrentYear) {
|
|
34
|
+
this.promise = new Promise((res, rej) => {
|
|
35
|
+
this.resolve = res;
|
|
36
|
+
this.reject = rej;
|
|
37
|
+
}).then(() => {
|
|
38
|
+
i18NProviderUtils.getI18NValue = getI18NValue(this.props.i18n);
|
|
39
|
+
i18NProviderUtils.getI18NComponent = getI18NComponent(this.props.i18n);
|
|
40
|
+
if (this.props.tzData) {
|
|
41
|
+
i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, this.props.tzData, this.props.timeFormat, this.props.datePattern, this.props.isEnabledCurrentYear);
|
|
42
|
+
}
|
|
43
|
+
this.promise = null;
|
|
44
|
+
}, () => {
|
|
45
|
+
this.promise = null;
|
|
46
|
+
});
|
|
47
|
+
onChange && onChange(this.resolve, this.reject);
|
|
88
48
|
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
49
|
+
}
|
|
50
|
+
render() {
|
|
51
|
+
return /*#__PURE__*/React.createElement(I18NContext.Provider, {
|
|
52
|
+
value: {
|
|
53
|
+
i18n: this.props.i18n,
|
|
54
|
+
direction: this.props.direction,
|
|
55
|
+
timeZone: this.props.timeZone,
|
|
56
|
+
datePattern: this.props.datePattern,
|
|
57
|
+
timeFormat: this.props.timeFormat,
|
|
58
|
+
isEnabledCurrentYear: this.props.isEnabledCurrentYear,
|
|
59
|
+
tzData: this.props.tzData
|
|
60
|
+
}
|
|
61
|
+
}, this.props.children);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
97
64
|
I18NProvider.defaultProps = {
|
|
98
65
|
i18n: emptyObj,
|
|
99
66
|
timeZone: '',
|
|
100
67
|
datePattern: '',
|
|
101
68
|
timeFormat: '',
|
|
102
|
-
|
|
69
|
+
isEnabledCurrentYear: '',
|
|
103
70
|
direction: 'ltr'
|
|
104
71
|
};
|
|
105
|
-
|
|
106
72
|
I18NProvider.propTypes = {
|
|
107
73
|
children: PropTypes.element.isRequired,
|
|
108
74
|
datePattern: PropTypes.string,
|
|
109
|
-
|
|
75
|
+
isEnabledCurrentYear: PropTypes.string,
|
|
110
76
|
direction: PropTypes.string,
|
|
111
77
|
i18n: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
|
112
78
|
onChange: PropTypes.func,
|
|
113
79
|
timeFormat: PropTypes.string,
|
|
114
80
|
timeZone: PropTypes.string,
|
|
115
|
-
tzData: PropTypes.
|
|
81
|
+
tzData: PropTypes.object
|
|
116
82
|
};
|
|
@@ -1,57 +1,34 @@
|
|
|
1
|
-
import _extends from 'babel-runtime/helpers/extends';
|
|
2
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
3
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
4
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
5
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
6
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
7
1
|
import React from 'react';
|
|
8
2
|
import PropTypes from 'prop-types';
|
|
9
|
-
import FormatText from
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
value
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
zero = _props.zero,
|
|
27
|
-
value = _props.value;
|
|
28
|
-
|
|
29
|
-
var key = '',
|
|
30
|
-
values = '';
|
|
31
|
-
if (value > 1) {
|
|
32
|
-
key = many;
|
|
33
|
-
} else if (value == 1) {
|
|
34
|
-
key = one;
|
|
35
|
-
} else if (value == 0) {
|
|
36
|
-
key = zero;
|
|
37
|
-
}
|
|
38
|
-
values = '' + value;
|
|
39
|
-
|
|
40
|
-
return React.createElement(FormatText, _extends({}, this.props, {
|
|
41
|
-
i18NKey: key,
|
|
42
|
-
values: values,
|
|
43
|
-
one: null,
|
|
44
|
-
many: null,
|
|
45
|
-
zero: null
|
|
46
|
-
}));
|
|
3
|
+
import FormatText from "./FormatText";
|
|
4
|
+
export default class PluralFormat extends React.Component {
|
|
5
|
+
render() {
|
|
6
|
+
const {
|
|
7
|
+
one,
|
|
8
|
+
many,
|
|
9
|
+
zero,
|
|
10
|
+
value
|
|
11
|
+
} = this.props;
|
|
12
|
+
let key = '',
|
|
13
|
+
values = '';
|
|
14
|
+
if (value > 1) {
|
|
15
|
+
key = many;
|
|
16
|
+
} else if (value == 1) {
|
|
17
|
+
key = one;
|
|
18
|
+
} else if (value == 0) {
|
|
19
|
+
key = zero;
|
|
47
20
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
21
|
+
values = `${value}`;
|
|
22
|
+
return /*#__PURE__*/React.createElement(FormatText, {
|
|
23
|
+
...this.props,
|
|
24
|
+
i18NKey: key,
|
|
25
|
+
values: values,
|
|
26
|
+
one: null,
|
|
27
|
+
many: null,
|
|
28
|
+
zero: null
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
55
32
|
PluralFormat.propTypes = {
|
|
56
33
|
many: PropTypes.string,
|
|
57
34
|
one: PropTypes.string,
|
|
@@ -1,93 +1,78 @@
|
|
|
1
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
2
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
3
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
4
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
5
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
6
1
|
import React, { Component } from 'react';
|
|
7
2
|
import PropTypes from 'prop-types';
|
|
8
|
-
import DateTimeDiffFormat from
|
|
9
|
-
import { I18NContext } from
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
timeZone = _ref.timeZone;
|
|
48
|
-
|
|
49
|
-
if (!format && !others) {
|
|
50
|
-
var pattern = displayType === 'date' ? datePattern : displayType === 'time' ? timeFormat : displayType === 'dateTime' ? dateTimeFormat : '';
|
|
51
|
-
format = function format() {
|
|
52
|
-
return pattern;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
var tz = tzData || timeZone;
|
|
57
|
-
|
|
58
|
-
return React.createElement(DateTimeDiffFormat, {
|
|
59
|
-
type: type,
|
|
60
|
-
page: page,
|
|
61
|
-
from: currentTimeUTCString,
|
|
62
|
-
fromTzData: tz,
|
|
63
|
-
to: to,
|
|
64
|
-
toTzData: tz,
|
|
65
|
-
today: today,
|
|
66
|
-
yesterday: yesterday,
|
|
67
|
-
tomorrow: tomorrow,
|
|
68
|
-
others: others,
|
|
69
|
-
ago: ago,
|
|
70
|
-
later: later,
|
|
71
|
-
format: format,
|
|
72
|
-
title: title,
|
|
73
|
-
className: className,
|
|
74
|
-
dataId: dataId,
|
|
75
|
-
isOverdue: isOverdue
|
|
76
|
-
});
|
|
3
|
+
import DateTimeDiffFormat from "./DateTimeDiffFormat";
|
|
4
|
+
import { I18NContext } from "../I18NContext";
|
|
5
|
+
export default class UserTimeDiffFormat extends Component {
|
|
6
|
+
render() {
|
|
7
|
+
let currentTime = new Date();
|
|
8
|
+
let currentTimeUTCString = currentTime.toISOString();
|
|
9
|
+
let {
|
|
10
|
+
type,
|
|
11
|
+
page,
|
|
12
|
+
isNeedTime,
|
|
13
|
+
to,
|
|
14
|
+
today,
|
|
15
|
+
yesterday,
|
|
16
|
+
tomorrow,
|
|
17
|
+
others,
|
|
18
|
+
ago,
|
|
19
|
+
later,
|
|
20
|
+
format,
|
|
21
|
+
title,
|
|
22
|
+
className,
|
|
23
|
+
displayType,
|
|
24
|
+
dataId,
|
|
25
|
+
isOverdue,
|
|
26
|
+
isDateField
|
|
27
|
+
} = this.props;
|
|
28
|
+
let {
|
|
29
|
+
tzData,
|
|
30
|
+
timeFormat,
|
|
31
|
+
datePattern,
|
|
32
|
+
isEnabledCurrentYear
|
|
33
|
+
} = this.context || {};
|
|
34
|
+
if (!format && !others) {
|
|
35
|
+
format = ({
|
|
36
|
+
dateTimeFormat,
|
|
37
|
+
dateFormat,
|
|
38
|
+
timeFormat
|
|
39
|
+
}) => {
|
|
40
|
+
displayType === 'dateTime' ? dateTimeFormat : displayType === 'date' ? dateFormat : timeFormat;
|
|
41
|
+
};
|
|
77
42
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
43
|
+
return /*#__PURE__*/React.createElement(DateTimeDiffFormat, {
|
|
44
|
+
type: type,
|
|
45
|
+
page: page,
|
|
46
|
+
isNeedTime: isNeedTime,
|
|
47
|
+
from: currentTimeUTCString,
|
|
48
|
+
fromTzData: tzData,
|
|
49
|
+
to: to,
|
|
50
|
+
toTzData: tzData,
|
|
51
|
+
today: today,
|
|
52
|
+
yesterday: yesterday,
|
|
53
|
+
tomorrow: tomorrow,
|
|
54
|
+
others: others,
|
|
55
|
+
ago: ago,
|
|
56
|
+
later: later,
|
|
57
|
+
format: format,
|
|
58
|
+
title: title,
|
|
59
|
+
className: className,
|
|
60
|
+
dataId: dataId,
|
|
61
|
+
isOverdue: isOverdue,
|
|
62
|
+
timeFormat: timeFormat,
|
|
63
|
+
datePattern: datePattern,
|
|
64
|
+
isEnabledCurrentYear: isEnabledCurrentYear,
|
|
65
|
+
isDateField: isDateField
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
85
69
|
UserTimeDiffFormat.propTypes = {
|
|
86
70
|
ago: PropTypes.string,
|
|
87
71
|
className: PropTypes.string,
|
|
88
72
|
dataId: PropTypes.string,
|
|
89
73
|
displayType: PropTypes.oneOf(['date', 'time', 'dateTime']),
|
|
90
74
|
format: PropTypes.func,
|
|
75
|
+
isDateField: PropTypes.bool,
|
|
91
76
|
later: PropTypes.string,
|
|
92
77
|
others: PropTypes.func,
|
|
93
78
|
title: PropTypes.string,
|