react-intl 8.0.10 → 8.0.11
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 +44 -34
- package/index.js +30 -21
- package/package.json +5 -5
- package/react-intl.iife.js +7318 -1963
- package/src/components/createFormattedComponent.d.ts +19 -19
- package/src/components/createFormattedComponent.js +53 -56
- package/src/components/createIntl.d.ts +12 -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 +43 -29
- package/src/components/injectIntl.js +35 -31
- package/src/components/message.d.ts +12 -7
- package/src/components/message.js +26 -25
- package/src/components/plural.d.ts +15 -10
- package/src/components/plural.js +22 -15
- package/src/components/provider.d.ts +29 -25
- package/src/components/provider.js +51 -57
- package/src/components/relative.d.ts +11 -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 +14 -9
- package/src/types.js +8 -1
- package/src/utils.d.ts +18 -18
- package/src/utils.js +60 -59
package/src/utils.js
CHANGED
|
@@ -1,70 +1,71 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "intl-messageformat";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import "./types.js";
|
|
4
|
+
import { DEFAULT_INTL_CONFIG as CORE_DEFAULT_INTL_CONFIG } from "@formatjs/intl";
|
|
2
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (!condition) {
|
|
8
|
-
throw new Err(message);
|
|
9
|
-
}
|
|
6
|
+
export function invariant(condition, message, Err = Error) {
|
|
7
|
+
if (!condition) {
|
|
8
|
+
throw new Err(message);
|
|
9
|
+
}
|
|
10
10
|
}
|
|
11
11
|
export function invariantIntlContext(intl) {
|
|
12
|
-
|
|
13
|
-
'<IntlProvider> needs to exist in the component ancestry.');
|
|
12
|
+
invariant(intl, "[React Intl] Could not find required `intl` object. " + "<IntlProvider> needs to exist in the component ancestry.");
|
|
14
13
|
}
|
|
15
|
-
export
|
|
14
|
+
export const DEFAULT_INTL_CONFIG = {
|
|
15
|
+
...CORE_DEFAULT_INTL_CONFIG,
|
|
16
|
+
textComponent: React.Fragment
|
|
17
|
+
};
|
|
16
18
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
* Builds an array of {@link React.ReactNode}s with index-based keys, similar to
|
|
20
|
+
* {@link React.Children.toArray}. However, this function tells React that it
|
|
21
|
+
* was intentional, so they won't produce a bunch of warnings about it.
|
|
22
|
+
*
|
|
23
|
+
* React doesn't recommend doing this because it makes reordering inefficient,
|
|
24
|
+
* but we mostly need this for message chunks, which don't tend to reorder to
|
|
25
|
+
* begin with.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
export const toKeyedReactNodeArray = (children) => {
|
|
29
|
+
const childrenArray = React.Children.toArray(children);
|
|
30
|
+
return childrenArray.map((child, index) => {
|
|
31
|
+
// For React elements, wrap in a keyed Fragment
|
|
32
|
+
// This creates a new element with a key rather than trying to add one after creation
|
|
33
|
+
if (React.isValidElement(child)) {
|
|
34
|
+
return /* @__PURE__ */ _jsx(React.Fragment, { children: child }, index);
|
|
35
|
+
}
|
|
36
|
+
return child;
|
|
37
|
+
});
|
|
36
38
|
};
|
|
37
39
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
* Takes a `formatXMLElementFn`, and composes it in function, which passes
|
|
41
|
+
* argument `parts` through, assigning unique key to each part, to prevent
|
|
42
|
+
* "Each child in a list should have a unique "key"" React error.
|
|
43
|
+
* @param formatXMLElementFn
|
|
44
|
+
*/
|
|
43
45
|
export function assignUniqueKeysToParts(formatXMLElementFn) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
return function(parts) {
|
|
47
|
+
// eslint-disable-next-line prefer-rest-params
|
|
48
|
+
return formatXMLElementFn(toKeyedReactNodeArray(parts));
|
|
49
|
+
};
|
|
48
50
|
}
|
|
49
51
|
export function shallowEqual(objA, objB) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return true;
|
|
52
|
+
if (objA === objB) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (!objA || !objB) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
var aKeys = Object.keys(objA);
|
|
59
|
+
var bKeys = Object.keys(objB);
|
|
60
|
+
var len = aKeys.length;
|
|
61
|
+
if (bKeys.length !== len) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
for (var i = 0; i < len; i++) {
|
|
65
|
+
var key = aKeys[i];
|
|
66
|
+
if (objA[key] !== objB[key] || !Object.prototype.hasOwnProperty.call(objB, key)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
70
71
|
}
|