react-intl 7.1.6 → 7.1.7
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/lib/src/components/createIntl.js +2 -6
- package/lib/src/components/message.js +2 -2
- package/lib/src/utils.d.ts +10 -0
- package/lib/src/utils.js +22 -0
- package/package.json +39 -43
- package/react-intl.iife.js +37 -28
- package/src/components/createIntl.js +1 -5
- package/src/components/message.js +2 -2
- package/src/utils.d.ts +10 -0
- package/src/utils.js +24 -1
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
import { __assign, __rest, __spreadArray } from "tslib";
|
|
7
7
|
import { createIntl as coreCreateIntl, formatMessage as coreFormatMessage, } from '@formatjs/intl';
|
|
8
8
|
import { isFormatXMLElementFn, } from 'intl-messageformat';
|
|
9
|
-
import
|
|
10
|
-
import { DEFAULT_INTL_CONFIG, assignUniqueKeysToParts } from '../utils';
|
|
9
|
+
import { DEFAULT_INTL_CONFIG, assignUniqueKeysToParts, toKeyedReactNodeArray, } from '../utils';
|
|
11
10
|
function assignUniqueKeysToFormatXMLElementFnArgument(values) {
|
|
12
11
|
if (!values) {
|
|
13
12
|
return values;
|
|
@@ -30,10 +29,7 @@ var formatMessage = function (config, formatters, descriptor, rawValues) {
|
|
|
30
29
|
formatters,
|
|
31
30
|
descriptor,
|
|
32
31
|
values], rest, false));
|
|
33
|
-
|
|
34
|
-
return React.Children.toArray(chunks);
|
|
35
|
-
}
|
|
36
|
-
return chunks;
|
|
32
|
+
return toKeyedReactNodeArray(chunks);
|
|
37
33
|
};
|
|
38
34
|
/**
|
|
39
35
|
* Create intl object
|
|
@@ -22,10 +22,10 @@ function FormattedMessage(props) {
|
|
|
22
22
|
ignoreTag: ignoreTag,
|
|
23
23
|
});
|
|
24
24
|
if (typeof children === 'function') {
|
|
25
|
-
return children(
|
|
25
|
+
return children(nodes);
|
|
26
26
|
}
|
|
27
27
|
if (Component) {
|
|
28
|
-
return React.createElement(Component, null,
|
|
28
|
+
return React.createElement(Component, null, nodes);
|
|
29
29
|
}
|
|
30
30
|
return React.createElement(React.Fragment, null, nodes);
|
|
31
31
|
}
|
package/lib/src/utils.d.ts
CHANGED
|
@@ -5,6 +5,16 @@ export declare function invariant(condition: boolean, message: string, Err?: any
|
|
|
5
5
|
export declare function invariantIntlContext(intl?: any): asserts intl;
|
|
6
6
|
export type DefaultIntlConfig = Pick<ResolvedIntlConfig, 'fallbackOnEmptyString' | 'formats' | 'messages' | 'timeZone' | 'textComponent' | 'defaultLocale' | 'defaultFormats' | 'onError'>;
|
|
7
7
|
export declare const DEFAULT_INTL_CONFIG: DefaultIntlConfig;
|
|
8
|
+
/**
|
|
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
|
+
export declare const toKeyedReactNodeArray: typeof React.Children.toArray;
|
|
8
18
|
/**
|
|
9
19
|
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
10
20
|
* argument `parts` through, assigning unique key to each part, to prevent
|
package/lib/src/utils.js
CHANGED
|
@@ -12,6 +12,28 @@ export function invariantIntlContext(intl) {
|
|
|
12
12
|
'<IntlProvider> needs to exist in the component ancestry.');
|
|
13
13
|
}
|
|
14
14
|
export var DEFAULT_INTL_CONFIG = __assign(__assign({}, CORE_DEFAULT_INTL_CONFIG), { textComponent: React.Fragment });
|
|
15
|
+
var arbitraryKeyProps = { key: 42 };
|
|
16
|
+
var toArbitrarilyKeyedReactNode = function (reactNode) {
|
|
17
|
+
return React.isValidElement(reactNode)
|
|
18
|
+
? React.createElement(React.Fragment, arbitraryKeyProps, reactNode)
|
|
19
|
+
: reactNode;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Builds an array of {@link React.ReactNode}s with index-based keys, similar to
|
|
23
|
+
* {@link React.Children.toArray}. However, this function tells React that it
|
|
24
|
+
* was intentional, so they won't produce a bunch of warnings about it.
|
|
25
|
+
*
|
|
26
|
+
* React doesn't recommend doing this because it makes reordering inefficient,
|
|
27
|
+
* but we mostly need this for message chunks, which don't tend to reorder to
|
|
28
|
+
* begin with.
|
|
29
|
+
*/
|
|
30
|
+
export var toKeyedReactNodeArray = function (children) { var _a;
|
|
31
|
+
/**
|
|
32
|
+
* Note: {@link React.Children.map} will add its own index-based prefix to
|
|
33
|
+
* every key anyway, so the auto-injected one doesn't even have to be unique.
|
|
34
|
+
* This basically just tells React that it's explicit/intentional.
|
|
35
|
+
*/
|
|
36
|
+
return (_a = React.Children.map(children, toArbitrarilyKeyedReactNode)) !== null && _a !== void 0 ? _a : []; };
|
|
15
37
|
/**
|
|
16
38
|
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
17
39
|
* argument `parts` through, assigning unique key to each part, to prevent
|
package/package.json
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intl",
|
|
3
|
-
"version": "7.1.6",
|
|
4
3
|
"description": "Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"i18n",
|
|
8
|
-
"internationalization",
|
|
9
|
-
"locale",
|
|
10
|
-
"localization",
|
|
11
|
-
"globalization",
|
|
12
|
-
"react",
|
|
13
|
-
"reactjs",
|
|
14
|
-
"format",
|
|
15
|
-
"formatting",
|
|
16
|
-
"translate",
|
|
17
|
-
"translation"
|
|
18
|
-
],
|
|
4
|
+
"version": "7.1.7",
|
|
5
|
+
"license": "BSD-3-Clause",
|
|
19
6
|
"author": "Eric Ferraiuolo <edf@ericf.me>",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@types/hoist-non-react-statics": "^3.3.1",
|
|
11
|
+
"@types/react": "^18.3.12",
|
|
12
|
+
"hoist-non-react-statics": "^3.3.2",
|
|
13
|
+
"tslib": "^2.8.0",
|
|
14
|
+
"@formatjs/ecma402-abstract": "2.3.4",
|
|
15
|
+
"intl-messageformat": "10.7.16",
|
|
16
|
+
"@formatjs/intl": "3.1.5",
|
|
17
|
+
"@formatjs/icu-messageformat-parser": "2.11.2"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": "^18",
|
|
21
|
+
"typescript": "5.8.2"
|
|
22
|
+
},
|
|
23
|
+
"browserslist": [
|
|
24
|
+
"ie 11"
|
|
25
|
+
],
|
|
26
|
+
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
20
27
|
"contributors": [
|
|
21
28
|
"Aarni Koskela <akx@iki.fi>",
|
|
22
29
|
"Alexis Deveria <adeveria@gmail.com>",
|
|
@@ -56,6 +63,7 @@
|
|
|
56
63
|
"Jiayi Hu <steph.jiayi@gmail.com>",
|
|
57
64
|
"Jimmy Jia <tesrin@gmail.com>",
|
|
58
65
|
"Joe Lencioni <joe.lencioni@gmail.com>",
|
|
66
|
+
"Johannes Wüller <johanneswueller@gmail.com>",
|
|
59
67
|
"Jonas Antonelli <jonas.antonelli@gmail.com>",
|
|
60
68
|
"Jose G <josegranafdez@gmail.com>",
|
|
61
69
|
"Juan Ignacio Dopazo <juan@dopazo.me>",
|
|
@@ -114,40 +122,28 @@
|
|
|
114
122
|
"Yang Su <yang@quip.com>",
|
|
115
123
|
"zouxuoz <zouxuoz@gmail.com>"
|
|
116
124
|
],
|
|
117
|
-
"
|
|
125
|
+
"gitHead": "773d6ebf881357f6e4c2dd7e8984b1bd0f69b4ca",
|
|
118
126
|
"homepage": "https://formatjs.github.io/docs/react-intl",
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
-
|
|
127
|
+
"keywords": [
|
|
128
|
+
"format",
|
|
129
|
+
"formatting",
|
|
130
|
+
"globalization",
|
|
131
|
+
"i18n",
|
|
132
|
+
"internationalization",
|
|
133
|
+
"intl",
|
|
134
|
+
"locale",
|
|
135
|
+
"localization",
|
|
136
|
+
"react",
|
|
137
|
+
"reactjs",
|
|
138
|
+
"translate",
|
|
139
|
+
"translation"
|
|
140
|
+
],
|
|
126
141
|
"main": "index.js",
|
|
127
142
|
"module": "lib/index.js",
|
|
128
|
-
"types": "index.d.ts",
|
|
129
|
-
"sideEffects": false,
|
|
130
|
-
"dependencies": {
|
|
131
|
-
"@types/hoist-non-react-statics": "3",
|
|
132
|
-
"@types/react": "16 || 17 || 18 || 19",
|
|
133
|
-
"hoist-non-react-statics": "3",
|
|
134
|
-
"tslib": "2",
|
|
135
|
-
"@formatjs/ecma402-abstract": "2.3.3",
|
|
136
|
-
"@formatjs/intl": "3.1.4",
|
|
137
|
-
"intl-messageformat": "10.7.15",
|
|
138
|
-
"@formatjs/icu-messageformat-parser": "2.11.1"
|
|
139
|
-
},
|
|
140
|
-
"peerDependencies": {
|
|
141
|
-
"react": "^16.6.0 || 17 || 18 || 19",
|
|
142
|
-
"typescript": "5"
|
|
143
|
-
},
|
|
144
143
|
"peerDependenciesMeta": {
|
|
145
144
|
"typescript": {
|
|
146
145
|
"optional": true
|
|
147
146
|
}
|
|
148
147
|
},
|
|
149
|
-
"
|
|
150
|
-
"ie 11"
|
|
151
|
-
],
|
|
152
|
-
"gitHead": "773d6ebf881357f6e4c2dd7e8984b1bd0f69b4ca"
|
|
148
|
+
"repository": "git@github.com:formatjs/formatjs.git"
|
|
153
149
|
}
|
package/react-intl.iife.js
CHANGED
|
@@ -4394,6 +4394,19 @@ var ReactIntl = (() => {
|
|
|
4394
4394
|
var DEFAULT_INTL_CONFIG2 = __spreadProps(__spreadValues({}, DEFAULT_INTL_CONFIG), {
|
|
4395
4395
|
textComponent: React.Fragment
|
|
4396
4396
|
});
|
|
4397
|
+
var arbitraryKeyProps = { key: 42 };
|
|
4398
|
+
var toArbitrarilyKeyedReactNode = (reactNode) => React.isValidElement(reactNode) ? React.createElement(React.Fragment, arbitraryKeyProps, reactNode) : reactNode;
|
|
4399
|
+
var toKeyedReactNodeArray = (children) => {
|
|
4400
|
+
var _a2;
|
|
4401
|
+
return (
|
|
4402
|
+
/**
|
|
4403
|
+
* Note: {@link React.Children.map} will add its own index-based prefix to
|
|
4404
|
+
* every key anyway, so the auto-injected one doesn't even have to be unique.
|
|
4405
|
+
* This basically just tells React that it's explicit/intentional.
|
|
4406
|
+
*/
|
|
4407
|
+
(_a2 = React.Children.map(children, toArbitrarilyKeyedReactNode)) != null ? _a2 : []
|
|
4408
|
+
);
|
|
4409
|
+
};
|
|
4397
4410
|
function assignUniqueKeysToParts(formatXMLElementFn) {
|
|
4398
4411
|
return function(parts) {
|
|
4399
4412
|
return formatXMLElementFn(React.Children.toArray(parts));
|
|
@@ -4525,7 +4538,6 @@ var ReactIntl = (() => {
|
|
|
4525
4538
|
}
|
|
4526
4539
|
|
|
4527
4540
|
// packages/react-intl/src/components/createIntl.ts
|
|
4528
|
-
var React5 = __toESM(window.React);
|
|
4529
4541
|
function assignUniqueKeysToFormatXMLElementFnArgument(values) {
|
|
4530
4542
|
if (!values) {
|
|
4531
4543
|
return values;
|
|
@@ -4545,10 +4557,7 @@ var ReactIntl = (() => {
|
|
|
4545
4557
|
values,
|
|
4546
4558
|
...rest
|
|
4547
4559
|
);
|
|
4548
|
-
|
|
4549
|
-
return React5.Children.toArray(chunks);
|
|
4550
|
-
}
|
|
4551
|
-
return chunks;
|
|
4560
|
+
return toKeyedReactNodeArray(chunks);
|
|
4552
4561
|
};
|
|
4553
4562
|
var createIntl2 = (_a2, cache) => {
|
|
4554
4563
|
var _b = _a2, { defaultRichTextElements: rawDefaultRichTextElements } = _b, config = __objRest(_b, ["defaultRichTextElements"]);
|
|
@@ -4583,7 +4592,7 @@ var ReactIntl = (() => {
|
|
|
4583
4592
|
};
|
|
4584
4593
|
|
|
4585
4594
|
// packages/react-intl/src/components/dateTimeRange.tsx
|
|
4586
|
-
var
|
|
4595
|
+
var React5 = __toESM(window.React);
|
|
4587
4596
|
var FormattedDateTimeRange = (props) => {
|
|
4588
4597
|
const intl = useIntl();
|
|
4589
4598
|
const _a2 = props, { from, to, children } = _a2, formatProps = __objRest(_a2, ["from", "to", "children"]);
|
|
@@ -4591,14 +4600,14 @@ var ReactIntl = (() => {
|
|
|
4591
4600
|
if (typeof children === "function") {
|
|
4592
4601
|
return children(formattedValue);
|
|
4593
4602
|
}
|
|
4594
|
-
const Text = intl.textComponent ||
|
|
4595
|
-
return
|
|
4603
|
+
const Text = intl.textComponent || React5.Fragment;
|
|
4604
|
+
return React5.createElement(Text, null, formattedValue);
|
|
4596
4605
|
};
|
|
4597
4606
|
FormattedDateTimeRange.displayName = "FormattedDateTimeRange";
|
|
4598
4607
|
var dateTimeRange_default = FormattedDateTimeRange;
|
|
4599
4608
|
|
|
4600
4609
|
// packages/react-intl/src/components/message.tsx
|
|
4601
|
-
var
|
|
4610
|
+
var React6 = __toESM(window.React);
|
|
4602
4611
|
function areEqual(prevProps, nextProps) {
|
|
4603
4612
|
const _a2 = prevProps, { values } = _a2, otherProps = __objRest(_a2, ["values"]);
|
|
4604
4613
|
const _b = nextProps, { values: nextValues } = _b, nextOtherProps = __objRest(_b, ["values"]);
|
|
@@ -4606,7 +4615,7 @@ var ReactIntl = (() => {
|
|
|
4606
4615
|
}
|
|
4607
4616
|
function FormattedMessage(props) {
|
|
4608
4617
|
const intl = useIntl();
|
|
4609
|
-
const { formatMessage: formatMessage3, textComponent: Text =
|
|
4618
|
+
const { formatMessage: formatMessage3, textComponent: Text = React6.Fragment } = intl;
|
|
4610
4619
|
const {
|
|
4611
4620
|
id,
|
|
4612
4621
|
description,
|
|
@@ -4617,19 +4626,19 @@ var ReactIntl = (() => {
|
|
|
4617
4626
|
ignoreTag
|
|
4618
4627
|
} = props;
|
|
4619
4628
|
const descriptor = { id, description, defaultMessage };
|
|
4620
|
-
|
|
4629
|
+
const nodes = formatMessage3(descriptor, values, {
|
|
4621
4630
|
ignoreTag
|
|
4622
4631
|
});
|
|
4623
4632
|
if (typeof children === "function") {
|
|
4624
|
-
return children(
|
|
4633
|
+
return children(nodes);
|
|
4625
4634
|
}
|
|
4626
4635
|
if (Component) {
|
|
4627
|
-
return
|
|
4636
|
+
return React6.createElement(Component, null, nodes);
|
|
4628
4637
|
}
|
|
4629
|
-
return
|
|
4638
|
+
return React6.createElement(React6.Fragment, null, nodes);
|
|
4630
4639
|
}
|
|
4631
4640
|
FormattedMessage.displayName = "FormattedMessage";
|
|
4632
|
-
var MemoizedFormattedMessage =
|
|
4641
|
+
var MemoizedFormattedMessage = React6.memo(
|
|
4633
4642
|
FormattedMessage,
|
|
4634
4643
|
areEqual
|
|
4635
4644
|
);
|
|
@@ -4637,7 +4646,7 @@ var ReactIntl = (() => {
|
|
|
4637
4646
|
var message_default = MemoizedFormattedMessage;
|
|
4638
4647
|
|
|
4639
4648
|
// packages/react-intl/src/components/plural.tsx
|
|
4640
|
-
var
|
|
4649
|
+
var React7 = __toESM(window.React);
|
|
4641
4650
|
var FormattedPlural = (props) => {
|
|
4642
4651
|
const { formatPlural: formatPlural2, textComponent: Text } = useIntl();
|
|
4643
4652
|
const { value, other, children } = props;
|
|
@@ -4647,7 +4656,7 @@ var ReactIntl = (() => {
|
|
|
4647
4656
|
return children(formattedPlural);
|
|
4648
4657
|
}
|
|
4649
4658
|
if (Text) {
|
|
4650
|
-
return
|
|
4659
|
+
return React7.createElement(Text, null, formattedPlural);
|
|
4651
4660
|
}
|
|
4652
4661
|
return formattedPlural;
|
|
4653
4662
|
};
|
|
@@ -4655,7 +4664,7 @@ var ReactIntl = (() => {
|
|
|
4655
4664
|
var plural_default = FormattedPlural;
|
|
4656
4665
|
|
|
4657
4666
|
// packages/react-intl/src/components/provider.tsx
|
|
4658
|
-
var
|
|
4667
|
+
var React8 = __toESM(window.React);
|
|
4659
4668
|
function processIntlConfig(config) {
|
|
4660
4669
|
return {
|
|
4661
4670
|
locale: config.locale,
|
|
@@ -4672,7 +4681,7 @@ var ReactIntl = (() => {
|
|
|
4672
4681
|
defaultRichTextElements: config.defaultRichTextElements
|
|
4673
4682
|
};
|
|
4674
4683
|
}
|
|
4675
|
-
var IntlProvider2 = class extends
|
|
4684
|
+
var IntlProvider2 = class extends React8.PureComponent {
|
|
4676
4685
|
constructor() {
|
|
4677
4686
|
super(...arguments);
|
|
4678
4687
|
__publicField(this, "cache", createIntlCache());
|
|
@@ -4694,14 +4703,14 @@ var ReactIntl = (() => {
|
|
|
4694
4703
|
}
|
|
4695
4704
|
render() {
|
|
4696
4705
|
invariantIntlContext(this.state.intl);
|
|
4697
|
-
return
|
|
4706
|
+
return React8.createElement(Provider, { value: this.state.intl }, this.props.children);
|
|
4698
4707
|
}
|
|
4699
4708
|
};
|
|
4700
4709
|
__publicField(IntlProvider2, "displayName", "IntlProvider");
|
|
4701
4710
|
__publicField(IntlProvider2, "defaultProps", DEFAULT_INTL_CONFIG2);
|
|
4702
4711
|
|
|
4703
4712
|
// packages/react-intl/src/components/relative.tsx
|
|
4704
|
-
var
|
|
4713
|
+
var React9 = __toESM(window.React);
|
|
4705
4714
|
var MINUTE = 60;
|
|
4706
4715
|
var HOUR = 60 * 60;
|
|
4707
4716
|
var DAY = 60 * 60 * 24;
|
|
@@ -4759,9 +4768,9 @@ var ReactIntl = (() => {
|
|
|
4759
4768
|
return children(formattedRelativeTime);
|
|
4760
4769
|
}
|
|
4761
4770
|
if (Text) {
|
|
4762
|
-
return
|
|
4771
|
+
return React9.createElement(Text, null, formattedRelativeTime);
|
|
4763
4772
|
}
|
|
4764
|
-
return
|
|
4773
|
+
return React9.createElement(React9.Fragment, null, formattedRelativeTime);
|
|
4765
4774
|
};
|
|
4766
4775
|
var FormattedRelativeTime = (_a2) => {
|
|
4767
4776
|
var _b = _a2, {
|
|
@@ -4777,9 +4786,9 @@ var ReactIntl = (() => {
|
|
|
4777
4786
|
!updateIntervalInSeconds || !!(updateIntervalInSeconds && canIncrement(unit)),
|
|
4778
4787
|
"Cannot schedule update with unit longer than hour"
|
|
4779
4788
|
);
|
|
4780
|
-
const [prevUnit, setPrevUnit] =
|
|
4781
|
-
const [prevValue, setPrevValue] =
|
|
4782
|
-
const [currentValueInSeconds, setCurrentValueInSeconds] =
|
|
4789
|
+
const [prevUnit, setPrevUnit] = React9.useState();
|
|
4790
|
+
const [prevValue, setPrevValue] = React9.useState(0);
|
|
4791
|
+
const [currentValueInSeconds, setCurrentValueInSeconds] = React9.useState(0);
|
|
4783
4792
|
let updateTimer;
|
|
4784
4793
|
if (unit !== prevUnit || value !== prevValue) {
|
|
4785
4794
|
setPrevValue(value || 0);
|
|
@@ -4788,7 +4797,7 @@ var ReactIntl = (() => {
|
|
|
4788
4797
|
canIncrement(unit) ? valueToSeconds(value, unit) : 0
|
|
4789
4798
|
);
|
|
4790
4799
|
}
|
|
4791
|
-
|
|
4800
|
+
React9.useEffect(() => {
|
|
4792
4801
|
function clearUpdateTimer() {
|
|
4793
4802
|
clearTimeout(updateTimer);
|
|
4794
4803
|
}
|
|
@@ -4823,7 +4832,7 @@ var ReactIntl = (() => {
|
|
|
4823
4832
|
const unitDuration = getDurationInSeconds(currentUnit);
|
|
4824
4833
|
currentValue = Math.round(currentValueInSeconds / unitDuration);
|
|
4825
4834
|
}
|
|
4826
|
-
return
|
|
4835
|
+
return React9.createElement(
|
|
4827
4836
|
SimpleFormattedRelativeTime,
|
|
4828
4837
|
__spreadValues({
|
|
4829
4838
|
value: currentValue,
|
|
@@ -9,7 +9,6 @@ exports.createIntl = void 0;
|
|
|
9
9
|
var tslib_1 = require("tslib");
|
|
10
10
|
var intl_1 = require("@formatjs/intl");
|
|
11
11
|
var intl_messageformat_1 = require("intl-messageformat");
|
|
12
|
-
var React = tslib_1.__importStar(require("react"));
|
|
13
12
|
var utils_1 = require("../utils");
|
|
14
13
|
function assignUniqueKeysToFormatXMLElementFnArgument(values) {
|
|
15
14
|
if (!values) {
|
|
@@ -33,10 +32,7 @@ var formatMessage = function (config, formatters, descriptor, rawValues) {
|
|
|
33
32
|
formatters,
|
|
34
33
|
descriptor,
|
|
35
34
|
values], rest, false));
|
|
36
|
-
|
|
37
|
-
return React.Children.toArray(chunks);
|
|
38
|
-
}
|
|
39
|
-
return chunks;
|
|
35
|
+
return (0, utils_1.toKeyedReactNodeArray)(chunks);
|
|
40
36
|
};
|
|
41
37
|
/**
|
|
42
38
|
* Create intl object
|
|
@@ -24,10 +24,10 @@ function FormattedMessage(props) {
|
|
|
24
24
|
ignoreTag: ignoreTag,
|
|
25
25
|
});
|
|
26
26
|
if (typeof children === 'function') {
|
|
27
|
-
return children(
|
|
27
|
+
return children(nodes);
|
|
28
28
|
}
|
|
29
29
|
if (Component) {
|
|
30
|
-
return React.createElement(Component, null,
|
|
30
|
+
return React.createElement(Component, null, nodes);
|
|
31
31
|
}
|
|
32
32
|
return React.createElement(React.Fragment, null, nodes);
|
|
33
33
|
}
|
package/src/utils.d.ts
CHANGED
|
@@ -5,6 +5,16 @@ export declare function invariant(condition: boolean, message: string, Err?: any
|
|
|
5
5
|
export declare function invariantIntlContext(intl?: any): asserts intl;
|
|
6
6
|
export type DefaultIntlConfig = Pick<ResolvedIntlConfig, 'fallbackOnEmptyString' | 'formats' | 'messages' | 'timeZone' | 'textComponent' | 'defaultLocale' | 'defaultFormats' | 'onError'>;
|
|
7
7
|
export declare const DEFAULT_INTL_CONFIG: DefaultIntlConfig;
|
|
8
|
+
/**
|
|
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
|
+
export declare const toKeyedReactNodeArray: typeof React.Children.toArray;
|
|
8
18
|
/**
|
|
9
19
|
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
10
20
|
* argument `parts` through, assigning unique key to each part, to prevent
|
package/src/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_INTL_CONFIG = void 0;
|
|
3
|
+
exports.toKeyedReactNodeArray = exports.DEFAULT_INTL_CONFIG = void 0;
|
|
4
4
|
exports.invariant = invariant;
|
|
5
5
|
exports.invariantIntlContext = invariantIntlContext;
|
|
6
6
|
exports.assignUniqueKeysToParts = assignUniqueKeysToParts;
|
|
@@ -19,6 +19,29 @@ function invariantIntlContext(intl) {
|
|
|
19
19
|
'<IntlProvider> needs to exist in the component ancestry.');
|
|
20
20
|
}
|
|
21
21
|
exports.DEFAULT_INTL_CONFIG = tslib_1.__assign(tslib_1.__assign({}, intl_1.DEFAULT_INTL_CONFIG), { textComponent: React.Fragment });
|
|
22
|
+
var arbitraryKeyProps = { key: 42 };
|
|
23
|
+
var toArbitrarilyKeyedReactNode = function (reactNode) {
|
|
24
|
+
return React.isValidElement(reactNode)
|
|
25
|
+
? React.createElement(React.Fragment, arbitraryKeyProps, reactNode)
|
|
26
|
+
: reactNode;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Builds an array of {@link React.ReactNode}s with index-based keys, similar to
|
|
30
|
+
* {@link React.Children.toArray}. However, this function tells React that it
|
|
31
|
+
* was intentional, so they won't produce a bunch of warnings about it.
|
|
32
|
+
*
|
|
33
|
+
* React doesn't recommend doing this because it makes reordering inefficient,
|
|
34
|
+
* but we mostly need this for message chunks, which don't tend to reorder to
|
|
35
|
+
* begin with.
|
|
36
|
+
*/
|
|
37
|
+
var toKeyedReactNodeArray = function (children) { var _a;
|
|
38
|
+
/**
|
|
39
|
+
* Note: {@link React.Children.map} will add its own index-based prefix to
|
|
40
|
+
* every key anyway, so the auto-injected one doesn't even have to be unique.
|
|
41
|
+
* This basically just tells React that it's explicit/intentional.
|
|
42
|
+
*/
|
|
43
|
+
return (_a = React.Children.map(children, toArbitrarilyKeyedReactNode)) !== null && _a !== void 0 ? _a : []; };
|
|
44
|
+
exports.toKeyedReactNodeArray = toKeyedReactNodeArray;
|
|
22
45
|
/**
|
|
23
46
|
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
24
47
|
* argument `parts` through, assigning unique key to each part, to prevent
|