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
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { FormatDateOptions, FormatDisplayNameOptions, FormatListOptions, FormatNumberOptions } from
|
|
2
|
-
import * as React from
|
|
3
|
-
import { IntlShape } from
|
|
1
|
+
import { type FormatDateOptions, type FormatDisplayNameOptions, type FormatListOptions, type FormatNumberOptions } from "@formatjs/intl";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { type IntlShape } from "../types.js";
|
|
4
4
|
type Formatter = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
formatDate: FormatDateOptions;
|
|
6
|
+
formatTime: FormatDateOptions;
|
|
7
|
+
formatNumber: FormatNumberOptions;
|
|
8
|
+
formatList: FormatListOptions;
|
|
9
|
+
formatDisplayName: FormatDisplayNameOptions;
|
|
10
10
|
};
|
|
11
|
-
export declare const FormattedNumberParts: React.FC<Formatter[
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export declare const FormattedNumberParts: React.FC<Formatter["formatNumber"] & {
|
|
12
|
+
value: Parameters<IntlShape["formatNumber"]>[0];
|
|
13
|
+
children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
|
|
14
14
|
}>;
|
|
15
|
-
export declare const FormattedListParts: React.FC<Formatter[
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export declare const FormattedListParts: React.FC<Formatter["formatList"] & {
|
|
16
|
+
value: Parameters<IntlShape["formatList"]>[0];
|
|
17
|
+
children(val: ReturnType<Intl.ListFormat["formatToParts"]>): React.ReactElement | null;
|
|
18
18
|
}>;
|
|
19
|
-
export declare function createFormattedDateTimePartsComponent<Name extends
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export declare function createFormattedDateTimePartsComponent<Name extends "formatDate" | "formatTime">(name: Name): React.FC<Formatter[Name] & {
|
|
20
|
+
value: Parameters<IntlShape[Name]>[0];
|
|
21
|
+
children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
|
|
22
22
|
}>;
|
|
23
23
|
export declare function createFormattedComponent<Name extends keyof Formatter>(name: Name): React.FC<Formatter[Name] & {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
value: Parameters<IntlShape[Name]>[0];
|
|
25
|
+
children?(val: string): React.ReactElement | null;
|
|
26
26
|
}>;
|
|
27
27
|
export {};
|
|
@@ -1,63 +1,60 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "@formatjs/intl";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import "../types.js";
|
|
4
|
+
import useIntl from "./useIntl.js";
|
|
2
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var value = props.value, children = props.children, formatProps = __rest(props, ["value", "children"]);
|
|
25
|
-
return children(intl.formatNumberToParts(value, formatProps));
|
|
6
|
+
var DisplayName = /* @__PURE__ */ function(DisplayName) {
|
|
7
|
+
DisplayName["formatDate"] = "FormattedDate";
|
|
8
|
+
DisplayName["formatTime"] = "FormattedTime";
|
|
9
|
+
DisplayName["formatNumber"] = "FormattedNumber";
|
|
10
|
+
DisplayName["formatList"] = "FormattedList";
|
|
11
|
+
// Note that this DisplayName is the locale display name, not to be confused with
|
|
12
|
+
// the name of the enum, which is for React component display name in dev tools.
|
|
13
|
+
DisplayName["formatDisplayName"] = "FormattedDisplayName";
|
|
14
|
+
return DisplayName;
|
|
15
|
+
}(DisplayName || {});
|
|
16
|
+
var DisplayNameParts = /* @__PURE__ */ function(DisplayNameParts) {
|
|
17
|
+
DisplayNameParts["formatDate"] = "FormattedDateParts";
|
|
18
|
+
DisplayNameParts["formatTime"] = "FormattedTimeParts";
|
|
19
|
+
DisplayNameParts["formatNumber"] = "FormattedNumberParts";
|
|
20
|
+
DisplayNameParts["formatList"] = "FormattedListParts";
|
|
21
|
+
return DisplayNameParts;
|
|
22
|
+
}(DisplayNameParts || {});
|
|
23
|
+
export const FormattedNumberParts = (props) => {
|
|
24
|
+
const intl = useIntl();
|
|
25
|
+
const { value, children, ...formatProps } = props;
|
|
26
|
+
return children(intl.formatNumberToParts(value, formatProps));
|
|
26
27
|
};
|
|
27
|
-
FormattedNumberParts.displayName =
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
FormattedNumberParts.displayName = "FormattedNumberParts";
|
|
29
|
+
export const FormattedListParts = (props) => {
|
|
30
|
+
const intl = useIntl();
|
|
31
|
+
const { value, children, ...formatProps } = props;
|
|
32
|
+
return children(intl.formatListToParts(value, formatProps));
|
|
32
33
|
};
|
|
33
|
-
FormattedNumberParts.displayName =
|
|
34
|
+
FormattedNumberParts.displayName = "FormattedNumberParts";
|
|
34
35
|
export function createFormattedDateTimePartsComponent(name) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
ComponentParts.displayName = DisplayNameParts[name];
|
|
45
|
-
return ComponentParts;
|
|
36
|
+
const ComponentParts = (props) => {
|
|
37
|
+
const intl = useIntl();
|
|
38
|
+
const { value, children, ...formatProps } = props;
|
|
39
|
+
const date = typeof value === "string" ? new Date(value || 0) : value;
|
|
40
|
+
const formattedParts = name === "formatDate" ? intl.formatDateToParts(date, formatProps) : intl.formatTimeToParts(date, formatProps);
|
|
41
|
+
return children(formattedParts);
|
|
42
|
+
};
|
|
43
|
+
ComponentParts.displayName = DisplayNameParts[name];
|
|
44
|
+
return ComponentParts;
|
|
46
45
|
}
|
|
47
46
|
export function createFormattedComponent(name) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Component.displayName = DisplayName[name];
|
|
62
|
-
return Component;
|
|
47
|
+
const Component = (props) => {
|
|
48
|
+
const intl = useIntl();
|
|
49
|
+
const { value, children, ...formatProps } = props;
|
|
50
|
+
// TODO: fix TS type definition for localeMatcher upstream
|
|
51
|
+
const formattedValue = intl[name](value, formatProps);
|
|
52
|
+
if (typeof children === "function") {
|
|
53
|
+
return children(formattedValue);
|
|
54
|
+
}
|
|
55
|
+
const Text = intl.textComponent || React.Fragment;
|
|
56
|
+
return /* @__PURE__ */ _jsx(Text, { children: formattedValue });
|
|
57
|
+
};
|
|
58
|
+
Component.displayName = DisplayName[name];
|
|
59
|
+
return Component;
|
|
63
60
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 { type CreateIntlFn } from "@formatjs/intl";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import type { IntlConfig, IntlShape } from "../types.js";
|
|
4
9
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
* Create intl object
|
|
11
|
+
* @param config intl config
|
|
12
|
+
* @param cache cache for formatter instances to prevent memory leak
|
|
13
|
+
*/
|
|
9
14
|
export declare const createIntl: CreateIntlFn<React.ReactNode, IntlConfig, IntlShape>;
|
|
@@ -1,58 +1,56 @@
|
|
|
1
1
|
/*
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import { DEFAULT_INTL_CONFIG, assignUniqueKeysToParts, toKeyedReactNodeArray
|
|
2
|
+
* Copyright 2015, Yahoo Inc.
|
|
3
|
+
* Copyrights licensed under the New BSD License.
|
|
4
|
+
* See the accompanying LICENSE file for terms.
|
|
5
|
+
*/
|
|
6
|
+
import { createIntl as coreCreateIntl, formatMessage as coreFormatMessage } from "@formatjs/intl";
|
|
7
|
+
import { isFormatXMLElementFn } from "intl-messageformat";
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { DEFAULT_INTL_CONFIG, assignUniqueKeysToParts, toKeyedReactNodeArray } from "../utils.js";
|
|
10
10
|
function assignUniqueKeysToFormatXMLElementFnArgument(values) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return acc;
|
|
20
|
-
}, {});
|
|
11
|
+
if (!values) {
|
|
12
|
+
return values;
|
|
13
|
+
}
|
|
14
|
+
return Object.keys(values).reduce((acc, k) => {
|
|
15
|
+
const v = values[k];
|
|
16
|
+
acc[k] = isFormatXMLElementFn(v) ? assignUniqueKeysToParts(v) : v;
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
formatters,
|
|
30
|
-
descriptor,
|
|
31
|
-
values], rest, false));
|
|
32
|
-
if (Array.isArray(chunks)) {
|
|
33
|
-
return toKeyedReactNodeArray(chunks);
|
|
34
|
-
}
|
|
35
|
-
return chunks;
|
|
20
|
+
const formatMessage = (config, formatters, descriptor, rawValues, ...rest) => {
|
|
21
|
+
const values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues);
|
|
22
|
+
const chunks = coreFormatMessage(config, formatters, descriptor, values, ...rest);
|
|
23
|
+
if (Array.isArray(chunks)) {
|
|
24
|
+
return toKeyedReactNodeArray(chunks);
|
|
25
|
+
}
|
|
26
|
+
return chunks;
|
|
36
27
|
};
|
|
37
28
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
29
|
+
* Create intl object
|
|
30
|
+
* @param config intl config
|
|
31
|
+
* @param cache cache for formatter instances to prevent memory leak
|
|
32
|
+
*/
|
|
33
|
+
export const createIntl = ({ defaultRichTextElements: rawDefaultRichTextElements, ...config }, cache) => {
|
|
34
|
+
const defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(rawDefaultRichTextElements);
|
|
35
|
+
const coreIntl = coreCreateIntl({
|
|
36
|
+
...DEFAULT_INTL_CONFIG,
|
|
37
|
+
...config,
|
|
38
|
+
defaultRichTextElements
|
|
39
|
+
}, cache);
|
|
40
|
+
const resolvedConfig = {
|
|
41
|
+
locale: coreIntl.locale,
|
|
42
|
+
timeZone: coreIntl.timeZone,
|
|
43
|
+
fallbackOnEmptyString: coreIntl.fallbackOnEmptyString,
|
|
44
|
+
formats: coreIntl.formats,
|
|
45
|
+
defaultLocale: coreIntl.defaultLocale,
|
|
46
|
+
defaultFormats: coreIntl.defaultFormats,
|
|
47
|
+
messages: coreIntl.messages,
|
|
48
|
+
onError: coreIntl.onError,
|
|
49
|
+
defaultRichTextElements
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
...coreIntl,
|
|
53
|
+
formatMessage: formatMessage.bind(null, resolvedConfig, coreIntl.formatters),
|
|
54
|
+
$t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters)
|
|
55
|
+
};
|
|
58
56
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { FormatDateTimeRangeOptions } from
|
|
2
|
-
import * as React from
|
|
1
|
+
import { type FormatDateTimeRangeOptions } from "@formatjs/intl";
|
|
2
|
+
import * as React from "react";
|
|
3
3
|
interface Props extends FormatDateTimeRangeOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
from: Parameters<Intl.DateTimeFormat["formatRange"]>[0];
|
|
5
|
+
to: Parameters<Intl.DateTimeFormat["formatRange"]>[1];
|
|
6
|
+
children?(value: React.ReactNode): React.ReactElement | null;
|
|
7
7
|
}
|
|
8
8
|
declare const FormattedDateTimeRange: React.FC<Props>;
|
|
9
9
|
export default FormattedDateTimeRange;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "@formatjs/intl";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import useIntl from "./useIntl.js";
|
|
2
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var Text = intl.textComponent || React.Fragment;
|
|
13
|
-
return _jsx(Text, { children: formattedValue });
|
|
5
|
+
const FormattedDateTimeRange = (props) => {
|
|
6
|
+
const intl = useIntl();
|
|
7
|
+
const { from, to, children, ...formatProps } = props;
|
|
8
|
+
const formattedValue = intl.formatDateTimeRange(from, to, formatProps);
|
|
9
|
+
if (typeof children === "function") {
|
|
10
|
+
return children(formattedValue);
|
|
11
|
+
}
|
|
12
|
+
const Text = intl.textComponent || React.Fragment;
|
|
13
|
+
return /* @__PURE__ */ _jsx(Text, { children: formattedValue });
|
|
14
14
|
};
|
|
15
|
-
FormattedDateTimeRange.displayName =
|
|
15
|
+
FormattedDateTimeRange.displayName = "FormattedDateTimeRange";
|
|
16
16
|
export default FormattedDateTimeRange;
|
|
@@ -1,39 +1,53 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { IntlShape } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type IntlShape } from "../types.js";
|
|
3
3
|
declare global {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
interface Window {
|
|
5
|
+
/**
|
|
6
|
+
* Set this to `true` prior to mounting to bypass using a globally-exposed context.
|
|
7
|
+
*/
|
|
8
|
+
__REACT_INTL_BYPASS_GLOBAL_CONTEXT__: boolean | undefined;
|
|
9
|
+
__REACT_INTL_CONTEXT__: React.Context<IntlShape> | undefined;
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
12
|
export declare const Provider: React.Provider<IntlShape>;
|
|
13
13
|
export declare const Context: React.Context<IntlShape>;
|
|
14
|
-
export interface Opts<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
export interface Opts<
|
|
15
|
+
IntlPropName extends string = "intl",
|
|
16
|
+
ForwardRef extends boolean = false
|
|
17
|
+
> {
|
|
18
|
+
intlPropName?: IntlPropName;
|
|
19
|
+
forwardRef?: ForwardRef;
|
|
20
|
+
enforceContext?: boolean;
|
|
18
21
|
}
|
|
19
|
-
export type WrappedComponentProps<IntlPropName extends string =
|
|
20
|
-
[k in IntlPropName]: IntlShape;
|
|
21
|
-
};
|
|
22
|
+
export type WrappedComponentProps<IntlPropName extends string = "intl"> = { [k in IntlPropName] : IntlShape };
|
|
22
23
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export type DistributedOmit<
|
|
24
|
+
* Utility type to help deal with the fact that `Omit` doesn't play well with unions:
|
|
25
|
+
* - https://github.com/microsoft/TypeScript/issues/31501
|
|
26
|
+
* - https://github.com/microsoft/TypeScript/issues/28339
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* DistributedOmit<X | Y, K> --> Omit<X, K> | Omit<Y, K>
|
|
30
|
+
*/
|
|
31
|
+
export type DistributedOmit<
|
|
32
|
+
T,
|
|
33
|
+
K extends PropertyKey
|
|
34
|
+
> = T extends unknown ? Omit<T, K> : never;
|
|
31
35
|
export type WithIntlProps<P> = DistributedOmit<P, keyof WrappedComponentProps> & {
|
|
32
|
-
|
|
36
|
+
forwardedRef?: React.Ref<any>;
|
|
33
37
|
};
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
// TODO: type hoisted static methods.
|
|
39
|
+
// Non ref forwarding overload
|
|
40
|
+
export default function injectIntl<
|
|
41
|
+
IntlPropName extends string = "intl",
|
|
42
|
+
P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>
|
|
43
|
+
>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, false>): React.FC<WithIntlProps<P>> & {
|
|
44
|
+
WrappedComponent: React.ComponentType<P>;
|
|
36
45
|
};
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
// Ref forwarding overload.
|
|
47
|
+
export default function injectIntl<
|
|
48
|
+
IntlPropName extends string = "intl",
|
|
49
|
+
P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>,
|
|
50
|
+
T extends React.ComponentType<P> = any
|
|
51
|
+
>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, true>): React.ForwardRefExoticComponent<React.PropsWithoutRef<WithIntlProps<React.PropsWithChildren<P>>> & React.RefAttributes<T>> & {
|
|
52
|
+
WrappedComponent: React.ComponentType<P>;
|
|
39
53
|
};
|
|
@@ -1,38 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import * as hoistNonReactStaticsNs from "hoist-non-react-statics";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import "../types.js";
|
|
4
|
+
import { invariantIntlContext } from "../utils.js";
|
|
3
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
-
|
|
5
|
-
import * as React from 'react';
|
|
6
|
-
import { invariantIntlContext } from '../utils.js';
|
|
7
|
-
var hoistNonReactStatics = (_a = hoistNonReactStaticsNs.default) !== null && _a !== void 0 ? _a : hoistNonReactStaticsNs;
|
|
6
|
+
const hoistNonReactStatics = hoistNonReactStaticsNs.default ?? hoistNonReactStaticsNs;
|
|
8
7
|
function getDisplayName(Component) {
|
|
9
|
-
|
|
8
|
+
return Component.displayName || Component.name || "Component";
|
|
10
9
|
}
|
|
11
10
|
// This is primarily dealing with packaging systems where multiple copies of react-intl
|
|
12
11
|
// might exist
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var IntlConsumer = IntlContext.Consumer, IntlProvider = IntlContext.Provider;
|
|
18
|
-
export var Provider = IntlProvider;
|
|
19
|
-
export var Context = IntlContext;
|
|
12
|
+
const IntlContext = typeof window !== "undefined" && !window.__REACT_INTL_BYPASS_GLOBAL_CONTEXT__ ? window.__REACT_INTL_CONTEXT__ || (window.__REACT_INTL_CONTEXT__ = React.createContext(null)) : React.createContext(null);
|
|
13
|
+
const { Consumer: IntlConsumer, Provider: IntlProvider } = IntlContext;
|
|
14
|
+
export const Provider = IntlProvider;
|
|
15
|
+
export const Context = IntlContext;
|
|
20
16
|
export default function injectIntl(WrappedComponent, options) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
17
|
+
const { intlPropName = "intl", forwardRef = false, enforceContext = true } = options || {};
|
|
18
|
+
const WithIntl = (props) => /* @__PURE__ */ _jsx(IntlConsumer, { children: (intl) => {
|
|
19
|
+
if (enforceContext) {
|
|
20
|
+
invariantIntlContext(intl);
|
|
21
|
+
}
|
|
22
|
+
const intlProp = { [intlPropName]: intl };
|
|
23
|
+
return /* @__PURE__ */ _jsx(WrappedComponent, {
|
|
24
|
+
...props,
|
|
25
|
+
...intlProp,
|
|
26
|
+
ref: forwardRef ? props.forwardedRef : null
|
|
27
|
+
});
|
|
28
|
+
} });
|
|
29
|
+
WithIntl.displayName = `injectIntl(${getDisplayName(WrappedComponent)})`;
|
|
30
|
+
WithIntl.WrappedComponent = WrappedComponent;
|
|
31
|
+
if (forwardRef) {
|
|
32
|
+
return hoistNonReactStatics(
|
|
33
|
+
// @ts-expect-error
|
|
34
|
+
React.forwardRef((props, ref) => /* @__PURE__ */ _jsx(WithIntl, {
|
|
35
|
+
...props,
|
|
36
|
+
forwardedRef: ref
|
|
37
|
+
})),
|
|
38
|
+
WrappedComponent
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return hoistNonReactStatics(WithIntl, WrappedComponent);
|
|
38
42
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 type { FormatXMLElementFn, Options as IntlMessageFormatOptions, PrimitiveType } from "intl-messageformat";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import { type MessageDescriptor } from "@formatjs/intl";
|
|
4
9
|
export interface Props<V extends Record<string, any> = Record<string, React.ReactNode | PrimitiveType | FormatXMLElementFn<React.ReactNode>>> extends MessageDescriptor {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
values?: V;
|
|
11
|
+
tagName?: React.ElementType<any>;
|
|
12
|
+
children?(nodes: React.ReactNode[]): React.ReactNode | null;
|
|
13
|
+
ignoreTag?: IntlMessageFormatOptions["ignoreTag"];
|
|
9
14
|
}
|
|
10
15
|
declare const MemoizedFormattedMessage: React.ComponentType<Props>;
|
|
11
16
|
export default MemoizedFormattedMessage;
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import "@formatjs/intl";
|
|
3
|
+
import { shallowEqual } from "../utils.js";
|
|
4
|
+
import useIntl from "./useIntl.js";
|
|
2
5
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import { shallowEqual } from '../utils.js';
|
|
5
|
-
import useIntl from './useIntl.js';
|
|
6
6
|
function areEqual(prevProps, nextProps) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
shallowEqual(otherProps, nextOtherProps));
|
|
7
|
+
const { values, ...otherProps } = prevProps;
|
|
8
|
+
const { values: nextValues, ...nextOtherProps } = nextProps;
|
|
9
|
+
return shallowEqual(nextValues, values) && shallowEqual(otherProps, nextOtherProps);
|
|
11
10
|
}
|
|
12
11
|
function FormattedMessage(props) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
const intl = useIntl();
|
|
13
|
+
const { formatMessage, textComponent: Text = React.Fragment } = intl;
|
|
14
|
+
const { id, description, defaultMessage, values, children, tagName: Component = Text, ignoreTag } = props;
|
|
15
|
+
const descriptor = {
|
|
16
|
+
id,
|
|
17
|
+
description,
|
|
18
|
+
defaultMessage
|
|
19
|
+
};
|
|
20
|
+
const nodes = formatMessage(descriptor, values, { ignoreTag });
|
|
21
|
+
if (typeof children === "function") {
|
|
22
|
+
return children(Array.isArray(nodes) ? nodes : [nodes]);
|
|
23
|
+
}
|
|
24
|
+
if (Component) {
|
|
25
|
+
return /* @__PURE__ */ _jsx(Component, { children: nodes });
|
|
26
|
+
}
|
|
27
|
+
return /* @__PURE__ */ _jsx(_Fragment, { children: nodes });
|
|
27
28
|
}
|
|
28
|
-
FormattedMessage.displayName =
|
|
29
|
-
|
|
30
|
-
MemoizedFormattedMessage.displayName =
|
|
29
|
+
FormattedMessage.displayName = "FormattedMessage";
|
|
30
|
+
const MemoizedFormattedMessage = React.memo(FormattedMessage, areEqual);
|
|
31
|
+
MemoizedFormattedMessage.displayName = "MemoizedFormattedMessage";
|
|
31
32
|
export default MemoizedFormattedMessage;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { type FormatPluralOptions } from "@formatjs/intl";
|
|
3
8
|
interface Props extends FormatPluralOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
value: number;
|
|
10
|
+
other: React.ReactNode;
|
|
11
|
+
zero?: React.ReactNode;
|
|
12
|
+
one?: React.ReactNode;
|
|
13
|
+
two?: React.ReactNode;
|
|
14
|
+
few?: React.ReactNode;
|
|
15
|
+
many?: React.ReactNode;
|
|
16
|
+
children?(value: React.ReactNode): React.ReactElement | null;
|
|
12
17
|
}
|
|
13
18
|
declare const FormattedPlural: React.FC<Props>;
|
|
14
19
|
export default FormattedPlural;
|