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