react-intl 10.1.0 → 10.1.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/index.d.ts CHANGED
@@ -1,50 +1,170 @@
1
- import { type NumberFormatOptions } from "@formatjs/ecma402-abstract";
2
- import { type CustomFormatConfig, type FormatDateOptions, type FormatTimeOptions, type MessageDescriptor } from "@formatjs/intl";
3
1
  import * as React from "react";
4
- import { createIntl } from "./src/components/createIntl.js";
5
- import { Context as IntlContext, Provider as RawIntlProvider } from "./src/components/context.js";
6
- import FormattedDateTimeRange from "./src/components/dateTimeRange.js";
7
- import FormattedMessage from "./src/components/message.js";
8
- import FormattedPlural from "./src/components/plural.js";
9
- import IntlProvider from "./src/components/provider.js";
10
- import FormattedRelativeTime from "./src/components/relative.js";
11
- import useIntl from "./src/components/useIntl.js";
12
- import { type IntlShape } from "./src/types.js";
13
- export { createIntlCache, type CustomFormatConfig, type CustomFormats, type FormatDateOptions, type FormatDisplayNameOptions, type FormatListOptions, type FormatNumberOptions, type FormatPluralOptions, type FormatRelativeTimeOptions, type Formatters, type IntlCache, type IntlFormatters, InvalidConfigError, type MessageDescriptor, MessageFormatError, MissingDataError, MissingTranslationError, IntlError as ReactIntlError, IntlErrorCode as ReactIntlErrorCode, UnsupportedFormatterError } from "@formatjs/intl";
14
- export { type IntlConfig, type IntlShape, type ResolvedIntlConfig } from "./src/types.js";
15
- export { createIntl, FormattedDateTimeRange, FormattedMessage, FormattedPlural, FormattedRelativeTime, IntlContext, IntlProvider, RawIntlProvider, useIntl };
16
- export declare function defineMessages<
17
- K extends keyof any,
18
- T = MessageDescriptor,
19
- U extends Record<K, T> = Record<K, T>
20
- >(msgs: U): U;
21
- export declare function defineMessage<T extends MessageDescriptor>(msg: T): T;
22
- export declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig<"date"> & {
23
- value: string | number | Date | undefined;
24
- children?(formattedDate: string): React.ReactElement | null;
25
- }>;
26
- export declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig<"time"> & {
27
- value: string | number | Date | undefined;
28
- children?(formattedTime: string): React.ReactElement | null;
29
- }>;
30
- export declare const FormattedNumber: React.FC<Omit<NumberFormatOptions, "localeMatcher"> & CustomFormatConfig<"number"> & {
31
- value: Parameters<IntlShape["formatNumber"]>[0];
32
- children?(formattedNumber: string): React.ReactElement | null;
33
- }>;
34
- export declare const FormattedList: React.FC<Intl.ListFormatOptions & {
35
- value: readonly React.ReactNode[];
36
- }>;
37
- export declare const FormattedDisplayName: React.FC<Intl.DisplayNamesOptions & {
38
- value: string;
39
- }>;
40
- export declare const FormattedDateParts: React.FC<FormatDateOptions & {
41
- value: Parameters<Intl.DateTimeFormat["format"]>[0] | string;
42
- children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
43
- }>;
44
- export declare const FormattedTimeParts: React.FC<FormatTimeOptions & {
45
- value: Parameters<Intl.DateTimeFormat["format"]>[0] | string;
46
- children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
47
- }>;
48
- export type { MessageFormatElement } from "@formatjs/icu-messageformat-parser";
49
- export type { PrimitiveType } from "intl-messageformat";
50
- export { FormattedListParts, FormattedNumberParts } from "./src/components/createFormattedComponent.js";
2
+ import { CreateIntlFn, CustomFormatConfig, CustomFormatConfig as CustomFormatConfig$1, CustomFormats, FormatDateOptions, FormatDateOptions as FormatDateOptions$1, FormatDateTimeRangeOptions, FormatDisplayNameOptions, FormatDisplayNameOptions as FormatDisplayNameOptions$1, FormatListOptions, FormatListOptions as FormatListOptions$1, FormatNumberOptions, FormatNumberOptions as FormatNumberOptions$1, FormatPluralOptions, FormatPluralOptions as FormatPluralOptions$1, FormatRelativeTimeOptions, FormatRelativeTimeOptions as FormatRelativeTimeOptions$1, FormatTimeOptions, Formatters, Formatters as Formatters$1, IntlCache, IntlError as ReactIntlError, IntlErrorCode as ReactIntlErrorCode, IntlFormatters, IntlFormatters as IntlFormatters$1, InvalidConfigError, MessageDescriptor, MessageDescriptor as MessageDescriptor$1, MessageFormatError, MissingDataError, MissingTranslationError, ResolvedIntlConfig as ResolvedIntlConfig$1, UnsupportedFormatterError, createIntlCache } from "@formatjs/intl";
3
+ import { FormatXMLElementFn, Options, PrimitiveType, PrimitiveType as PrimitiveType$1 } from "intl-messageformat";
4
+ import { MessageFormatElement } from "@formatjs/icu-messageformat-parser";
5
+
6
+ //#region packages/ecma402-abstract/types/number.d.ts
7
+ type NumberFormatNotation = "standard" | "scientific" | "engineering" | "compact";
8
+ type RoundingPriorityType = "auto" | "morePrecision" | "lessPrecision";
9
+ type RoundingModeType = "ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven";
10
+ type UseGroupingType = "min2" | "auto" | "always" | boolean;
11
+ interface NumberFormatDigitOptions {
12
+ minimumIntegerDigits?: number;
13
+ minimumSignificantDigits?: number;
14
+ maximumSignificantDigits?: number;
15
+ minimumFractionDigits?: number;
16
+ maximumFractionDigits?: number;
17
+ roundingPriority?: RoundingPriorityType;
18
+ roundingIncrement?: number;
19
+ roundingMode?: RoundingModeType;
20
+ trailingZeroDisplay?: TrailingZeroDisplay;
21
+ }
22
+ type NumberFormatOptionsLocaleMatcher = "lookup" | "best fit";
23
+ type NumberFormatOptionsStyle = "decimal" | "percent" | "currency" | "unit";
24
+ type NumberFormatOptionsCompactDisplay = "short" | "long";
25
+ type NumberFormatOptionsCurrencyDisplay = "symbol" | "code" | "name" | "narrowSymbol";
26
+ type NumberFormatOptionsCurrencySign = "standard" | "accounting";
27
+ type NumberFormatOptionsNotation = NumberFormatNotation;
28
+ type NumberFormatOptionsSignDisplay = "auto" | "always" | "never" | "exceptZero" | "negative";
29
+ type NumberFormatOptionsUnitDisplay = "long" | "short" | "narrow";
30
+ type TrailingZeroDisplay = "auto" | "stripIfInteger";
31
+ type NumberFormatOptions = Omit<Intl.NumberFormatOptions, "signDisplay" | "useGrouping"> & NumberFormatDigitOptions & {
32
+ localeMatcher?: NumberFormatOptionsLocaleMatcher;
33
+ style?: NumberFormatOptionsStyle;
34
+ compactDisplay?: NumberFormatOptionsCompactDisplay;
35
+ currencyDisplay?: NumberFormatOptionsCurrencyDisplay;
36
+ currencySign?: NumberFormatOptionsCurrencySign;
37
+ notation?: NumberFormatOptionsNotation;
38
+ signDisplay?: NumberFormatOptionsSignDisplay;
39
+ unit?: string;
40
+ unitDisplay?: NumberFormatOptionsUnitDisplay;
41
+ numberingSystem?: string;
42
+ trailingZeroDisplay?: TrailingZeroDisplay;
43
+ roundingPriority?: RoundingPriorityType;
44
+ roundingIncrement?: number;
45
+ roundingMode?: RoundingModeType;
46
+ useGrouping?: UseGroupingType;
47
+ };
48
+ //#endregion
49
+ //#region packages/react-intl/utils.d.ts
50
+ type DefaultIntlConfig = Pick<ResolvedIntlConfig, "fallbackOnEmptyString" | "formats" | "messages" | "timeZone" | "textComponent" | "defaultLocale" | "defaultFormats" | "onError">;
51
+ declare const DEFAULT_INTL_CONFIG$1: DefaultIntlConfig;
52
+ //#endregion
53
+ //#region packages/react-intl/types.d.ts
54
+ type IntlConfig = Omit<ResolvedIntlConfig, keyof typeof DEFAULT_INTL_CONFIG$1> & Partial<typeof DEFAULT_INTL_CONFIG$1>;
55
+ interface ResolvedIntlConfig extends ResolvedIntlConfig$1<React.ReactNode> {
56
+ textComponent?: React.ComponentType | keyof React.JSX.IntrinsicElements;
57
+ wrapRichTextChunksInFragment?: boolean;
58
+ }
59
+ interface IntlShape extends ResolvedIntlConfig, IntlFormatters$1<React.ReactNode> {
60
+ formatMessage(this: void, descriptor: MessageDescriptor$1, values?: Record<string, PrimitiveType$1 | FormatXMLElementFn<string, string>>, opts?: Options): string;
61
+ formatMessage(this: void, descriptor: MessageDescriptor$1, values?: Record<string, React.ReactNode | PrimitiveType$1 | FormatXMLElementFn<string, React.ReactNode>>, opts?: Options): Array<React.ReactNode>;
62
+ formatters: Formatters$1;
63
+ }
64
+ //#endregion
65
+ //#region packages/react-intl/components/createIntl.d.ts
66
+ /**
67
+ * Create intl object
68
+ * @param config intl config
69
+ * @param cache cache for formatter instances to prevent memory leak
70
+ */
71
+ declare const createIntl: CreateIntlFn<React.ReactNode, IntlConfig, IntlShape>;
72
+ //#endregion
73
+ //#region packages/react-intl/components/context.d.ts
74
+ declare const IntlContext: React.Context<IntlShape>;
75
+ declare const Provider: React.Provider<IntlShape>;
76
+ //#endregion
77
+ //#region packages/react-intl/components/dateTimeRange.d.ts
78
+ interface Props$3 extends FormatDateTimeRangeOptions {
79
+ from: Parameters<Intl.DateTimeFormat["formatRange"]>[0];
80
+ to: Parameters<Intl.DateTimeFormat["formatRange"]>[1];
81
+ children?(value: React.ReactNode): React.ReactElement | null;
82
+ }
83
+ declare const FormattedDateTimeRange: React.FC<Props$3>;
84
+ //#endregion
85
+ //#region packages/react-intl/components/message.d.ts
86
+ interface Props$2<V extends Record<string, any> = Record<string, React.ReactNode | PrimitiveType$1 | FormatXMLElementFn<React.ReactNode>>> extends MessageDescriptor$1 {
87
+ values?: V;
88
+ tagName?: React.ElementType<any>;
89
+ children?(nodes: React.ReactNode[]): React.ReactNode | null;
90
+ ignoreTag?: Options["ignoreTag"];
91
+ }
92
+ declare const MemoizedFormattedMessage: React.ComponentType<Props$2>;
93
+ //#endregion
94
+ //#region packages/react-intl/components/plural.d.ts
95
+ interface Props$1 extends FormatPluralOptions$1 {
96
+ value: number;
97
+ other: React.ReactNode;
98
+ zero?: React.ReactNode;
99
+ one?: React.ReactNode;
100
+ two?: React.ReactNode;
101
+ few?: React.ReactNode;
102
+ many?: React.ReactNode;
103
+ children?(value: React.ReactNode): React.ReactElement | null;
104
+ }
105
+ declare const FormattedPlural: React.FC<Props$1>;
106
+ //#endregion
107
+ //#region packages/react-intl/components/provider.d.ts
108
+ declare const IntlProvider: React.FC<React.PropsWithChildren<IntlConfig>>;
109
+ //#endregion
110
+ //#region packages/react-intl/components/relative.d.ts
111
+ interface Props extends FormatRelativeTimeOptions$1 {
112
+ value?: number;
113
+ unit?: Intl.RelativeTimeFormatUnit;
114
+ updateIntervalInSeconds?: number;
115
+ children?(value: string): React.ReactElement | null;
116
+ }
117
+ declare const FormattedRelativeTime: React.FC<Props>;
118
+ //#endregion
119
+ //#region packages/react-intl/components/useIntl.d.ts
120
+ declare function useIntl(this: void): IntlShape;
121
+ //#endregion
122
+ //#region packages/react-intl/components/createFormattedComponent.d.ts
123
+ type Formatter = {
124
+ formatDate: FormatDateOptions$1;
125
+ formatTime: FormatDateOptions$1;
126
+ formatNumber: FormatNumberOptions$1;
127
+ formatList: FormatListOptions$1;
128
+ formatDisplayName: FormatDisplayNameOptions$1;
129
+ };
130
+ declare const FormattedNumberParts: React.FC<Formatter["formatNumber"] & {
131
+ value: Parameters<IntlShape["formatNumber"]>[0];
132
+ children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
133
+ }>;
134
+ declare const FormattedListParts: React.FC<Formatter["formatList"] & {
135
+ value: Parameters<IntlShape["formatList"]>[0];
136
+ children(val: ReturnType<Intl.ListFormat["formatToParts"]>): React.ReactElement | null;
137
+ }>;
138
+ //#endregion
139
+ //#region packages/react-intl/index.d.ts
140
+ declare function defineMessages<K extends keyof any, T = MessageDescriptor$1, U extends Record<K, T> = Record<K, T>>(msgs: U): U;
141
+ declare function defineMessage<T extends MessageDescriptor$1>(msg: T): T;
142
+ declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig$1<"date"> & {
143
+ value: string | number | Date | undefined;
144
+ children?(formattedDate: string): React.ReactElement | null;
145
+ }>;
146
+ declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig$1<"time"> & {
147
+ value: string | number | Date | undefined;
148
+ children?(formattedTime: string): React.ReactElement | null;
149
+ }>;
150
+ declare const FormattedNumber: React.FC<Omit<NumberFormatOptions, "localeMatcher"> & CustomFormatConfig$1<"number"> & {
151
+ value: Parameters<IntlShape["formatNumber"]>[0];
152
+ children?(formattedNumber: string): React.ReactElement | null;
153
+ }>;
154
+ declare const FormattedList: React.FC<Intl.ListFormatOptions & {
155
+ value: readonly React.ReactNode[];
156
+ }>;
157
+ declare const FormattedDisplayName: React.FC<Intl.DisplayNamesOptions & {
158
+ value: string;
159
+ }>;
160
+ declare const FormattedDateParts: React.FC<FormatDateOptions$1 & {
161
+ value: Parameters<Intl.DateTimeFormat["format"]>[0] | string;
162
+ children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
163
+ }>;
164
+ declare const FormattedTimeParts: React.FC<FormatTimeOptions & {
165
+ value: Parameters<Intl.DateTimeFormat["format"]>[0] | string;
166
+ children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
167
+ }>;
168
+ //#endregion
169
+ export { type CustomFormatConfig, type CustomFormats, type FormatDateOptions, type FormatDisplayNameOptions, type FormatListOptions, type FormatNumberOptions, type FormatPluralOptions, type FormatRelativeTimeOptions, FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedList, FormattedListParts, MemoizedFormattedMessage as FormattedMessage, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, type Formatters, type IntlCache, type IntlConfig, IntlContext, type IntlFormatters, IntlProvider, type IntlShape, InvalidConfigError, type MessageDescriptor, type MessageFormatElement, MessageFormatError, MissingDataError, MissingTranslationError, type PrimitiveType, Provider as RawIntlProvider, ReactIntlError, ReactIntlErrorCode, type ResolvedIntlConfig, UnsupportedFormatterError, createIntl, createIntlCache, defineMessage, defineMessages, useIntl };
170
+ //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,36 +1,352 @@
1
1
  "use client";
