react-intl 8.0.10 → 8.1.0
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/index.d.ts +38 -34
- package/index.js +30 -21
- package/package.json +7 -7
- package/react-intl.iife.js +7317 -1963
- package/src/components/createFormattedComponent.d.ts +19 -19
- package/src/components/createFormattedComponent.js +53 -56
- package/src/components/createIntl.d.ts +7 -7
- package/src/components/createIntl.js +50 -52
- package/src/components/dateTimeRange.d.ts +5 -5
- package/src/components/dateTimeRange.js +13 -13
- package/src/components/injectIntl.d.ts +40 -29
- package/src/components/injectIntl.js +35 -31
- package/src/components/message.d.ts +7 -7
- package/src/components/message.js +26 -25
- package/src/components/plural.d.ts +10 -10
- package/src/components/plural.js +22 -15
- package/src/components/provider.d.ts +24 -25
- package/src/components/provider.js +51 -57
- package/src/components/relative.d.ts +6 -6
- package/src/components/relative.js +108 -114
- package/src/components/useIntl.d.ts +1 -1
- package/src/components/useIntl.js +7 -6
- package/src/types.d.ts +9 -9
- package/src/types.js +8 -1
- package/src/utils.d.ts +18 -18
- package/src/utils.js +60 -59
package/src/components/plural.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2015, Yahoo Inc.
|
|
3
|
+
* Copyrights licensed under the New BSD License.
|
|
4
|
+
* See the accompanying LICENSE file for terms.
|
|
5
|
+
*/
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import "@formatjs/intl";
|
|
8
|
+
import useIntl from "./useIntl.js";
|
|
1
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return formattedPlural;
|
|
10
|
+
const FormattedPlural = (props) => {
|
|
11
|
+
const { formatPlural, textComponent: Text } = useIntl();
|
|
12
|
+
const { value, other, children } = props;
|
|
13
|
+
const pluralCategory = formatPlural(value, props);
|
|
14
|
+
const formattedPlural = props[pluralCategory] || other;
|
|
15
|
+
if (typeof children === "function") {
|
|
16
|
+
return children(formattedPlural);
|
|
17
|
+
}
|
|
18
|
+
if (Text) {
|
|
19
|
+
return /* @__PURE__ */ _jsx(Text, { children: formattedPlural });
|
|
20
|
+
}
|
|
21
|
+
// Work around @types/react where React.FC cannot return string
|
|
22
|
+
return formattedPlural;
|
|
16
23
|
};
|
|
17
|
-
FormattedPlural.displayName =
|
|
24
|
+
FormattedPlural.displayName = "FormattedPlural";
|
|
18
25
|
export default FormattedPlural;
|
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
import { IntlCache } from
|
|
2
|
-
import * as React from
|
|
3
|
-
import type { IntlConfig, IntlShape } from
|
|
4
|
-
import { DefaultIntlConfig } from
|
|
1
|
+
import { type IntlCache } from "@formatjs/intl";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import type { IntlConfig, IntlShape } from "../types.js";
|
|
4
|
+
import { type DefaultIntlConfig } from "../utils.js";
|
|
5
5
|
interface State {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Explicit intl cache to prevent memory leaks
|
|
8
|
+
*/
|
|
9
|
+
cache: IntlCache;
|
|
10
|
+
/**
|
|
11
|
+
* Intl object we created
|
|
12
|
+
*/
|
|
13
|
+
intl?: IntlShape;
|
|
14
|
+
/**
|
|
15
|
+
* list of memoized config we care about.
|
|
16
|
+
* This is important since creating intl is
|
|
17
|
+
* very expensive
|
|
18
|
+
*/
|
|
19
|
+
prevConfig: IntlConfig;
|
|
20
20
|
}
|
|
21
21
|
export default class IntlProvider extends React.PureComponent<React.PropsWithChildren<IntlConfig>, State> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
static displayName: string;
|
|
23
|
+
static defaultProps: DefaultIntlConfig;
|
|
24
|
+
private cache;
|
|
25
|
+
state: State;
|
|
26
|
+
static getDerivedStateFromProps(props: Readonly<IntlConfig>, { prevConfig, cache }: State): Partial<State> | null;
|
|
27
|
+
render(): React.JSX.Element;
|
|
28
28
|
}
|
|
29
|
-
export {};
|
|
@@ -1,60 +1,54 @@
|
|
|
1
|
-
import { __extends } from "tslib";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
1
|
/*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { createIntlCache } from
|
|
9
|
-
import * as React from
|
|
10
|
-
import { DEFAULT_INTL_CONFIG, invariantIntlContext, shallowEqual
|
|
11
|
-
import { createIntl } from
|
|
12
|
-
import { Provider } from
|
|
2
|
+
* Copyright 2015, Yahoo Inc.
|
|
3
|
+
* Copyrights licensed under the New BSD License.
|
|
4
|
+
* See the accompanying LICENSE file for terms.
|
|
5
|
+
*/
|
|
6
|
+
import { createIntlCache } from "@formatjs/intl";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import { DEFAULT_INTL_CONFIG, invariantIntlContext, shallowEqual } from "../utils.js";
|
|
9
|
+
import { createIntl } from "./createIntl.js";
|
|
10
|
+
import { Provider } from "./injectIntl.js";
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
12
|
function processIntlConfig(config) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
return {
|
|
14
|
+
locale: config.locale,
|
|
15
|
+
timeZone: config.timeZone,
|
|
16
|
+
fallbackOnEmptyString: config.fallbackOnEmptyString,
|
|
17
|
+
formats: config.formats,
|
|
18
|
+
textComponent: config.textComponent,
|
|
19
|
+
messages: config.messages,
|
|
20
|
+
defaultLocale: config.defaultLocale,
|
|
21
|
+
defaultFormats: config.defaultFormats,
|
|
22
|
+
onError: config.onError,
|
|
23
|
+
onWarn: config.onWarn,
|
|
24
|
+
wrapRichTextChunksInFragment: config.wrapRichTextChunksInFragment,
|
|
25
|
+
defaultRichTextElements: config.defaultRichTextElements
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export default class IntlProvider extends React.PureComponent {
|
|
29
|
+
static displayName = "IntlProvider";
|
|
30
|
+
static defaultProps = DEFAULT_INTL_CONFIG;
|
|
31
|
+
cache = createIntlCache();
|
|
32
|
+
state = {
|
|
33
|
+
cache: this.cache,
|
|
34
|
+
intl: createIntl(processIntlConfig(this.props), this.cache),
|
|
35
|
+
prevConfig: processIntlConfig(this.props)
|
|
36
|
+
};
|
|
37
|
+
static getDerivedStateFromProps(props, { prevConfig, cache }) {
|
|
38
|
+
const config = processIntlConfig(props);
|
|
39
|
+
if (!shallowEqual(prevConfig, config)) {
|
|
40
|
+
return {
|
|
41
|
+
intl: createIntl(config, cache),
|
|
42
|
+
prevConfig: config
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
render() {
|
|
48
|
+
invariantIntlContext(this.state.intl);
|
|
49
|
+
return /* @__PURE__ */ _jsx(Provider, {
|
|
50
|
+
value: this.state.intl,
|
|
51
|
+
children: this.props.children
|
|
52
|
+
});
|
|
53
|
+
}
|
|
28
54
|
}
|
|
29
|
-
var IntlProvider = /** @class */ (function (_super) {
|
|
30
|
-
__extends(IntlProvider, _super);
|
|
31
|
-
function IntlProvider() {
|
|
32
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
33
|
-
_this.cache = createIntlCache();
|
|
34
|
-
_this.state = {
|
|
35
|
-
cache: _this.cache,
|
|
36
|
-
intl: createIntl(processIntlConfig(_this.props), _this.cache),
|
|
37
|
-
prevConfig: processIntlConfig(_this.props),
|
|
38
|
-
};
|
|
39
|
-
return _this;
|
|
40
|
-
}
|
|
41
|
-
IntlProvider.getDerivedStateFromProps = function (props, _a) {
|
|
42
|
-
var prevConfig = _a.prevConfig, cache = _a.cache;
|
|
43
|
-
var config = processIntlConfig(props);
|
|
44
|
-
if (!shallowEqual(prevConfig, config)) {
|
|
45
|
-
return {
|
|
46
|
-
intl: createIntl(config, cache),
|
|
47
|
-
prevConfig: config,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
};
|
|
52
|
-
IntlProvider.prototype.render = function () {
|
|
53
|
-
invariantIntlContext(this.state.intl);
|
|
54
|
-
return _jsx(Provider, { value: this.state.intl, children: this.props.children });
|
|
55
|
-
};
|
|
56
|
-
IntlProvider.displayName = 'IntlProvider';
|
|
57
|
-
IntlProvider.defaultProps = DEFAULT_INTL_CONFIG;
|
|
58
|
-
return IntlProvider;
|
|
59
|
-
}(React.PureComponent));
|
|
60
|
-
export default IntlProvider;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { FormatRelativeTimeOptions } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type FormatRelativeTimeOptions } from "@formatjs/intl";
|
|
3
3
|
export interface Props extends FormatRelativeTimeOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
value?: number;
|
|
5
|
+
unit?: Intl.RelativeTimeFormatUnit;
|
|
6
|
+
updateIntervalInSeconds?: number;
|
|
7
|
+
children?(value: string): React.ReactElement | null;
|
|
8
8
|
}
|
|
9
9
|
declare const FormattedRelativeTime: React.FC<Props>;
|
|
10
10
|
export default FormattedRelativeTime;
|
|
@@ -1,126 +1,120 @@
|
|
|
1
|
-
import { __assign, __rest } from "tslib";
|
|
2
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
1
|
/*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import * as React from
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
* Copyright 2015, Yahoo Inc.
|
|
3
|
+
* Copyrights licensed under the New BSD License.
|
|
4
|
+
* See the accompanying LICENSE file for terms.
|
|
5
|
+
*/
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import "@formatjs/intl";
|
|
8
|
+
import { invariant } from "../utils.js";
|
|
9
|
+
import useIntl from "./useIntl.js";
|
|
10
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
|
+
const MINUTE = 60;
|
|
12
|
+
const HOUR = 60 * 60;
|
|
13
|
+
const DAY = 60 * 60 * 24;
|
|
14
14
|
function selectUnit(seconds) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
const absValue = Math.abs(seconds);
|
|
16
|
+
if (absValue < MINUTE) {
|
|
17
|
+
return "second";
|
|
18
|
+
}
|
|
19
|
+
if (absValue < HOUR) {
|
|
20
|
+
return "minute";
|
|
21
|
+
}
|
|
22
|
+
if (absValue < DAY) {
|
|
23
|
+
return "hour";
|
|
24
|
+
}
|
|
25
|
+
return "day";
|
|
26
26
|
}
|
|
27
27
|
function getDurationInSeconds(unit) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return HOUR;
|
|
35
|
-
default:
|
|
36
|
-
return DAY;
|
|
37
|
-
}
|
|
28
|
+
switch (unit) {
|
|
29
|
+
case "second": return 1;
|
|
30
|
+
case "minute": return MINUTE;
|
|
31
|
+
case "hour": return HOUR;
|
|
32
|
+
default: return DAY;
|
|
33
|
+
}
|
|
38
34
|
}
|
|
39
35
|
function valueToSeconds(value, unit) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
default:
|
|
49
|
-
return value * HOUR;
|
|
50
|
-
}
|
|
36
|
+
if (!value) {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
switch (unit) {
|
|
40
|
+
case "second": return value;
|
|
41
|
+
case "minute": return value * MINUTE;
|
|
42
|
+
default: return value * HOUR;
|
|
43
|
+
}
|
|
51
44
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
const INCREMENTABLE_UNITS = [
|
|
46
|
+
"second",
|
|
47
|
+
"minute",
|
|
48
|
+
"hour"
|
|
56
49
|
];
|
|
57
|
-
function canIncrement(unit) {
|
|
58
|
-
|
|
59
|
-
return INCREMENTABLE_UNITS.indexOf(unit) > -1;
|
|
50
|
+
function canIncrement(unit = "second") {
|
|
51
|
+
return INCREMENTABLE_UNITS.indexOf(unit) > -1;
|
|
60
52
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
const SimpleFormattedRelativeTime = (props) => {
|
|
54
|
+
const { formatRelativeTime, textComponent: Text } = useIntl();
|
|
55
|
+
const { children, value, unit, ...otherProps } = props;
|
|
56
|
+
const formattedRelativeTime = formatRelativeTime(value || 0, unit, otherProps);
|
|
57
|
+
if (typeof children === "function") {
|
|
58
|
+
return children(formattedRelativeTime);
|
|
59
|
+
}
|
|
60
|
+
if (Text) {
|
|
61
|
+
return /* @__PURE__ */ _jsx(Text, { children: formattedRelativeTime });
|
|
62
|
+
}
|
|
63
|
+
return /* @__PURE__ */ _jsx(_Fragment, { children: formattedRelativeTime });
|
|
72
64
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
65
|
+
const FormattedRelativeTime = ({ value = 0, unit = "second", updateIntervalInSeconds, ...otherProps }) => {
|
|
66
|
+
invariant(!updateIntervalInSeconds || !!(updateIntervalInSeconds && canIncrement(unit)), "Cannot schedule update with unit longer than hour");
|
|
67
|
+
const [prevUnit, setPrevUnit] = React.useState();
|
|
68
|
+
const [prevValue, setPrevValue] = React.useState(0);
|
|
69
|
+
const [currentValueInSeconds, setCurrentValueInSeconds] = React.useState(0);
|
|
70
|
+
const updateTimer = React.useRef(undefined);
|
|
71
|
+
if (unit !== prevUnit || value !== prevValue) {
|
|
72
|
+
setPrevValue(value || 0);
|
|
73
|
+
setPrevUnit(unit);
|
|
74
|
+
setCurrentValueInSeconds(canIncrement(unit) ? valueToSeconds(value, unit) : 0);
|
|
75
|
+
}
|
|
76
|
+
React.useEffect(() => {
|
|
77
|
+
function clearUpdateTimer() {
|
|
78
|
+
clearTimeout(updateTimer.current);
|
|
79
|
+
}
|
|
80
|
+
clearUpdateTimer();
|
|
81
|
+
// If there's no interval and we cannot increment this unit, do nothing
|
|
82
|
+
if (!updateIntervalInSeconds || !canIncrement(unit)) {
|
|
83
|
+
return clearUpdateTimer;
|
|
84
|
+
}
|
|
85
|
+
// Figure out the next interesting time
|
|
86
|
+
const nextValueInSeconds = currentValueInSeconds - updateIntervalInSeconds;
|
|
87
|
+
const nextUnit = selectUnit(nextValueInSeconds);
|
|
88
|
+
// We've reached the max auto incrementable unit, don't schedule another update
|
|
89
|
+
if (nextUnit === "day") {
|
|
90
|
+
return clearUpdateTimer;
|
|
91
|
+
}
|
|
92
|
+
const unitDuration = getDurationInSeconds(nextUnit);
|
|
93
|
+
const remainder = nextValueInSeconds % unitDuration;
|
|
94
|
+
const prevInterestingValueInSeconds = nextValueInSeconds - remainder;
|
|
95
|
+
const nextInterestingValueInSeconds = prevInterestingValueInSeconds >= currentValueInSeconds ? prevInterestingValueInSeconds - unitDuration : prevInterestingValueInSeconds;
|
|
96
|
+
const delayInSeconds = Math.abs(nextInterestingValueInSeconds - currentValueInSeconds);
|
|
97
|
+
if (currentValueInSeconds !== nextInterestingValueInSeconds) {
|
|
98
|
+
updateTimer.current = setTimeout(() => setCurrentValueInSeconds(nextInterestingValueInSeconds), delayInSeconds * 1e3);
|
|
99
|
+
}
|
|
100
|
+
return clearUpdateTimer;
|
|
101
|
+
}, [
|
|
102
|
+
currentValueInSeconds,
|
|
103
|
+
updateIntervalInSeconds,
|
|
104
|
+
unit
|
|
105
|
+
]);
|
|
106
|
+
let currentValue = value || 0;
|
|
107
|
+
let currentUnit = unit;
|
|
108
|
+
if (canIncrement(unit) && typeof currentValueInSeconds === "number" && updateIntervalInSeconds) {
|
|
109
|
+
currentUnit = selectUnit(currentValueInSeconds);
|
|
110
|
+
const unitDuration = getDurationInSeconds(currentUnit);
|
|
111
|
+
currentValue = Math.round(currentValueInSeconds / unitDuration);
|
|
112
|
+
}
|
|
113
|
+
return /* @__PURE__ */ _jsx(SimpleFormattedRelativeTime, {
|
|
114
|
+
value: currentValue,
|
|
115
|
+
unit: currentUnit,
|
|
116
|
+
...otherProps
|
|
117
|
+
});
|
|
124
118
|
};
|
|
125
|
-
FormattedRelativeTime.displayName =
|
|
119
|
+
FormattedRelativeTime.displayName = "FormattedRelativeTime";
|
|
126
120
|
export default FormattedRelativeTime;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IntlShape } from
|
|
1
|
+
import { type IntlShape } from "../types.js";
|
|
2
2
|
export default function useIntl(this: void): IntlShape;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import "../types.js";
|
|
3
|
+
import { invariantIntlContext } from "../utils.js";
|
|
4
|
+
import { Context } from "./injectIntl.js";
|
|
4
5
|
export default function useIntl() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const intl = React.useContext(Context);
|
|
7
|
+
invariantIntlContext(intl);
|
|
8
|
+
return intl;
|
|
8
9
|
}
|
package/src/types.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ResolvedIntlConfig as CoreResolvedIntlConfig, Formatters, IntlFormatters, MessageDescriptor } from
|
|
2
|
-
import { FormatXMLElementFn, Options as IntlMessageFormatOptions, PrimitiveType } from
|
|
3
|
-
import * as React from
|
|
4
|
-
import { DEFAULT_INTL_CONFIG } from
|
|
1
|
+
import { type ResolvedIntlConfig as CoreResolvedIntlConfig, type Formatters, type IntlFormatters, type MessageDescriptor } from "@formatjs/intl";
|
|
2
|
+
import { type FormatXMLElementFn, type Options as IntlMessageFormatOptions, type PrimitiveType } from "intl-messageformat";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import type { DEFAULT_INTL_CONFIG } from "./utils.js";
|
|
5
5
|
export type IntlConfig = Omit<ResolvedIntlConfig, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>;
|
|
6
6
|
export interface ResolvedIntlConfig extends CoreResolvedIntlConfig<React.ReactNode> {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
textComponent?: React.ComponentType | keyof React.JSX.IntrinsicElements;
|
|
8
|
+
wrapRichTextChunksInFragment?: boolean;
|
|
9
9
|
}
|
|
10
10
|
export interface IntlShape extends ResolvedIntlConfig, IntlFormatters<React.ReactNode> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
formatMessage(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string;
|
|
12
|
+
formatMessage(this: void, descriptor: MessageDescriptor, values?: Record<string, React.ReactNode | PrimitiveType | FormatXMLElementFn<string, React.ReactNode>>, opts?: IntlMessageFormatOptions): Array<React.ReactNode>;
|
|
13
|
+
formatters: Formatters;
|
|
14
14
|
}
|
package/src/types.js
CHANGED
package/src/utils.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { FormatXMLElementFn } from
|
|
2
|
-
import * as React from
|
|
3
|
-
import { ResolvedIntlConfig } from
|
|
1
|
+
import { type FormatXMLElementFn } from "intl-messageformat";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { type ResolvedIntlConfig } from "./types.js";
|
|
4
4
|
export declare function invariant(condition: boolean, message: string, Err?: any): asserts condition;
|
|
5
5
|
export declare function invariantIntlContext(intl?: any): asserts intl;
|
|
6
|
-
export type DefaultIntlConfig = Pick<ResolvedIntlConfig,
|
|
6
|
+
export type DefaultIntlConfig = Pick<ResolvedIntlConfig, "fallbackOnEmptyString" | "formats" | "messages" | "timeZone" | "textComponent" | "defaultLocale" | "defaultFormats" | "onError">;
|
|
7
7
|
export declare const DEFAULT_INTL_CONFIG: DefaultIntlConfig;
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
* Builds an array of {@link React.ReactNode}s with index-based keys, similar to
|
|
10
|
+
* {@link React.Children.toArray}. However, this function tells React that it
|
|
11
|
+
* was intentional, so they won't produce a bunch of warnings about it.
|
|
12
|
+
*
|
|
13
|
+
* React doesn't recommend doing this because it makes reordering inefficient,
|
|
14
|
+
* but we mostly need this for message chunks, which don't tend to reorder to
|
|
15
|
+
* begin with.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
18
|
export declare const toKeyedReactNodeArray: typeof React.Children.toArray;
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
21
|
+
* argument `parts` through, assigning unique key to each part, to prevent
|
|
22
|
+
* "Each child in a list should have a unique "key"" React error.
|
|
23
|
+
* @param formatXMLElementFn
|
|
24
|
+
*/
|
|
25
25
|
export declare function assignUniqueKeysToParts(formatXMLElementFn: FormatXMLElementFn<React.ReactNode>): FormatXMLElementFn<React.ReactNode>;
|
|
26
26
|
export declare function shallowEqual<T extends Record<string, unknown> = Record<string, unknown>>(objA?: T, objB?: T): boolean;
|