react-intl 4.7.5 → 5.0.2
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/CHANGELOG.md +58 -0
- package/dist/components/message.d.ts.map +1 -1
- package/dist/components/message.js +4 -24
- package/dist/components/message.js.map +1 -1
- package/dist/formatters/message.d.ts +2 -0
- package/dist/formatters/message.d.ts.map +1 -1
- package/dist/formatters/message.js +15 -3
- package/dist/formatters/message.js.map +1 -1
- package/dist/react-intl.d.ts +1 -1
- package/dist/react-intl.js +30 -24
- package/dist/react-intl.js.map +1 -1
- package/dist/react-intl.min.js +1 -1
- package/dist/react-intl.min.js.map +1 -1
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +13 -0
- package/dist/utils.js.map +1 -1
- package/lib/components/message.d.ts.map +1 -1
- package/lib/components/message.js +5 -25
- package/lib/components/message.js.map +1 -1
- package/lib/formatters/message.d.ts +2 -0
- package/lib/formatters/message.d.ts.map +1 -1
- package/lib/formatters/message.js +15 -4
- package/lib/formatters/message.js.map +1 -1
- package/lib/utils.d.ts +9 -0
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +12 -0
- package/lib/utils.js.map +1 -1
- package/package.json +12 -12
- package/src/components/message.tsx +4 -38
- package/src/formatters/message.ts +22 -3
- package/src/utils.ts +16 -1
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { IntlConfig, IntlCache, CustomFormats, Formatters, IntlShape } from './types';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { FormatXMLElementFn } from 'intl-messageformat';
|
|
2
4
|
import { IntlRelativeTimeFormatOptions } from '@formatjs/intl-relativetimeformat';
|
|
3
5
|
export declare function filterProps<T extends Record<string, any>, K extends string>(props: T, whitelist: Array<K>, defaults?: Partial<T>): Pick<T, K>;
|
|
4
6
|
export declare function invariantIntlContext(intl?: any): asserts intl;
|
|
@@ -11,4 +13,11 @@ export declare function createIntlCache(): IntlCache;
|
|
|
11
13
|
*/
|
|
12
14
|
export declare function createFormatters(cache?: IntlCache): Formatters;
|
|
13
15
|
export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: IntlShape['onError']): Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | IntlRelativeTimeFormatOptions | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
18
|
+
* argument `parts` through, assigning unique key to each part, to prevent
|
|
19
|
+
* "Each child in a list should have a unique "key"" React error.
|
|
20
|
+
* @param formatXMLElementFn
|
|
21
|
+
*/
|
|
22
|
+
export declare function assignUniqueKeysToParts(formatXMLElementFn: FormatXMLElementFn<React.ReactNode>): typeof formatXMLElementFn;
|
|
14
23
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,UAAU,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,SAAS,EACV,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,UAAU,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,SAAS,EACV,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAA0B,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAGzE,OAAO,EAAC,6BAA6B,EAAC,MAAM,mCAAmC,CAAC;AAGhF,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,MAAM,EACzE,KAAK,EAAE,CAAC,EACR,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,EACnB,QAAQ,GAAE,OAAO,CAAC,CAAC,CAAM,GACxB,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAUZ;AAED,wBAAgB,oBAAoB,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAM7D;AAED,eAAO,MAAM,mBAAmB,EAAE,SAAS,CAAC,SAAS,CAIpD,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,IAAI,CACpC,UAAU,EACR,SAAS,GACT,UAAU,GACV,UAAU,GACV,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,SAAS,CAWZ,CAAC;AAEF,wBAAgB,eAAe,IAAI,SAAS,CAU3C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,GAAE,SAA6B,GACnC,UAAU,CAmBZ;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,aAAa,EAC1D,OAAO,EAAE,aAAa,EACtB,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,GAE3B,IAAI,CAAC,mBAAmB,GACxB,IAAI,CAAC,qBAAqB,GAC1B,6BAA6B,GAC7B,SAAS,CAWZ;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,kBAAkB,EAAE,kBAAkB,CAAC,KAAK,CAAC,SAAS,CAAC,GACtD,OAAO,kBAAkB,CAK3B"}
|
package/dist/utils.js
CHANGED
|
@@ -91,4 +91,17 @@ function getNamedFormat(formats, type, name, onError) {
|
|
|
91
91
|
onError(new error_1.UnsupportedFormatterError("No " + type + " format named: " + name));
|
|
92
92
|
}
|
|
93
93
|
exports.getNamedFormat = getNamedFormat;
|
|
94
|
+
/**
|
|
95
|
+
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
96
|
+
* argument `parts` through, assigning unique key to each part, to prevent
|
|
97
|
+
* "Each child in a list should have a unique "key"" React error.
|
|
98
|
+
* @param formatXMLElementFn
|
|
99
|
+
*/
|
|
100
|
+
function assignUniqueKeysToParts(formatXMLElementFn) {
|
|
101
|
+
return function (parts) {
|
|
102
|
+
// eslint-disable-next-line prefer-rest-params
|
|
103
|
+
return formatXMLElementFn(React.Children.toArray(parts));
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
exports.assignUniqueKeysToParts = assignUniqueKeysToParts;
|
|
94
107
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;EASE;;AASF,6BAA+B;AAC/B,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;EASE;;AASF,6BAA+B;AAC/B,yDAAyE;AACzE,uDAAuD;AACvD,mDAA+C;AAE/C,iCAAkD;AAElD,SAAgB,WAAW,CACzB,KAAQ,EACR,SAAmB,EACnB,QAAyB;IAAzB,yBAAA,EAAA,aAAyB;IAEzB,OAAO,SAAS,CAAC,MAAM,CAAC,UAAC,QAAQ,EAAE,IAAI;QACrC,IAAI,IAAI,IAAI,KAAK,EAAE;YACjB,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;SAC9B;aAAM,IAAI,IAAI,IAAI,QAAQ,EAAE;YAC3B,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAE,CAAC;SAClC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,EAAE,EAAgB,CAAC,CAAC;AACvB,CAAC;AAdD,kCAcC;AAED,SAAgB,oBAAoB,CAAC,IAAU;IAC7C,sBAAS,CACP,IAAI,EACJ,sDAAsD;QACpD,0DAA0D,CAC7D,CAAC;AACJ,CAAC;AAND,oDAMC;AAEY,QAAA,mBAAmB,GAAyB,UAAA,KAAK;IAC5D,IAAI,OAAO,CAAC,GA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B,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC;QAC7D,eAAe,EAAE,2BAAsB,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC;KAC1E,CAAC;AACJ,CAAC;AArBD,4CAqBC;AAED,SAAgB,cAAc,CAC5B,OAAsB,EACtB,IAAO,EACP,IAAY,EACZ,OAA6B;IAM7B,IAAM,UAAU,GAAG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,MAAM,CAAC;IACX,IAAI,UAAU,EAAE;QACd,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;KAC3B;IACD,IAAI,MAAM,EAAE;QACV,OAAO,MAAM,CAAC;KACf;IAED,OAAO,CAAC,IAAI,iCAAyB,CAAC,QAAM,IAAI,uBAAkB,IAAM,CAAC,CAAC,CAAC;AAC7E,CAAC;AApBD,wCAoBC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,kBAAuD;IAEvD,OAAO,UAAU,KAAK;QACpB,8CAA8C;QAC9C,OAAO,kBAAkB,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC;AAPD,0DAOC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/components/message.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAC,iBAAiB,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/components/message.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAC,iBAAiB,EAAC,MAAM,UAAU,CAAC;AAM3C,MAAM,WAAW,KAAK,CACpB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAC/D,SAAQ,iBAAiB;IACzB,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,OAAO,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACjC,QAAQ,CAAC,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,cAAc,GAAG,KAAK,CAAC,SAAS,CAAC;CAC5D;AAED,cAAM,gBAAgB,CACpB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CACpC,MAAM,EACJ,aAAa,GACb,KAAK,CAAC,YAAY,GAClB,kBAAkB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CACvD,CACD,SAAQ,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,CAAC,WAAW,SAAsB;IAExC,qBAAqB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO;IASnD,MAAM,IAAI,GAAG,CAAC,OAAO;CAwCtB;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -16,17 +16,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
16
16
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
17
17
|
};
|
|
18
18
|
})();
|
|
19
|
-
var __assign = (this && this.__assign) || function () {
|
|
20
|
-
__assign = Object.assign || function(t) {
|
|
21
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
22
|
-
s = arguments[i];
|
|
23
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
24
|
-
t[p] = s[p];
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
};
|
|
28
|
-
return __assign.apply(this, arguments);
|
|
29
|
-
};
|
|
30
19
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
31
20
|
var t = {};
|
|
32
21
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -47,16 +36,9 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
47
36
|
};
|
|
48
37
|
import * as React from 'react';
|
|
49
38
|
import { Context } from './injectIntl';
|
|
50
|
-
import {
|
|
51
|
-
import { invariantIntlContext, DEFAULT_INTL_CONFIG, createFormatters, } from '../utils';
|
|
39
|
+
import { invariantIntlContext } from '../utils';
|
|
52
40
|
import * as shallowEquals_ from 'shallow-equal/objects';
|
|
53
41
|
var shallowEquals = shallowEquals_.default || shallowEquals_;
|
|
54
|
-
function defaultFormatMessage(descriptor, values) {
|
|
55
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
56
|
-
console.error('[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry. Using default message as fallback.');
|
|
57
|
-
}
|
|
58
|
-
return formatMessage(__assign(__assign({}, DEFAULT_INTL_CONFIG), { locale: 'en' }), createFormatters(), descriptor, values);
|
|
59
|
-
}
|
|
60
42
|
var FormattedMessage = /** @class */ (function (_super) {
|
|
61
43
|
__extends(FormattedMessage, _super);
|
|
62
44
|
function FormattedMessage() {
|
|
@@ -71,18 +53,16 @@ var FormattedMessage = /** @class */ (function (_super) {
|
|
|
71
53
|
FormattedMessage.prototype.render = function () {
|
|
72
54
|
var _this = this;
|
|
73
55
|
return (React.createElement(Context.Consumer, null, function (intl) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var _a = intl || {}, _b = _a.formatMessage, formatMessage = _b === void 0 ? defaultFormatMessage : _b, _c = _a.textComponent, Text = _c === void 0 ? React.Fragment : _c;
|
|
78
|
-
var _d = _this.props, id = _d.id, description = _d.description, defaultMessage = _d.defaultMessage, values = _d.values, children = _d.children, _e = _d.tagName, Component = _e === void 0 ? Text : _e;
|
|
56
|
+
invariantIntlContext(intl);
|
|
57
|
+
var formatMessage = intl.formatMessage, _a = intl.textComponent, Text = _a === void 0 ? React.Fragment : _a;
|
|
58
|
+
var _b = _this.props, id = _b.id, description = _b.description, defaultMessage = _b.defaultMessage, values = _b.values, children = _b.children, _c = _b.tagName, Component = _c === void 0 ? Text : _c;
|
|
79
59
|
var descriptor = { id: id, description: description, defaultMessage: defaultMessage };
|
|
80
60
|
var nodes = formatMessage(descriptor, values);
|
|
81
61
|
if (!Array.isArray(nodes)) {
|
|
82
62
|
nodes = [nodes];
|
|
83
63
|
}
|
|
84
64
|
if (typeof children === 'function') {
|
|
85
|
-
return children
|
|
65
|
+
return children(nodes);
|
|
86
66
|
}
|
|
87
67
|
if (Component) {
|
|
88
68
|
// Needs to use `createElement()` instead of JSX, otherwise React will
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/components/message.tsx"],"names":[],"mappings":"AAAA;;;;GAIG
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/components/message.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAErC,OAAO,EAAC,oBAAoB,EAAC,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AACxD,IAAM,aAAa,GAChB,cAAsB,CAAC,OAAO,IAAI,cAAc,CAAC;AAUpD;IAOU,oCAAyB;IAPnC;;IA2DA,CAAC;IAjDC,gDAAqB,GAArB,UAAsB,SAAmB;QACvC,IAAM,eAAoC,EAAnC,kBAAM,EAAE,mCAA2B,CAAC;QACpC,IAAA,6BAAkB,EAAE,8CAAiB,CAAc;QAC1D,OAAO,CACL,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC;YAClC,CAAC,aAAa,CAAC,UAAU,EAAE,cAAc,CAAC,CAC3C,CAAC;IACJ,CAAC;IAED,iCAAM,GAAN;QAAA,iBAuCC;QAtCC,OAAO,CACL,oBAAC,OAAO,CAAC,QAAQ,QACd,UAAC,IAAI;YACJ,oBAAoB,CAAC,IAAI,CAAC,CAAC;YAEpB,IAAA,kCAAa,EAAE,uBAAoC,EAApC,0CAAoC,CAAS;YAC7D,IAAA,gBAOQ,EANZ,UAAE,EACF,4BAAW,EACX,kCAAc,EACd,kBAAM,EACN,sBAAQ,EACR,eAAyB,EAAzB,qCACY,CAAC;YAEf,IAAM,UAAU,GAAG,EAAC,EAAE,IAAA,EAAE,WAAW,aAAA,EAAE,cAAc,gBAAA,EAAC,CAAC;YACrD,IAAI,KAAK,GAAkC,aAAa,CACtD,UAAU,EACV,MAAM,CACP,CAAC;YAEF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACzB,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC;aACjB;YAED,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;gBAClC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;aACxB;YAED,IAAI,SAAS,EAAE;gBACb,sEAAsE;gBACtE,qEAAqE;gBACrE,OAAO,KAAK,CAAC,aAAa,OAAnB,KAAK,kBAAe,SAAS,EAAE,IAAI,GAAK,KAAK,GAAE;aACvD;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CACgB,CACpB,CAAC;IACJ,CAAC;IAlDM,4BAAW,GAAG,kBAAkB,CAAC;IAmD1C,uBAAC;CAAA,AA3DD,CAOU,KAAK,CAAC,SAAS,GAoDxB;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import { Formatters, IntlConfig, MessageDescriptor } from '../types';
|
|
2
3
|
import { FormatXMLElementFn, PrimitiveType } from 'intl-messageformat';
|
|
4
|
+
export declare function assignUniqueKeysToFormatXMLElementFnArgument(values: Record<string, PrimitiveType | React.ReactNode | FormatXMLElementFn<React.ReactNode>>): typeof values;
|
|
3
5
|
export declare function formatMessage({ locale, formats, messages, defaultLocale, defaultFormats, onError, }: Pick<IntlConfig, 'locale' | 'formats' | 'messages' | 'defaultLocale' | 'defaultFormats' | 'onError'>, state: Formatters, messageDescriptor?: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>): string;
|
|
4
6
|
//# sourceMappingURL=message.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/formatters/message.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/formatters/message.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EACL,UAAU,EACV,UAAU,EACV,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAElB,OAA0B,EACxB,kBAAkB,EAClB,aAAa,EAEd,MAAM,oBAAoB,CAAC;AAuD5B,wBAAgB,4CAA4C,CAC1D,MAAM,EAAE,MAAM,CACZ,MAAM,EACN,aAAa,GAAG,KAAK,CAAC,SAAS,GAAG,kBAAkB,CAAC,KAAK,CAAC,SAAS,CAAC,CACtE,GACA,OAAO,MAAM,CAQf;AAWD,wBAAgB,aAAa,CAC3B,EACE,MAAM,EACN,OAAO,EACP,QAAQ,EACR,aAAa,EACb,cAAc,EACd,OAAO,GACR,EAAE,IAAI,CACL,UAAU,EACR,QAAQ,GACR,SAAS,GACT,UAAU,GACV,eAAe,GACf,gBAAgB,GAChB,SAAS,CACZ,EACD,KAAK,EAAE,UAAU,EACjB,iBAAiB,CAAC,EAAE,iBAAiB,EACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC1E,MAAM,CAAC"}
|
|
@@ -23,7 +23,8 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
23
23
|
};
|
|
24
24
|
import * as React from 'react';
|
|
25
25
|
import { invariant } from '@formatjs/intl-utils';
|
|
26
|
-
import
|
|
26
|
+
import { assignUniqueKeysToParts } from '../utils';
|
|
27
|
+
import IntlMessageFormat, { isFormatXMLElementFn, } from 'intl-messageformat';
|
|
27
28
|
import { MissingTranslationError, MessageFormatError } from '../error';
|
|
28
29
|
function setTimeZoneInOptions(opts, timeZone) {
|
|
29
30
|
return Object.keys(opts).reduce(function (all, k) {
|
|
@@ -45,6 +46,15 @@ function deepMergeFormatsAndSetTimeZone(f1, timeZone) {
|
|
|
45
46
|
var mfFormats = IntlMessageFormat.formats;
|
|
46
47
|
return __assign(__assign(__assign({}, mfFormats), f1), { date: deepMergeOptions(setTimeZoneInOptions(mfFormats.date, timeZone), setTimeZoneInOptions(f1.date || {}, timeZone)), time: deepMergeOptions(setTimeZoneInOptions(mfFormats.time, timeZone), setTimeZoneInOptions(f1.time || {}, timeZone)) });
|
|
47
48
|
}
|
|
49
|
+
export function assignUniqueKeysToFormatXMLElementFnArgument(values) {
|
|
50
|
+
return Object.keys(values).reduce(function (acc, k) {
|
|
51
|
+
var v = values[k];
|
|
52
|
+
acc[k] = isFormatXMLElementFn(v)
|
|
53
|
+
? assignUniqueKeysToParts(v)
|
|
54
|
+
: v;
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
57
|
+
}
|
|
48
58
|
function prepareIntlMessageFormatHtmlOutput(chunks, shouldWrap) {
|
|
49
59
|
return Array.isArray(chunks) && shouldWrap
|
|
50
60
|
? React.createElement.apply(React, __spreadArrays([React.Fragment, null], chunks)) : chunks;
|
|
@@ -60,6 +70,7 @@ export function formatMessage(_a, state, messageDescriptor, values) {
|
|
|
60
70
|
if (!values && message && typeof message === 'string') {
|
|
61
71
|
return message.replace(/'\{(.*?)\}'/gi, "{$1}");
|
|
62
72
|
}
|
|
73
|
+
var patchedValues = values && assignUniqueKeysToFormatXMLElementFnArgument(values);
|
|
63
74
|
formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
|
|
64
75
|
defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);
|
|
65
76
|
if (!message) {
|
|
@@ -73,7 +84,7 @@ export function formatMessage(_a, state, messageDescriptor, values) {
|
|
|
73
84
|
if (defaultMessage) {
|
|
74
85
|
try {
|
|
75
86
|
var formatter = state.getMessageFormat(defaultMessage, defaultLocale, defaultFormats);
|
|
76
|
-
return prepareIntlMessageFormatHtmlOutput(formatter.format(
|
|
87
|
+
return prepareIntlMessageFormatHtmlOutput(formatter.format(patchedValues), wrapRichTextChunksInFragment);
|
|
77
88
|
}
|
|
78
89
|
catch (e) {
|
|
79
90
|
onError(new MessageFormatError("Error formatting default message for: \"" + id + "\", rendering default message verbatim", locale, messageDescriptor, e));
|
|
@@ -87,7 +98,7 @@ export function formatMessage(_a, state, messageDescriptor, values) {
|
|
|
87
98
|
var formatter = state.getMessageFormat(message, locale, formats, {
|
|
88
99
|
formatters: state,
|
|
89
100
|
});
|
|
90
|
-
return prepareIntlMessageFormatHtmlOutput(formatter.format(
|
|
101
|
+
return prepareIntlMessageFormatHtmlOutput(formatter.format(patchedValues), wrapRichTextChunksInFragment);
|
|
91
102
|
}
|
|
92
103
|
catch (e) {
|
|
93
104
|
onError(new MessageFormatError("Error formatting message: \"" + id + "\", using " + (defaultMessage ? 'default message' : 'id') + " as fallback.", locale, messageDescriptor, e));
|
|
@@ -95,7 +106,7 @@ export function formatMessage(_a, state, messageDescriptor, values) {
|
|
|
95
106
|
if (defaultMessage) {
|
|
96
107
|
try {
|
|
97
108
|
var formatter = state.getMessageFormat(defaultMessage, defaultLocale, defaultFormats);
|
|
98
|
-
return prepareIntlMessageFormatHtmlOutput(formatter.format(
|
|
109
|
+
return prepareIntlMessageFormatHtmlOutput(formatter.format(patchedValues), wrapRichTextChunksInFragment);
|
|
99
110
|
}
|
|
100
111
|
catch (e) {
|
|
101
112
|
onError(new MessageFormatError("Error formatting the default message for: \"" + id + "\", rendering message verbatim", locale, messageDescriptor, e));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/formatters/message.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/formatters/message.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAC,uBAAuB,EAAC,MAAM,UAAU,CAAC;AASjD,OAAO,iBAAiB,EAAE,EAGxB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,uBAAuB,EAAE,kBAAkB,EAAC,MAAM,UAAU,CAAC;AAErE,SAAS,oBAAoB,CAC3B,IAAgD,EAChD,QAAgB;IAEhB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAC7B,UAAC,GAA+C,EAAE,CAAC;QACjD,GAAG,CAAC,CAAC,CAAC,cACJ,QAAQ,UAAA,IACL,IAAI,CAAC,CAAC,CAAC,CACX,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CACvB,KAAiD,EACjD,KAAiD;IAEjD,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,uBAAK,KAAK,GAAK,KAAK,EAAE,CAAC;IAC/C,OAAO,IAAI,CAAC,MAAM,CAAC,UAAC,GAA+C,EAAE,CAAC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OAAO,OAAO,IAAI,cAAc,IAAI,EAAE,CAAC;AACzC,CAAC"}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { IntlConfig, IntlCache, CustomFormats, Formatters, IntlShape } from './types';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { FormatXMLElementFn } from 'intl-messageformat';
|
|
2
4
|
import { IntlRelativeTimeFormatOptions } from '@formatjs/intl-relativetimeformat';
|
|
3
5
|
export declare function filterProps<T extends Record<string, any>, K extends string>(props: T, whitelist: Array<K>, defaults?: Partial<T>): Pick<T, K>;
|
|
4
6
|
export declare function invariantIntlContext(intl?: any): asserts intl;
|
|
@@ -11,4 +13,11 @@ export declare function createIntlCache(): IntlCache;
|
|
|
11
13
|
*/
|
|
12
14
|
export declare function createFormatters(cache?: IntlCache): Formatters;
|
|
13
15
|
export declare function getNamedFormat<T extends keyof CustomFormats>(formats: CustomFormats, type: T, name: string, onError: IntlShape['onError']): Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | IntlRelativeTimeFormatOptions | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
18
|
+
* argument `parts` through, assigning unique key to each part, to prevent
|
|
19
|
+
* "Each child in a list should have a unique "key"" React error.
|
|
20
|
+
* @param formatXMLElementFn
|
|
21
|
+
*/
|
|
22
|
+
export declare function assignUniqueKeysToParts(formatXMLElementFn: FormatXMLElementFn<React.ReactNode>): typeof formatXMLElementFn;
|
|
14
23
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,UAAU,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,SAAS,EACV,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"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ACrC,kBAAkB,EAAE,kBAAkB,CAAC,KAAK,CAAC,SAAS,CAAC,GACtD,OAAO,kBAAkB,CAK3B"}
|
package/lib/utils.js
CHANGED
|
@@ -84,4 +84,16 @@ export function getNamedFormat(formats, type, name, onError) {
|
|
|
84
84
|
}
|
|
85
85
|
onError(new UnsupportedFormatterError("No " + type + " format named: " + name));
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
89
|
+
* argument `parts` through, assigning unique key to each part, to prevent
|
|
90
|
+
* "Each child in a list should have a unique "key"" React error.
|
|
91
|
+
* @param formatXMLElementFn
|
|
92
|
+
*/
|
|
93
|
+
export function assignUniqueKeysToParts(formatXMLElementFn) {
|
|
94
|
+
return function (parts) {
|
|
95
|
+
// eslint-disable-next-line prefer-rest-params
|
|
96
|
+
return formatXMLElementFn(React.Children.toArray(parts));
|
|
97
|
+
};
|
|
98
|
+
}
|
|
87
99
|
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AASF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AASF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,iBAAuC,MAAM,oBAAoB,CAAC;AACzE,OAAO,sBAAsB,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAC,yBAAyB,EAAC,MAAM,SAAS,CAAC;AAElD,MAAM,UAAU,WAAW,CACzB,KAAQ,EACR,SAAmB,EACnB,QAAyB;IAAzB,yBAAA,EAAA,aAAyB;IAEzB,O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AO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -133,18 +133,18 @@
|
|
|
133
133
|
"types": "./lib/react-intl.d.ts",
|
|
134
134
|
"sideEffects": false,
|
|
135
135
|
"dependencies": {
|
|
136
|
-
"@formatjs/intl-datetimeformat": "^
|
|
137
|
-
"@formatjs/intl-displaynames": "^
|
|
138
|
-
"@formatjs/intl-listformat": "^
|
|
139
|
-
"@formatjs/intl-numberformat": "^
|
|
140
|
-
"@formatjs/intl-relativetimeformat": "^
|
|
141
|
-
"@formatjs/intl-utils": "^3.
|
|
136
|
+
"@formatjs/intl-datetimeformat": "^2.0.2",
|
|
137
|
+
"@formatjs/intl-displaynames": "^3.0.2",
|
|
138
|
+
"@formatjs/intl-listformat": "^3.0.2",
|
|
139
|
+
"@formatjs/intl-numberformat": "^5.0.2",
|
|
140
|
+
"@formatjs/intl-relativetimeformat": "^6.0.2",
|
|
141
|
+
"@formatjs/intl-utils": "^3.6.0",
|
|
142
142
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
143
143
|
"@types/invariant": "^2.2.31",
|
|
144
144
|
"hoist-non-react-statics": "^3.3.2",
|
|
145
|
-
"intl-format-cache": "^4.2.
|
|
146
|
-
"intl-messageformat": "^
|
|
147
|
-
"intl-messageformat-parser": "^5.2.
|
|
145
|
+
"intl-format-cache": "^4.2.46",
|
|
146
|
+
"intl-messageformat": "^9.0.2",
|
|
147
|
+
"intl-messageformat-parser": "^5.2.4",
|
|
148
148
|
"shallow-equal": "^1.2.1"
|
|
149
149
|
},
|
|
150
150
|
"peerDependencies": {
|
|
@@ -167,7 +167,7 @@
|
|
|
167
167
|
"ie 11"
|
|
168
168
|
],
|
|
169
169
|
"devDependencies": {
|
|
170
|
-
"@formatjs/intl-pluralrules": "^
|
|
170
|
+
"@formatjs/intl-pluralrules": "^3.0.2",
|
|
171
171
|
"@microsoft/api-documenter": "^7.8.14",
|
|
172
172
|
"@types/benchmark": "^1.0.31",
|
|
173
173
|
"@types/enzyme": "^3.10.5",
|
|
@@ -197,5 +197,5 @@
|
|
|
197
197
|
"tslib": "^1.11.1",
|
|
198
198
|
"typescript": "3.8"
|
|
199
199
|
},
|
|
200
|
-
"gitHead": "
|
|
200
|
+
"gitHead": "315646645e3906f787df93b0d082ed9b98ad6f4f"
|
|
201
201
|
}
|
|
@@ -8,40 +8,11 @@ import * as React from 'react';
|
|
|
8
8
|
import {PrimitiveType, FormatXMLElementFn} from 'intl-messageformat';
|
|
9
9
|
import {Context} from './injectIntl';
|
|
10
10
|
import {MessageDescriptor} from '../types';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
invariantIntlContext,
|
|
14
|
-
DEFAULT_INTL_CONFIG,
|
|
15
|
-
createFormatters,
|
|
16
|
-
} from '../utils';
|
|
11
|
+
import {invariantIntlContext} from '../utils';
|
|
17
12
|
import * as shallowEquals_ from 'shallow-equal/objects';
|
|
18
13
|
const shallowEquals: typeof shallowEquals_ =
|
|
19
14
|
(shallowEquals_ as any).default || shallowEquals_;
|
|
20
15
|
|
|
21
|
-
function defaultFormatMessage<T = React.ReactNode>(
|
|
22
|
-
descriptor: MessageDescriptor,
|
|
23
|
-
values?: Record<
|
|
24
|
-
string,
|
|
25
|
-
PrimitiveType | React.ReactElement | FormatXMLElementFn<T, T>
|
|
26
|
-
>
|
|
27
|
-
): string {
|
|
28
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
29
|
-
console.error(
|
|
30
|
-
'[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry. Using default message as fallback.'
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return formatMessage(
|
|
35
|
-
{
|
|
36
|
-
...DEFAULT_INTL_CONFIG,
|
|
37
|
-
locale: 'en',
|
|
38
|
-
},
|
|
39
|
-
createFormatters(),
|
|
40
|
-
descriptor,
|
|
41
|
-
values as any
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
16
|
export interface Props<
|
|
46
17
|
V extends Record<string, any> = Record<string, React.ReactNode>
|
|
47
18
|
> extends MessageDescriptor {
|
|
@@ -73,14 +44,9 @@ class FormattedMessage<
|
|
|
73
44
|
return (
|
|
74
45
|
<Context.Consumer>
|
|
75
46
|
{(intl): React.ReactNode => {
|
|
76
|
-
|
|
77
|
-
invariantIntlContext(intl);
|
|
78
|
-
}
|
|
47
|
+
invariantIntlContext(intl);
|
|
79
48
|
|
|
80
|
-
const {
|
|
81
|
-
formatMessage = defaultFormatMessage,
|
|
82
|
-
textComponent: Text = React.Fragment,
|
|
83
|
-
} = intl || {};
|
|
49
|
+
const {formatMessage, textComponent: Text = React.Fragment} = intl;
|
|
84
50
|
const {
|
|
85
51
|
id,
|
|
86
52
|
description,
|
|
@@ -101,7 +67,7 @@ class FormattedMessage<
|
|
|
101
67
|
}
|
|
102
68
|
|
|
103
69
|
if (typeof children === 'function') {
|
|
104
|
-
return children(
|
|
70
|
+
return children(nodes);
|
|
105
71
|
}
|
|
106
72
|
|
|
107
73
|
if (Component) {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import {invariant} from '@formatjs/intl-utils';
|
|
9
|
+
import {assignUniqueKeysToParts} from '../utils';
|
|
9
10
|
|
|
10
11
|
import {
|
|
11
12
|
Formatters,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
import IntlMessageFormat, {
|
|
18
19
|
FormatXMLElementFn,
|
|
19
20
|
PrimitiveType,
|
|
21
|
+
isFormatXMLElementFn,
|
|
20
22
|
} from 'intl-messageformat';
|
|
21
23
|
import {MissingTranslationError, MessageFormatError} from '../error';
|
|
22
24
|
|
|
@@ -72,6 +74,21 @@ function deepMergeFormatsAndSetTimeZone(
|
|
|
72
74
|
};
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
export function assignUniqueKeysToFormatXMLElementFnArgument(
|
|
78
|
+
values: Record<
|
|
79
|
+
string,
|
|
80
|
+
PrimitiveType | React.ReactNode | FormatXMLElementFn<React.ReactNode>
|
|
81
|
+
>
|
|
82
|
+
): typeof values {
|
|
83
|
+
return Object.keys(values).reduce((acc: typeof values, k) => {
|
|
84
|
+
const v = values[k];
|
|
85
|
+
acc[k] = isFormatXMLElementFn<React.ReactNode>(v)
|
|
86
|
+
? assignUniqueKeysToParts(v)
|
|
87
|
+
: v;
|
|
88
|
+
return acc;
|
|
89
|
+
}, {});
|
|
90
|
+
}
|
|
91
|
+
|
|
75
92
|
function prepareIntlMessageFormatHtmlOutput(
|
|
76
93
|
chunks: React.ReactNode,
|
|
77
94
|
shouldWrap?: boolean
|
|
@@ -141,6 +158,8 @@ export function formatMessage(
|
|
|
141
158
|
if (!values && message && typeof message === 'string') {
|
|
142
159
|
return message.replace(/'\{(.*?)\}'/gi, `{$1}`);
|
|
143
160
|
}
|
|
161
|
+
const patchedValues =
|
|
162
|
+
values && assignUniqueKeysToFormatXMLElementFnArgument(values);
|
|
144
163
|
formats = deepMergeFormatsAndSetTimeZone(formats, timeZone);
|
|
145
164
|
defaultFormats = deepMergeFormatsAndSetTimeZone(defaultFormats, timeZone);
|
|
146
165
|
|
|
@@ -163,7 +182,7 @@ export function formatMessage(
|
|
|
163
182
|
);
|
|
164
183
|
|
|
165
184
|
return prepareIntlMessageFormatHtmlOutput(
|
|
166
|
-
formatter.format(
|
|
185
|
+
formatter.format(patchedValues),
|
|
167
186
|
wrapRichTextChunksInFragment
|
|
168
187
|
);
|
|
169
188
|
} catch (e) {
|
|
@@ -188,7 +207,7 @@ export function formatMessage(
|
|
|
188
207
|
});
|
|
189
208
|
|
|
190
209
|
return prepareIntlMessageFormatHtmlOutput(
|
|
191
|
-
formatter.format<React.ReactNode>(
|
|
210
|
+
formatter.format<React.ReactNode>(patchedValues),
|
|
192
211
|
wrapRichTextChunksInFragment
|
|
193
212
|
);
|
|
194
213
|
} catch (e) {
|
|
@@ -213,7 +232,7 @@ export function formatMessage(
|
|
|
213
232
|
);
|
|
214
233
|
|
|
215
234
|
return prepareIntlMessageFormatHtmlOutput(
|
|
216
|
-
formatter.format(
|
|
235
|
+
formatter.format(patchedValues),
|
|
217
236
|
wrapRichTextChunksInFragment
|
|
218
237
|
);
|
|
219
238
|
} catch (e) {
|
package/src/utils.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
IntlShape,
|
|
18
18
|
} from './types';
|
|
19
19
|
import * as React from 'react';
|
|
20
|
-
import IntlMessageFormat from 'intl-messageformat';
|
|
20
|
+
import IntlMessageFormat, {FormatXMLElementFn} from 'intl-messageformat';
|
|
21
21
|
import memoizeIntlConstructor from 'intl-format-cache';
|
|
22
22
|
import {invariant} from '@formatjs/intl-utils';
|
|
23
23
|
import {IntlRelativeTimeFormatOptions} from '@formatjs/intl-relativetimeformat';
|
|
@@ -134,3 +134,18 @@ export function getNamedFormat<T extends keyof CustomFormats>(
|
|
|
134
134
|
|
|
135
135
|
onError(new UnsupportedFormatterError(`No ${type} format named: ${name}`));
|
|
136
136
|
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
140
|
+
* argument `parts` through, assigning unique key to each part, to prevent
|
|
141
|
+
* "Each child in a list should have a unique "key"" React error.
|
|
142
|
+
* @param formatXMLElementFn
|
|
143
|
+
*/
|
|
144
|
+
export function assignUniqueKeysToParts(
|
|
145
|
+
formatXMLElementFn: FormatXMLElementFn<React.ReactNode>
|
|
146
|
+
): typeof formatXMLElementFn {
|
|
147
|
+
return function (parts) {
|
|
148
|
+
// eslint-disable-next-line prefer-rest-params
|
|
149
|
+
return formatXMLElementFn(React.Children.toArray(parts));
|
|
150
|
+
};
|
|
151
|
+
}
|