2
- /*
3
- * Copyright 2015, Yahoo Inc.
4
- * Copyrights licensed under the New BSD License.
5
- * See the accompanying LICENSE file for terms.
6
- */
7
- import "@formatjs/ecma402-abstract";
8
- import "@formatjs/intl";
9
2
  import * as React from "react";
10
- import { createFormattedComponent, createFormattedDateTimePartsComponent } from "./src/components/createFormattedComponent.js";
11
- import { createIntl } from "./src/components/createIntl.js";
12
- import { Context as IntlContext, Provider as RawIntlProvider } from "./src/components/context.js";
13
- import FormattedDateTimeRange from "./src/components/dateTimeRange.js";
14
- import FormattedMessage from "./src/components/message.js";
15
- import FormattedPlural from "./src/components/plural.js";
16
- import IntlProvider from "./src/components/provider.js";
17
- import FormattedRelativeTime from "./src/components/relative.js";
18
- import useIntl from "./src/components/useIntl.js";
19
- import "./src/types.js";
20
- export { createIntlCache, InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, IntlError as ReactIntlError, IntlErrorCode as ReactIntlErrorCode, UnsupportedFormatterError } from "@formatjs/intl";
21
- export { createIntl, FormattedDateTimeRange, FormattedMessage, FormattedPlural, FormattedRelativeTime, IntlContext, IntlProvider, RawIntlProvider, useIntl };
22
- export function defineMessages(msgs) {
3
+ import { DEFAULT_INTL_CONFIG, IntlError as ReactIntlError, IntlErrorCode as ReactIntlErrorCode, InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, UnsupportedFormatterError, createIntl as createIntl$1, createIntlCache, createIntlCache as createIntlCache$1, formatMessage } from "@formatjs/intl";
4
+ import { Fragment, jsx } from "react/jsx-runtime";
5
+ import { isFormatXMLElementFn } from "intl-messageformat";
6
+ //#region packages/react-intl/utils.tsx
7
+ function invariant(condition, message, Err = Error) {
8
+ if (!condition) throw new Err(message);
9
+ }
10
+ function invariantIntlContext(intl) {
11
+ invariant(intl, "[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.");
12
+ }
13
+ const DEFAULT_INTL_CONFIG$1 = {
14
+ ...DEFAULT_INTL_CONFIG,
15
+ textComponent: React.Fragment
16
+ };
17
+ /**
18
+ * Builds an array of {@link React.ReactNode}s with index-based keys, similar to
19
+ * {@link React.Children.toArray}. However, this function tells React that it
20
+ * was intentional, so they won't produce a bunch of warnings about it.
21
+ *
22
+ * React doesn't recommend doing this because it makes reordering inefficient,
23
+ * but we mostly need this for message chunks, which don't tend to reorder to
24
+ * begin with.
25
+ *
26
+ */
27
+ const toKeyedReactNodeArray = (children) => {
28
+ return React.Children.toArray(children).map((child, index) => {
29
+ if (React.isValidElement(child)) return /* @__PURE__ */ jsx(React.Fragment, { children: child }, index);
30
+ return child;
31
+ });
32
+ };
33
+ /**
34
+ * Takes a `formatXMLElementFn`, and composes it in function, which passes
35
+ * argument `parts` through, assigning unique key to each part, to prevent
36
+ * "Each child in a list should have a unique "key"" React error.
37
+ * @param formatXMLElementFn
38
+ */
39
+ function assignUniqueKeysToParts(formatXMLElementFn) {
40
+ return function(parts) {
41
+ return formatXMLElementFn(toKeyedReactNodeArray(parts));
42
+ };
43
+ }
44
+ function shallowEqual(objA, objB) {
45
+ if (objA === objB) return true;
46
+ if (!objA || !objB) return false;
47
+ var aKeys = Object.keys(objA);
48
+ var bKeys = Object.keys(objB);
49
+ var len = aKeys.length;
50
+ if (bKeys.length !== len) return false;
51
+ for (var i = 0; i < len; i++) {
52
+ var key = aKeys[i];
53
+ if (objA[key] !== objB[key] || !Object.prototype.hasOwnProperty.call(objB, key)) return false;
54
+ }
55
+ return true;
56
+ }
57
+ //#endregion
58
+ //#region packages/react-intl/components/context.ts
59
+ const IntlContext = React.createContext(null);
60
+ const Provider = IntlContext.Provider;
61
+ //#endregion
62
+ //#region packages/react-intl/components/useIntl.ts
63
+ function useIntl() {
64
+ const intl = React.useContext(IntlContext);
65
+ invariantIntlContext(intl);
66
+ return intl;
67
+ }
68
+ //#endregion
69
+ //#region packages/react-intl/components/createFormattedComponent.tsx
70
+ var DisplayName = /* @__PURE__ */ function(DisplayName) {
71
+ DisplayName["formatDate"] = "FormattedDate";
72
+ DisplayName["formatTime"] = "FormattedTime";
73
+ DisplayName["formatNumber"] = "FormattedNumber";
74
+ DisplayName["formatList"] = "FormattedList";
75
+ DisplayName["formatDisplayName"] = "FormattedDisplayName";
76
+ return DisplayName;
77
+ }(DisplayName || {});
78
+ var DisplayNameParts = /* @__PURE__ */ function(DisplayNameParts) {
79
+ DisplayNameParts["formatDate"] = "FormattedDateParts";
80
+ DisplayNameParts["formatTime"] = "FormattedTimeParts";
81
+ DisplayNameParts["formatNumber"] = "FormattedNumberParts";
82
+ DisplayNameParts["formatList"] = "FormattedListParts";
83
+ return DisplayNameParts;
84
+ }(DisplayNameParts || {});
85
+ const FormattedNumberParts = (props) => {
86
+ const intl = useIntl();
87
+ const { value, children, ...formatProps } = props;
88
+ return children(intl.formatNumberToParts(value, formatProps));
89
+ };
90
+ FormattedNumberParts.displayName = "FormattedNumberParts";
91
+ const FormattedListParts = (props) => {
92
+ const intl = useIntl();
93
+ const { value, children, ...formatProps } = props;
94
+ return children(intl.formatListToParts(value, formatProps));
95
+ };
96
+ FormattedNumberParts.displayName = "FormattedNumberParts";
97
+ function createFormattedDateTimePartsComponent(name) {
98
+ const ComponentParts = (props) => {
99
+ const intl = useIntl();
100
+ const { value, children, ...formatProps } = props;
101
+ const date = typeof value === "string" ? new Date(value || 0) : value;
102
+ return children(name === "formatDate" ? intl.formatDateToParts(date, formatProps) : intl.formatTimeToParts(date, formatProps));
103
+ };
104
+ ComponentParts.displayName = DisplayNameParts[name];
105
+ return ComponentParts;
106
+ }
107
+ function createFormattedComponent(name) {
108
+ const Component = (props) => {
109
+ const intl = useIntl();
110
+ const { value, children, ...formatProps } = props;
111
+ const formattedValue = intl[name](value, formatProps);
112
+ if (typeof children === "function") return children(formattedValue);
113
+ return /* @__PURE__ */ jsx(intl.textComponent || React.Fragment, { children: formattedValue });
114
+ };
115
+ Component.displayName = DisplayName[name];
116
+ return Component;
117
+ }
118
+ //#endregion
119
+ //#region packages/react-intl/components/createIntl.ts
120
+ function assignUniqueKeysToFormatXMLElementFnArgument(values) {
121
+ if (!values) return values;
122
+ return Object.keys(values).reduce((acc, k) => {
123
+ const v = values[k];
124
+ acc[k] = isFormatXMLElementFn(v) ? assignUniqueKeysToParts(v) : v;
125
+ return acc;
126
+ }, {});
127
+ }
128
+ const formatMessage$1 = (config, formatters, descriptor, rawValues, ...rest) => {
129
+ const chunks = formatMessage(config, formatters, descriptor, assignUniqueKeysToFormatXMLElementFnArgument(rawValues), ...rest);
130
+ if (Array.isArray(chunks)) return toKeyedReactNodeArray(chunks);
131
+ return chunks;
132
+ };
133
+ /**
134
+ * Create intl object
135
+ * @param config intl config
136
+ * @param cache cache for formatter instances to prevent memory leak
137
+ */
138
+ const createIntl = ({ defaultRichTextElements: rawDefaultRichTextElements, ...config }, cache) => {
139
+ const defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(rawDefaultRichTextElements);
140
+ const coreIntl = createIntl$1({
141
+ ...DEFAULT_INTL_CONFIG$1,
142
+ ...config,
143
+ defaultRichTextElements
144
+ }, cache);
145
+ const resolvedConfig = {
146
+ locale: coreIntl.locale,
147
+ timeZone: coreIntl.timeZone,
148
+ fallbackOnEmptyString: coreIntl.fallbackOnEmptyString,
149
+ formats: coreIntl.formats,
150
+ defaultLocale: coreIntl.defaultLocale,
151
+ defaultFormats: coreIntl.defaultFormats,
152
+ messages: coreIntl.messages,
153
+ onError: coreIntl.onError,
154
+ defaultRichTextElements
155
+ };
156
+ return {
157
+ ...coreIntl,
158
+ formatMessage: formatMessage$1.bind(null, resolvedConfig, coreIntl.formatters),
159
+ $t: formatMessage$1.bind(null, resolvedConfig, coreIntl.formatters)
160
+ };
161
+ };
162
+ //#endregion
163
+ //#region packages/react-intl/components/dateTimeRange.tsx
164
+ const FormattedDateTimeRange = (props) => {
165
+ const intl = useIntl();
166
+ const { from, to, children, ...formatProps } = props;
167
+ const formattedValue = intl.formatDateTimeRange(from, to, formatProps);
168
+ if (typeof children === "function") return children(formattedValue);
169
+ return /* @__PURE__ */ jsx(intl.textComponent || React.Fragment, { children: formattedValue });
170
+ };
171
+ FormattedDateTimeRange.displayName = "FormattedDateTimeRange";
172
+ //#endregion
173
+ //#region packages/react-intl/components/message.tsx
174
+ function areEqual(prevProps, nextProps) {
175
+ const { values, ...otherProps } = prevProps;
176
+ const { values: nextValues, ...nextOtherProps } = nextProps;
177
+ return shallowEqual(nextValues, values) && shallowEqual(otherProps, nextOtherProps);
178
+ }
179
+ function FormattedMessage(props) {
180
+ const { formatMessage, textComponent: Text = React.Fragment } = useIntl();
181
+ const { id, description, defaultMessage, values, children, tagName: Component = Text, ignoreTag } = props;
182
+ const nodes = formatMessage({
183
+ id,
184
+ description,
185
+ defaultMessage
186
+ }, values, { ignoreTag });
187
+ if (typeof children === "function") return children(Array.isArray(nodes) ? nodes : [nodes]);
188
+ if (Component) return /* @__PURE__ */ jsx(Component, { children: nodes });
189
+ return /* @__PURE__ */ jsx(Fragment, { children: nodes });
190
+ }
191
+ FormattedMessage.displayName = "FormattedMessage";
192
+ const MemoizedFormattedMessage = React.memo(FormattedMessage, areEqual);
193
+ MemoizedFormattedMessage.displayName = "MemoizedFormattedMessage";
194
+ //#endregion
195
+ //#region packages/react-intl/components/plural.tsx
196
+ const FormattedPlural = (props) => {
197
+ const { formatPlural, textComponent: Text } = useIntl();
198
+ const { value, other, children } = props;
199
+ const formattedPlural = props[formatPlural(value, props)] || other;
200
+ if (typeof children === "function") return children(formattedPlural);
201
+ if (Text) return /* @__PURE__ */ jsx(Text, { children: formattedPlural });
202
+ return formattedPlural;
203
+ };
204
+ FormattedPlural.displayName = "FormattedPlural";
205
+ //#endregion
206
+ //#region packages/react-intl/components/provider.tsx
207
+ function processIntlConfig(config) {
208
+ return {
209
+ locale: config.locale,
210
+ timeZone: config.timeZone,
211
+ fallbackOnEmptyString: config.fallbackOnEmptyString,
212
+ formats: config.formats,
213
+ textComponent: config.textComponent,
214
+ messages: config.messages,
215
+ defaultLocale: config.defaultLocale,
216
+ defaultFormats: config.defaultFormats,
217
+ onError: config.onError,
218
+ onWarn: config.onWarn,
219
+ wrapRichTextChunksInFragment: config.wrapRichTextChunksInFragment,
220
+ defaultRichTextElements: config.defaultRichTextElements
221
+ };
222
+ }
223
+ function IntlProviderImpl(props) {
224
+ const cacheRef = React.useRef(createIntlCache$1());
225
+ const prevConfigRef = React.useRef(void 0);
226
+ const intlRef = React.useRef(void 0);
227
+ const filteredProps = {};
228
+ for (const key in props) if (props[key] !== void 0) filteredProps[key] = props[key];
229
+ const config = processIntlConfig({
230
+ ...DEFAULT_INTL_CONFIG$1,
231
+ ...filteredProps
232
+ });
233
+ if (!prevConfigRef.current || !shallowEqual(prevConfigRef.current, config)) {
234
+ prevConfigRef.current = config;
235
+ intlRef.current = createIntl(config, cacheRef.current);
236
+ }
237
+ invariantIntlContext(intlRef.current);
238
+ return /* @__PURE__ */ jsx(Provider, {
239
+ value: intlRef.current,
240
+ children: props.children
241
+ });
242
+ }
243
+ IntlProviderImpl.displayName = "IntlProvider";
244
+ const IntlProvider = IntlProviderImpl;
245
+ //#endregion
246
+ //#region packages/react-intl/components/relative.tsx
247
+ const MINUTE = 60;
248
+ const HOUR = 3600;
249
+ const DAY = 3600 * 24;
250
+ function selectUnit(seconds) {
251
+ const absValue = Math.abs(seconds);
252
+ if (absValue < MINUTE) return "second";
253
+ if (absValue < HOUR) return "minute";
254
+ if (absValue < DAY) return "hour";
255
+ return "day";
256
+ }
257
+ function getDurationInSeconds(unit) {
258
+ switch (unit) {
259
+ case "second": return 1;
260
+ case "minute": return MINUTE;
261
+ case "hour": return HOUR;
262
+ default: return DAY;
263
+ }
264
+ }
265
+ function valueToSeconds(value, unit) {
266
+ if (!value) return 0;
267
+ switch (unit) {
268
+ case "second": return value;
269
+ case "minute": return value * MINUTE;
270
+ default: return value * HOUR;
271
+ }
272
+ }
273
+ const INCREMENTABLE_UNITS = [
274
+ "second",
275
+ "minute",
276
+ "hour"
277
+ ];
278
+ function canIncrement(unit = "second") {
279
+ return INCREMENTABLE_UNITS.indexOf(unit) > -1;
280
+ }
281
+ const SimpleFormattedRelativeTime = (props) => {
282
+ const { formatRelativeTime, textComponent: Text } = useIntl();
283
+ const { children, value, unit, ...otherProps } = props;
284
+ const formattedRelativeTime = formatRelativeTime(value || 0, unit, otherProps);
285
+ if (typeof children === "function") return children(formattedRelativeTime);
286
+ if (Text) return /* @__PURE__ */ jsx(Text, { children: formattedRelativeTime });
287
+ return /* @__PURE__ */ jsx(Fragment, { children: formattedRelativeTime });
288
+ };
289
+ const FormattedRelativeTime = ({ value = 0, unit = "second", updateIntervalInSeconds, ...otherProps }) => {
290
+ invariant(!updateIntervalInSeconds || !!(updateIntervalInSeconds && canIncrement(unit)), "Cannot schedule update with unit longer than hour");
291
+ const [prevUnit, setPrevUnit] = React.useState();
292
+ const [prevValue, setPrevValue] = React.useState(0);
293
+ const [currentValueInSeconds, setCurrentValueInSeconds] = React.useState(0);
294
+ const updateTimer = React.useRef(void 0);
295
+ if (unit !== prevUnit || value !== prevValue) {
296
+ setPrevValue(value || 0);
297
+ setPrevUnit(unit);
298
+ setCurrentValueInSeconds(canIncrement(unit) ? valueToSeconds(value, unit) : 0);
299
+ }
300
+ React.useEffect(() => {
301
+ function clearUpdateTimer() {
302
+ clearTimeout(updateTimer.current);
303
+ }
304
+ clearUpdateTimer();
305
+ if (!updateIntervalInSeconds || !canIncrement(unit)) return clearUpdateTimer;
306
+ const nextValueInSeconds = currentValueInSeconds - updateIntervalInSeconds;
307
+ const nextUnit = selectUnit(nextValueInSeconds);
308
+ if (nextUnit === "day") return clearUpdateTimer;
309
+ const unitDuration = getDurationInSeconds(nextUnit);
310
+ const prevInterestingValueInSeconds = nextValueInSeconds - nextValueInSeconds % unitDuration;
311
+ const nextInterestingValueInSeconds = prevInterestingValueInSeconds >= currentValueInSeconds ? prevInterestingValueInSeconds - unitDuration : prevInterestingValueInSeconds;
312
+ const delayInSeconds = Math.abs(nextInterestingValueInSeconds - currentValueInSeconds);
313
+ if (currentValueInSeconds !== nextInterestingValueInSeconds) updateTimer.current = setTimeout(() => setCurrentValueInSeconds(nextInterestingValueInSeconds), delayInSeconds * 1e3);
314
+ return clearUpdateTimer;
315
+ }, [
316
+ currentValueInSeconds,
317
+ updateIntervalInSeconds,
318
+ unit
319
+ ]);
320
+ let currentValue = value || 0;
321
+ let currentUnit = unit;
322
+ if (canIncrement(unit) && typeof currentValueInSeconds === "number" && updateIntervalInSeconds) {
323
+ currentUnit = selectUnit(currentValueInSeconds);
324
+ const unitDuration = getDurationInSeconds(currentUnit);
325
+ currentValue = Math.round(currentValueInSeconds / unitDuration);
326
+ }
327
+ return /* @__PURE__ */ jsx(SimpleFormattedRelativeTime, {
328
+ value: currentValue,
329
+ unit: currentUnit,
330
+ ...otherProps
331
+ });
332
+ };
333
+ FormattedRelativeTime.displayName = "FormattedRelativeTime";
334
+ //#endregion
335
+ //#region packages/react-intl/index.ts
336
+ function defineMessages(msgs) {
23
337
  return msgs;
24
338
  }
25
- export function defineMessage(msg) {
339
+ function defineMessage(msg) {
26
340
  return msg;
27
341
  }
28
- // IMPORTANT: Explicit here to prevent api-extractor from outputing `import('./src/types').CustomFormatConfig`
29
- export const FormattedDate = createFormattedComponent("formatDate");
30
- export const FormattedTime = createFormattedComponent("formatTime");
31
- export const FormattedNumber = createFormattedComponent("formatNumber");
32
- export const FormattedList = createFormattedComponent("formatList");
33
- export const FormattedDisplayName = createFormattedComponent("formatDisplayName");
34
- export const FormattedDateParts = createFormattedDateTimePartsComponent("formatDate");
35
- export const FormattedTimeParts = createFormattedDateTimePartsComponent("formatTime");
36
- export { FormattedListParts, FormattedNumberParts } from "./src/components/createFormattedComponent.js";
342
+ const FormattedDate = createFormattedComponent("formatDate");
343
+ const FormattedTime = createFormattedComponent("formatTime");
344
+ const FormattedNumber = createFormattedComponent("formatNumber");
345
+ const FormattedList = createFormattedComponent("formatList");
346
+ const FormattedDisplayName = createFormattedComponent("formatDisplayName");
347
+ const FormattedDateParts = createFormattedDateTimePartsComponent("formatDate");
348
+ const FormattedTimeParts = createFormattedDateTimePartsComponent("formatTime");
349
+ //#endregion
350
+ export { FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedList, FormattedListParts, MemoizedFormattedMessage as FormattedMessage, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, IntlContext, IntlProvider, InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, Provider as RawIntlProvider, ReactIntlError, ReactIntlErrorCode, UnsupportedFormatterError, createIntl, createIntlCache, defineMessage, defineMessages, useIntl };
351
+
352
+ //# sourceMappingURL=index.js.map