react-intl 10.1.7 → 10.1.8

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.js CHANGED
@@ -93,7 +93,7 @@ const FormattedListParts = (props) => {
93
93
  const { value, children, ...formatProps } = props;
94
94
  return children(intl.formatListToParts(value, formatProps));
95
95
  };
96
- FormattedNumberParts.displayName = "FormattedNumberParts";
96
+ FormattedListParts.displayName = "FormattedListParts";
97
97
  function createFormattedDateTimePartsComponent(name) {
98
98
  const ComponentParts = (props) => {
99
99
  const intl = useIntl();
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["DEFAULT_INTL_CONFIG","CORE_DEFAULT_INTL_CONFIG","Context","formatMessage","coreFormatMessage","coreCreateIntl","DEFAULT_INTL_CONFIG","createIntlCache","DEFAULT_INTL_CONFIG"],"sources":["../utils.tsx","../components/context.ts","../components/useIntl.ts","../components/createFormattedComponent.tsx","../components/createIntl.ts","../components/dateTimeRange.tsx","../components/message.tsx","../components/plural.tsx","../components/provider.tsx","../components/relative.tsx","../index.ts"],"sourcesContent":["import {type FormatXMLElementFn} from 'intl-messageformat'\nimport * as React from 'react'\nimport {type ResolvedIntlConfig} from '#packages/react-intl/types.js'\n\nimport {DEFAULT_INTL_CONFIG as CORE_DEFAULT_INTL_CONFIG} from '@formatjs/intl'\n\nexport function invariant(\n condition: boolean,\n message: string,\n Err: any = Error\n): asserts condition {\n if (!condition) {\n throw new Err(message)\n }\n}\n\nexport function invariantIntlContext(intl?: any): asserts intl {\n invariant(\n intl,\n '[React Intl] Could not find required `intl` object. ' +\n '<IntlProvider> needs to exist in the component ancestry.'\n )\n}\n\nexport type DefaultIntlConfig = Pick<\n ResolvedIntlConfig,\n | 'fallbackOnEmptyString'\n | 'formats'\n | 'messages'\n | 'timeZone'\n | 'textComponent'\n | 'defaultLocale'\n | 'defaultFormats'\n | 'onError'\n>\n\nexport const DEFAULT_INTL_CONFIG: DefaultIntlConfig = {\n ...CORE_DEFAULT_INTL_CONFIG,\n textComponent: React.Fragment,\n}\n\n/**\n * Builds an array of {@link React.ReactNode}s with index-based keys, similar to\n * {@link React.Children.toArray}. However, this function tells React that it\n * was intentional, so they won't produce a bunch of warnings about it.\n *\n * React doesn't recommend doing this because it makes reordering inefficient,\n * but we mostly need this for message chunks, which don't tend to reorder to\n * begin with.\n *\n */\nexport const toKeyedReactNodeArray: typeof React.Children.toArray =\n children => {\n const childrenArray = React.Children.toArray(children)\n\n return childrenArray.map((child, index) => {\n // For React elements, wrap in a keyed Fragment\n // This creates a new element with a key rather than trying to add one after creation\n if (React.isValidElement(child)) {\n return <React.Fragment key={index}>{child}</React.Fragment>\n }\n return child\n })\n }\n\n/**\n * Takes a `formatXMLElementFn`, and composes it in function, which passes\n * argument `parts` through, assigning unique key to each part, to prevent\n * \"Each child in a list should have a unique \"key\"\" React error.\n * @param formatXMLElementFn\n */\nexport function assignUniqueKeysToParts(\n formatXMLElementFn: FormatXMLElementFn<React.ReactNode>\n): FormatXMLElementFn<React.ReactNode> {\n return function (parts: any) {\n // eslint-disable-next-line prefer-rest-params\n return formatXMLElementFn(toKeyedReactNodeArray(parts)) as any\n }\n}\n\nexport function shallowEqual<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(objA?: T, objB?: T): boolean {\n if (objA === objB) {\n return true\n }\n\n if (!objA || !objB) {\n return false\n }\n\n var aKeys = Object.keys(objA)\n var bKeys = Object.keys(objB)\n var len = aKeys.length\n\n if (bKeys.length !== len) {\n return false\n }\n\n for (var i = 0; i < len; i++) {\n var key = aKeys[i]\n\n if (\n objA[key] !== objB[key] ||\n !Object.prototype.hasOwnProperty.call(objB, key)\n ) {\n return false\n }\n }\n\n return true\n}\n","import * as React from 'react'\nimport {type IntlShape} from '#packages/react-intl/types.js'\n\nconst IntlContext: React.Context<IntlShape> = React.createContext<IntlShape>(\n null as any\n)\nconst Provider: React.Provider<IntlShape> = IntlContext.Provider\n\nexport {Provider, IntlContext as Context}\n","import * as React from 'react'\nimport {type IntlShape} from '#packages/react-intl/types.js'\nimport {invariantIntlContext} from '#packages/react-intl/utils.js'\nimport {Context} from '#packages/react-intl/components/context.js'\n\nexport default function useIntl(this: void): IntlShape {\n const intl = React.useContext(Context)\n invariantIntlContext(intl)\n return intl\n}\n","import {\n type FormatDateOptions,\n type FormatDisplayNameOptions,\n type FormatListOptions,\n type FormatNumberOptions,\n} from '@formatjs/intl'\nimport * as React from 'react'\nimport {type IntlShape} from '#packages/react-intl/types.js'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\n\nenum DisplayName {\n formatDate = 'FormattedDate',\n formatTime = 'FormattedTime',\n formatNumber = 'FormattedNumber',\n formatList = 'FormattedList',\n // Note that this DisplayName is the locale display name, not to be confused with\n // the name of the enum, which is for React component display name in dev tools.\n formatDisplayName = 'FormattedDisplayName',\n}\n\nenum DisplayNameParts {\n formatDate = 'FormattedDateParts',\n formatTime = 'FormattedTimeParts',\n formatNumber = 'FormattedNumberParts',\n formatList = 'FormattedListParts',\n}\n\ntype Formatter = {\n formatDate: FormatDateOptions\n formatTime: FormatDateOptions\n formatNumber: FormatNumberOptions\n formatList: FormatListOptions\n formatDisplayName: FormatDisplayNameOptions\n}\n\nexport const FormattedNumberParts: React.FC<\n Formatter['formatNumber'] & {\n value: Parameters<IntlShape['formatNumber']>[0]\n\n children(val: Intl.NumberFormatPart[]): React.ReactElement | null\n }\n> = props => {\n const intl = useIntl()\n const {value, children, ...formatProps} = props\n return children(intl.formatNumberToParts(value, formatProps))\n}\nFormattedNumberParts.displayName = 'FormattedNumberParts'\n\nexport const FormattedListParts: React.FC<\n Formatter['formatList'] & {\n value: Parameters<IntlShape['formatList']>[0]\n\n children(\n val: ReturnType<Intl.ListFormat['formatToParts']>\n ): React.ReactElement | null\n }\n> = props => {\n const intl = useIntl()\n const {value, children, ...formatProps} = props\n return children(intl.formatListToParts(value, formatProps))\n}\nFormattedNumberParts.displayName = 'FormattedNumberParts'\n\nexport function createFormattedDateTimePartsComponent<\n Name extends 'formatDate' | 'formatTime',\n>(\n name: Name\n): React.FC<\n Formatter[Name] & {\n value: Parameters<IntlShape[Name]>[0]\n children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null\n }\n> {\n type FormatFn = IntlShape[Name]\n type Props = Formatter[Name] & {\n value: Parameters<FormatFn>[0]\n children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null\n }\n\n const ComponentParts: React.FC<Props> = props => {\n const intl = useIntl()\n const {value, children, ...formatProps} = props\n const date = typeof value === 'string' ? new Date(value || 0) : value\n const formattedParts: Intl.DateTimeFormatPart[] =\n name === 'formatDate'\n ? intl.formatDateToParts(date, formatProps)\n : intl.formatTimeToParts(date, formatProps)\n\n return children(formattedParts)\n }\n ComponentParts.displayName = DisplayNameParts[name]\n return ComponentParts\n}\n\nexport function createFormattedComponent<Name extends keyof Formatter>(\n name: Name\n): React.FC<\n Formatter[Name] & {\n value: Parameters<IntlShape[Name]>[0]\n children?(val: string): React.ReactElement | null\n }\n> {\n type FormatFn = IntlShape[Name]\n type Props = Formatter[Name] & {\n value: Parameters<FormatFn>[0]\n children?(val: string): React.ReactElement | null\n }\n\n const Component: React.FC<Props> = props => {\n const intl = useIntl()\n const {value, children, ...formatProps} = props\n // TODO: fix TS type definition for localeMatcher upstream\n const formattedValue = intl[name](value as never, formatProps as any)\n\n if (typeof children === 'function') {\n return children(formattedValue as any)\n }\n const Text = intl.textComponent || React.Fragment\n return <Text>{formattedValue}</Text>\n }\n\n Component.displayName = DisplayName[name]\n return Component\n}\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\n\nimport {\n type CreateIntlFn,\n type FormatMessageFn,\n createIntl as coreCreateIntl,\n formatMessage as coreFormatMessage,\n} from '@formatjs/intl'\nimport {\n type FormatXMLElementFn,\n type PrimitiveType,\n isFormatXMLElementFn,\n} from 'intl-messageformat'\nimport * as React from 'react'\nimport type {\n IntlConfig,\n IntlShape,\n ResolvedIntlConfig,\n} from '#packages/react-intl/types.js'\nimport {\n DEFAULT_INTL_CONFIG,\n assignUniqueKeysToParts,\n toKeyedReactNodeArray,\n} from '#packages/react-intl/utils.js'\n\nfunction assignUniqueKeysToFormatXMLElementFnArgument<\n T extends Record<\n string,\n | PrimitiveType\n | React.ReactNode\n | FormatXMLElementFn<React.ReactNode, React.ReactNode>\n > = Record<\n string,\n | PrimitiveType\n | React.ReactNode\n | FormatXMLElementFn<React.ReactNode, React.ReactNode>\n >,\n>(values?: T): T | undefined {\n if (!values) {\n return values\n }\n return Object.keys(values).reduce((acc: T, k) => {\n const v = values[k]\n ;(acc as any)[k] = isFormatXMLElementFn<React.ReactNode>(v)\n ? assignUniqueKeysToParts(v)\n : v\n return acc\n }, {} as T)\n}\n\nconst formatMessage: FormatMessageFn<React.ReactNode> = (\n config,\n formatters,\n descriptor,\n rawValues,\n ...rest\n) => {\n const values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues)\n const chunks = coreFormatMessage(\n config,\n formatters,\n descriptor,\n values as any,\n ...rest\n )\n if (Array.isArray(chunks)) {\n return toKeyedReactNodeArray(chunks)\n }\n return chunks\n}\n\n/**\n * Create intl object\n * @param config intl config\n * @param cache cache for formatter instances to prevent memory leak\n */\nexport const createIntl: CreateIntlFn<\n React.ReactNode,\n IntlConfig,\n IntlShape\n> = (\n {defaultRichTextElements: rawDefaultRichTextElements, ...config},\n cache\n) => {\n const defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(\n rawDefaultRichTextElements\n )\n const coreIntl = coreCreateIntl<React.ReactNode>(\n {\n ...DEFAULT_INTL_CONFIG,\n ...config,\n defaultRichTextElements,\n },\n cache\n )\n\n const resolvedConfig: ResolvedIntlConfig = {\n locale: coreIntl.locale,\n timeZone: coreIntl.timeZone,\n fallbackOnEmptyString: coreIntl.fallbackOnEmptyString,\n formats: coreIntl.formats,\n defaultLocale: coreIntl.defaultLocale,\n defaultFormats: coreIntl.defaultFormats,\n messages: coreIntl.messages,\n onError: coreIntl.onError,\n defaultRichTextElements,\n }\n\n return {\n ...coreIntl,\n formatMessage: formatMessage.bind(\n null,\n resolvedConfig,\n coreIntl.formatters\n ),\n $t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters),\n } as any\n}\n","import {type FormatDateTimeRangeOptions} from '@formatjs/intl'\nimport * as React from 'react'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\n\ninterface Props extends FormatDateTimeRangeOptions {\n from: Parameters<Intl.DateTimeFormat['formatRange']>[0]\n to: Parameters<Intl.DateTimeFormat['formatRange']>[1]\n children?(value: React.ReactNode): React.ReactElement | null\n}\n\nconst FormattedDateTimeRange: React.FC<Props> = props => {\n const intl = useIntl()\n\n const {from, to, children, ...formatProps} = props\n const formattedValue = intl.formatDateTimeRange(from, to, formatProps)\n\n if (typeof children === 'function') {\n return children(formattedValue as any)\n }\n const Text = intl.textComponent || React.Fragment\n return <Text>{formattedValue}</Text>\n}\n\nFormattedDateTimeRange.displayName = 'FormattedDateTimeRange'\nexport default FormattedDateTimeRange\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\n\nimport type {\n FormatXMLElementFn,\n Options as IntlMessageFormatOptions,\n PrimitiveType,\n} from 'intl-messageformat'\nimport * as React from 'react'\n\nimport {type MessageDescriptor} from '@formatjs/intl'\nimport {shallowEqual} from '#packages/react-intl/utils.js'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\n\nexport interface Props<\n V extends Record<string, any> = Record<\n string,\n React.ReactNode | PrimitiveType | FormatXMLElementFn<React.ReactNode>\n >,\n> extends MessageDescriptor {\n values?: V\n tagName?: React.ElementType<any>\n children?(nodes: React.ReactNode[]): React.ReactNode | null\n ignoreTag?: IntlMessageFormatOptions['ignoreTag']\n}\n\nfunction areEqual(prevProps: Props, nextProps: Props): boolean {\n const {values, ...otherProps} = prevProps\n const {values: nextValues, ...nextOtherProps} = nextProps\n return (\n shallowEqual(nextValues, values) &&\n shallowEqual(otherProps as any, nextOtherProps)\n )\n}\n\nfunction FormattedMessage(props: Props) {\n const intl = useIntl()\n const {formatMessage, textComponent: Text = React.Fragment} = intl\n const {\n id,\n description,\n defaultMessage,\n values,\n children,\n tagName: Component = Text,\n ignoreTag,\n } = props\n\n const descriptor = {id, description, defaultMessage}\n const nodes = formatMessage(descriptor, values, {\n ignoreTag,\n })\n\n if (typeof children === 'function') {\n return children(Array.isArray(nodes) ? nodes : [nodes])\n }\n\n if (Component) {\n return <Component>{nodes}</Component>\n }\n return <>{nodes}</>\n}\nFormattedMessage.displayName = 'FormattedMessage'\n\nconst MemoizedFormattedMessage: React.ComponentType<Props> = React.memo<Props>(\n FormattedMessage,\n areEqual\n)\nMemoizedFormattedMessage.displayName = 'MemoizedFormattedMessage'\n\nexport default MemoizedFormattedMessage\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\n\nimport * as React from 'react'\nimport {type FormatPluralOptions} from '@formatjs/intl'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\n\ninterface Props extends FormatPluralOptions {\n value: number\n other: React.ReactNode\n zero?: React.ReactNode\n one?: React.ReactNode\n two?: React.ReactNode\n few?: React.ReactNode\n many?: React.ReactNode\n children?(value: React.ReactNode): React.ReactElement | null\n}\n\nconst FormattedPlural: React.FC<Props> = props => {\n const {formatPlural, textComponent: Text} = useIntl()\n const {value, other, children} = props\n\n const pluralCategory = formatPlural(value, props)\n const formattedPlural = props[pluralCategory as 'one'] || other\n\n if (typeof children === 'function') {\n return children(formattedPlural)\n }\n if (Text) {\n return <Text>{formattedPlural}</Text>\n }\n // Work around @types/react where React.FC cannot return string\n return formattedPlural as any\n}\n\nFormattedPlural.displayName = 'FormattedPlural'\n\nexport default FormattedPlural\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\n\nimport {type IntlCache, createIntlCache} from '@formatjs/intl'\nimport * as React from 'react'\nimport type {IntlConfig, IntlShape} from '#packages/react-intl/types.js'\nimport {\n DEFAULT_INTL_CONFIG,\n invariantIntlContext,\n shallowEqual,\n} from '#packages/react-intl/utils.js'\nimport {createIntl} from '#packages/react-intl/components/createIntl.js'\nimport {Provider} from '#packages/react-intl/components/context.js'\n\nfunction processIntlConfig<P extends IntlConfig = IntlConfig>(\n config: P\n): IntlConfig {\n return {\n locale: config.locale,\n timeZone: config.timeZone,\n fallbackOnEmptyString: config.fallbackOnEmptyString,\n formats: config.formats,\n textComponent: config.textComponent,\n messages: config.messages,\n defaultLocale: config.defaultLocale,\n defaultFormats: config.defaultFormats,\n onError: config.onError,\n onWarn: config.onWarn,\n wrapRichTextChunksInFragment: config.wrapRichTextChunksInFragment,\n defaultRichTextElements: config.defaultRichTextElements,\n }\n}\n\nfunction IntlProviderImpl(\n props: React.PropsWithChildren<IntlConfig>\n): React.JSX.Element {\n const cacheRef = React.useRef<IntlCache>(createIntlCache())\n const prevConfigRef = React.useRef<IntlConfig | undefined>(undefined)\n const intlRef = React.useRef<IntlShape | undefined>(undefined)\n\n // Filter out undefined values from props so they don't override defaults.\n // React's defaultProps treated `prop={undefined}` as \"not provided\"; we\n // replicate that behaviour here after converting to a function component.\n const filteredProps: Record<string, unknown> = {}\n for (const key in props) {\n if ((props as any)[key] !== undefined) {\n filteredProps[key] = (props as any)[key]\n }\n }\n const config = processIntlConfig({\n ...DEFAULT_INTL_CONFIG,\n ...filteredProps,\n } as IntlConfig)\n\n if (!prevConfigRef.current || !shallowEqual(prevConfigRef.current, config)) {\n prevConfigRef.current = config\n intlRef.current = createIntl(config, cacheRef.current)\n }\n\n invariantIntlContext(intlRef.current)\n return <Provider value={intlRef.current}>{props.children}</Provider>\n}\n\nIntlProviderImpl.displayName = 'IntlProvider'\n\nconst IntlProvider: React.FC<React.PropsWithChildren<IntlConfig>> =\n IntlProviderImpl\nexport default IntlProvider\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\nimport * as React from 'react'\n\nimport {type FormatRelativeTimeOptions} from '@formatjs/intl'\nimport {invariant} from '#packages/react-intl/utils.js'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\n\nconst MINUTE = 60\nconst HOUR = 60 * 60\nconst DAY = 60 * 60 * 24\n\nfunction selectUnit(seconds: number): Intl.RelativeTimeFormatUnit {\n const absValue = Math.abs(seconds)\n\n if (absValue < MINUTE) {\n return 'second'\n }\n\n if (absValue < HOUR) {\n return 'minute'\n }\n\n if (absValue < DAY) {\n return 'hour'\n }\n\n return 'day'\n}\n\nfunction getDurationInSeconds(unit?: Intl.RelativeTimeFormatUnit): number {\n switch (unit) {\n case 'second':\n return 1\n case 'minute':\n return MINUTE\n case 'hour':\n return HOUR\n default:\n return DAY\n }\n}\n\nfunction valueToSeconds(\n value?: number,\n unit?: Intl.RelativeTimeFormatUnit\n): number {\n if (!value) {\n return 0\n }\n switch (unit) {\n case 'second':\n return value\n case 'minute':\n return value * MINUTE\n default:\n return value * HOUR\n }\n}\n\nexport interface Props extends FormatRelativeTimeOptions {\n value?: number\n unit?: Intl.RelativeTimeFormatUnit\n updateIntervalInSeconds?: number\n children?(value: string): React.ReactElement | null\n}\n\nconst INCREMENTABLE_UNITS: Intl.RelativeTimeFormatUnit[] = [\n 'second',\n 'minute',\n 'hour',\n]\nfunction canIncrement(unit: Intl.RelativeTimeFormatUnit = 'second'): boolean {\n return INCREMENTABLE_UNITS.indexOf(unit) > -1\n}\n\nconst SimpleFormattedRelativeTime: React.FC<\n Omit<Props, 'updateIntervalInSeconds'>\n> = props => {\n const {formatRelativeTime, textComponent: Text} = useIntl()\n const {children, value, unit, ...otherProps} = props\n\n const formattedRelativeTime = formatRelativeTime(value || 0, unit, otherProps)\n\n if (typeof children === 'function') {\n return children(formattedRelativeTime)\n }\n if (Text) {\n return <Text>{formattedRelativeTime}</Text>\n }\n return <>{formattedRelativeTime}</>\n}\n\nconst FormattedRelativeTime: React.FC<Props> = ({\n value = 0,\n unit = 'second',\n updateIntervalInSeconds,\n ...otherProps\n}) => {\n invariant(\n !updateIntervalInSeconds ||\n !!(updateIntervalInSeconds && canIncrement(unit)),\n 'Cannot schedule update with unit longer than hour'\n )\n const [prevUnit, setPrevUnit] = React.useState<\n Intl.RelativeTimeFormatUnit | undefined\n >()\n const [prevValue, setPrevValue] = React.useState<number>(0)\n const [currentValueInSeconds, setCurrentValueInSeconds] =\n React.useState<number>(0)\n const updateTimer = React.useRef<number | undefined>(undefined)\n\n if (unit !== prevUnit || value !== prevValue) {\n setPrevValue(value || 0)\n setPrevUnit(unit)\n setCurrentValueInSeconds(\n canIncrement(unit) ? valueToSeconds(value, unit) : 0\n )\n }\n\n React.useEffect(() => {\n function clearUpdateTimer() {\n clearTimeout(updateTimer.current)\n }\n clearUpdateTimer()\n // If there's no interval and we cannot increment this unit, do nothing\n if (!updateIntervalInSeconds || !canIncrement(unit)) {\n return clearUpdateTimer\n }\n // Figure out the next interesting time\n const nextValueInSeconds = currentValueInSeconds - updateIntervalInSeconds\n const nextUnit = selectUnit(nextValueInSeconds)\n // We've reached the max auto incrementable unit, don't schedule another update\n if (nextUnit === 'day') {\n return clearUpdateTimer\n }\n\n const unitDuration = getDurationInSeconds(nextUnit)\n const remainder = nextValueInSeconds % unitDuration\n const prevInterestingValueInSeconds = nextValueInSeconds - remainder\n const nextInterestingValueInSeconds =\n prevInterestingValueInSeconds >= currentValueInSeconds\n ? prevInterestingValueInSeconds - unitDuration\n : prevInterestingValueInSeconds\n const delayInSeconds = Math.abs(\n nextInterestingValueInSeconds - currentValueInSeconds\n )\n\n if (currentValueInSeconds !== nextInterestingValueInSeconds) {\n updateTimer.current = setTimeout(\n () => setCurrentValueInSeconds(nextInterestingValueInSeconds),\n delayInSeconds * 1e3\n ) as unknown as number\n }\n return clearUpdateTimer\n }, [currentValueInSeconds, updateIntervalInSeconds, unit])\n\n let currentValue = value || 0\n let currentUnit = unit\n\n if (\n canIncrement(unit) &&\n typeof currentValueInSeconds === 'number' &&\n updateIntervalInSeconds\n ) {\n currentUnit = selectUnit(currentValueInSeconds)\n const unitDuration = getDurationInSeconds(currentUnit)\n currentValue = Math.round(currentValueInSeconds / unitDuration)\n }\n return (\n <SimpleFormattedRelativeTime\n value={currentValue}\n unit={currentUnit}\n {...otherProps}\n />\n )\n}\n\nFormattedRelativeTime.displayName = 'FormattedRelativeTime'\n\nexport default FormattedRelativeTime\n","'use client'\n/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\nimport {type NumberFormatOptions} from '#packages/ecma402-abstract/types/number.js'\nimport {\n type CustomFormatConfig,\n type FormatDateOptions,\n type FormatTimeOptions,\n type MessageDescriptor,\n} from '@formatjs/intl'\nimport * as React from 'react'\nimport {\n createFormattedComponent,\n createFormattedDateTimePartsComponent,\n} from '#packages/react-intl/components/createFormattedComponent.js'\nimport {createIntl} from '#packages/react-intl/components/createIntl.js'\nimport {\n Context as IntlContext,\n Provider as RawIntlProvider,\n} from '#packages/react-intl/components/context.js'\nimport FormattedDateTimeRange from '#packages/react-intl/components/dateTimeRange.js'\nimport FormattedMessage from '#packages/react-intl/components/message.js'\nimport FormattedPlural from '#packages/react-intl/components/plural.js'\nimport IntlProvider from '#packages/react-intl/components/provider.js'\nimport FormattedRelativeTime from '#packages/react-intl/components/relative.js'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\nimport {type IntlShape} from '#packages/react-intl/types.js'\nexport {\n createIntlCache,\n type CustomFormatConfig,\n type CustomFormats,\n type FormatDateOptions,\n type FormatDisplayNameOptions,\n type FormatListOptions,\n type FormatNumberOptions,\n type FormatPluralOptions,\n type FormatRelativeTimeOptions,\n type Formatters,\n type IntlCache,\n type IntlFormatters,\n InvalidConfigError,\n type MessageDescriptor,\n MessageFormatError,\n MissingDataError,\n MissingTranslationError,\n IntlError as ReactIntlError,\n IntlErrorCode as ReactIntlErrorCode,\n UnsupportedFormatterError,\n} from '@formatjs/intl'\nexport {\n type IntlConfig,\n type IntlShape,\n type ResolvedIntlConfig,\n} from '#packages/react-intl/types.js'\nexport {\n createIntl,\n FormattedDateTimeRange,\n FormattedMessage,\n FormattedPlural,\n FormattedRelativeTime,\n IntlContext,\n IntlProvider,\n RawIntlProvider,\n useIntl,\n}\n\nexport function defineMessages<\n K extends keyof any,\n T = MessageDescriptor,\n U extends Record<K, T> = Record<K, T>,\n>(msgs: U): U {\n return msgs\n}\n\nexport function defineMessage<T extends MessageDescriptor>(msg: T): T {\n return msg\n}\n// IMPORTANT: Explicit here to prevent api-extractor from outputing `import('./types').CustomFormatConfig`\nexport const FormattedDate: React.FC<\n Intl.DateTimeFormatOptions &\n CustomFormatConfig<'date'> & {\n value: string | number | Date | undefined\n children?(formattedDate: string): React.ReactElement | null\n }\n> = createFormattedComponent('formatDate')\nexport const FormattedTime: React.FC<\n Intl.DateTimeFormatOptions &\n CustomFormatConfig<'time'> & {\n value: string | number | Date | undefined\n children?(formattedTime: string): React.ReactElement | null\n }\n> = createFormattedComponent('formatTime')\nexport const FormattedNumber: React.FC<\n Omit<NumberFormatOptions, 'localeMatcher'> &\n CustomFormatConfig<'number'> & {\n value: Parameters<IntlShape['formatNumber']>[0]\n children?(formattedNumber: string): React.ReactElement | null\n }\n> = createFormattedComponent('formatNumber')\nexport const FormattedList: React.FC<\n Intl.ListFormatOptions & {\n value: readonly React.ReactNode[]\n }\n> = createFormattedComponent('formatList')\nexport const FormattedDisplayName: React.FC<\n Intl.DisplayNamesOptions & {\n value: string\n }\n> = createFormattedComponent('formatDisplayName')\nexport const FormattedDateParts: React.FC<\n FormatDateOptions & {\n value: Parameters<Intl.DateTimeFormat['format']>[0] | string\n children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null\n }\n> = createFormattedDateTimePartsComponent('formatDate')\nexport const FormattedTimeParts: React.FC<\n FormatTimeOptions & {\n value: Parameters<Intl.DateTimeFormat['format']>[0] | string\n children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null\n }\n> = createFormattedDateTimePartsComponent('formatTime')\n\nexport type {MessageFormatElement} from '@formatjs/icu-messageformat-parser'\nexport type {PrimitiveType} from 'intl-messageformat'\nexport {\n FormattedListParts,\n FormattedNumberParts,\n} from '#packages/react-intl/components/createFormattedComponent.js'\n"],"mappings":";;;;;;AAMA,SAAgB,UACd,WACA,SACA,MAAW,OACQ;AACnB,KAAI,CAAC,UACH,OAAM,IAAI,IAAI,QAAQ;;AAI1B,SAAgB,qBAAqB,MAA0B;AAC7D,WACE,MACA,+GAED;;AAeH,MAAaA,wBAAyC;CACpD,GAAGC;CACH,eAAe,MAAM;CACtB;;;;;;;;;;;AAYD,MAAa,yBACX,aAAY;AAGV,QAFsB,MAAM,SAAS,QAAQ,SAAS,CAEjC,KAAK,OAAO,UAAU;AAGzC,MAAI,MAAM,eAAe,MAAM,CAC7B,QAAO,oBAAC,MAAM,UAAP,EAAA,UAA6B,OAAuB,EAA/B,MAA+B;AAE7D,SAAO;GACP;;;;;;;;AASN,SAAgB,wBACd,oBACqC;AACrC,QAAO,SAAU,OAAY;AAE3B,SAAO,mBAAmB,sBAAsB,MAAM,CAAC;;;AAI3D,SAAgB,aAEd,MAAU,MAAmB;AAC7B,KAAI,SAAS,KACX,QAAO;AAGT,KAAI,CAAC,QAAQ,CAAC,KACZ,QAAO;CAGT,IAAI,QAAQ,OAAO,KAAK,KAAK;CAC7B,IAAI,QAAQ,OAAO,KAAK,KAAK;CAC7B,IAAI,MAAM,MAAM;AAEhB,KAAI,MAAM,WAAW,IACnB,QAAO;AAGT,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,KAAK;EAC5B,IAAI,MAAM,MAAM;AAEhB,MACE,KAAK,SAAS,KAAK,QACnB,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,IAAI,CAEhD,QAAO;;AAIX,QAAO;;;;AC3GT,MAAM,cAAwC,MAAM,cAClD,KACD;AAC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T,MAAM,eAAe,qBAAqB,SAAS;EAEnD,MAAM,gCAAgC,qBADpB,qBAAqB;EAEvC,MAAM,gCACJ,iCAAiC,wBAC7B,gCAAgC,eAChC;EACN,MAAM,iBAAiB,KAAK,IAC1B,gCAAgC,sBACjC;AAED,MAAI,0BAA0B,8BAC5B,aAAY,UAAU,iBACd,yBAAyB,8BAA8B,EAC7D,iBAAiB,IAClB;AAEH,SAAO;IACN;EAAC;EAAuB;EAAyB;EAAK,CAAC;CAE1D,IAAI,eAAe,SAAS;CAC5B,IAAI,cAAc;AAElB,KACE,aAAa,KAAK,IAClB,OAAO,0BAA0B,YACjC,yBACA;AACA,gBAAc,WAAW,sBAAsB;EAC/C,MAAM,eAAe,qBAAqB,YAAY;AACtD,iBAAe,KAAK,MAAM,wBAAwB,aAAa;;AAEjE,QACE,oBAAC,6BAAD;EACE,OAAO;EACP,MAAM;EACN,GAAI;EACJ,CAAA;;AAIN,sBAAsB,cAAc;;;AChHpC,SAAgB,eAId,MAAY;AACZ,QAAO;;AAGT,SAAgB,cAA2C,KAAW;AACpE,QAAO;;AAGT,MAAa,gBAMT,yBAAyB,aAAa;AAC1C,MAAa,gBAMT,yBAAyB,aAAa;AAC1C,MAAa,kBAMT,yBAAyB,eAAe;AAC5C,MAAa,gBAIT,yBAAyB,aAAa;AAC1C,MAAa,uBAIT,yBAAyB,oBAAoB;AACjD,MAAa,qBAKT,sCAAsC,aAAa;AACvD,MAAa,qBAKT,sCAAsC,aAAa"}
1
+ {"version":3,"file":"index.js","names":["DEFAULT_INTL_CONFIG","CORE_DEFAULT_INTL_CONFIG","Context","formatMessage","coreFormatMessage","coreCreateIntl","DEFAULT_INTL_CONFIG","createIntlCache","DEFAULT_INTL_CONFIG"],"sources":["../utils.tsx","../components/context.ts","../components/useIntl.ts","../components/createFormattedComponent.tsx","../components/createIntl.ts","../components/dateTimeRange.tsx","../components/message.tsx","../components/plural.tsx","../components/provider.tsx","../components/relative.tsx","../index.ts"],"sourcesContent":["import {type FormatXMLElementFn} from 'intl-messageformat'\nimport * as React from 'react'\nimport {type ResolvedIntlConfig} from '#packages/react-intl/types.js'\n\nimport {DEFAULT_INTL_CONFIG as CORE_DEFAULT_INTL_CONFIG} from '@formatjs/intl'\n\nexport function invariant(\n condition: boolean,\n message: string,\n Err: any = Error\n): asserts condition {\n if (!condition) {\n throw new Err(message)\n }\n}\n\nexport function invariantIntlContext(intl?: any): asserts intl {\n invariant(\n intl,\n '[React Intl] Could not find required `intl` object. ' +\n '<IntlProvider> needs to exist in the component ancestry.'\n )\n}\n\nexport type DefaultIntlConfig = Pick<\n ResolvedIntlConfig,\n | 'fallbackOnEmptyString'\n | 'formats'\n | 'messages'\n | 'timeZone'\n | 'textComponent'\n | 'defaultLocale'\n | 'defaultFormats'\n | 'onError'\n>\n\nexport const DEFAULT_INTL_CONFIG: DefaultIntlConfig = {\n ...CORE_DEFAULT_INTL_CONFIG,\n textComponent: React.Fragment,\n}\n\n/**\n * Builds an array of {@link React.ReactNode}s with index-based keys, similar to\n * {@link React.Children.toArray}. However, this function tells React that it\n * was intentional, so they won't produce a bunch of warnings about it.\n *\n * React doesn't recommend doing this because it makes reordering inefficient,\n * but we mostly need this for message chunks, which don't tend to reorder to\n * begin with.\n *\n */\nexport const toKeyedReactNodeArray: typeof React.Children.toArray =\n children => {\n const childrenArray = React.Children.toArray(children)\n\n return childrenArray.map((child, index) => {\n // For React elements, wrap in a keyed Fragment\n // This creates a new element with a key rather than trying to add one after creation\n if (React.isValidElement(child)) {\n return <React.Fragment key={index}>{child}</React.Fragment>\n }\n return child\n })\n }\n\n/**\n * Takes a `formatXMLElementFn`, and composes it in function, which passes\n * argument `parts` through, assigning unique key to each part, to prevent\n * \"Each child in a list should have a unique \"key\"\" React error.\n * @param formatXMLElementFn\n */\nexport function assignUniqueKeysToParts(\n formatXMLElementFn: FormatXMLElementFn<React.ReactNode>\n): FormatXMLElementFn<React.ReactNode> {\n return function (parts: any) {\n // eslint-disable-next-line prefer-rest-params\n return formatXMLElementFn(toKeyedReactNodeArray(parts)) as any\n }\n}\n\nexport function shallowEqual<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(objA?: T, objB?: T): boolean {\n if (objA === objB) {\n return true\n }\n\n if (!objA || !objB) {\n return false\n }\n\n var aKeys = Object.keys(objA)\n var bKeys = Object.keys(objB)\n var len = aKeys.length\n\n if (bKeys.length !== len) {\n return false\n }\n\n for (var i = 0; i < len; i++) {\n var key = aKeys[i]\n\n if (\n objA[key] !== objB[key] ||\n !Object.prototype.hasOwnProperty.call(objB, key)\n ) {\n return false\n }\n }\n\n return true\n}\n","import * as React from 'react'\nimport {type IntlShape} from '#packages/react-intl/types.js'\n\nconst IntlContext: React.Context<IntlShape> = React.createContext<IntlShape>(\n null as any\n)\nconst Provider: React.Provider<IntlShape> = IntlContext.Provider\n\nexport {Provider, IntlContext as Context}\n","import * as React from 'react'\nimport {type IntlShape} from '#packages/react-intl/types.js'\nimport {invariantIntlContext} from '#packages/react-intl/utils.js'\nimport {Context} from '#packages/react-intl/components/context.js'\n\nexport default function useIntl(this: void): IntlShape {\n const intl = React.useContext(Context)\n invariantIntlContext(intl)\n return intl\n}\n","import {\n type FormatDateOptions,\n type FormatDisplayNameOptions,\n type FormatListOptions,\n type FormatNumberOptions,\n} from '@formatjs/intl'\nimport * as React from 'react'\nimport {type IntlShape} from '#packages/react-intl/types.js'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\n\nenum DisplayName {\n formatDate = 'FormattedDate',\n formatTime = 'FormattedTime',\n formatNumber = 'FormattedNumber',\n formatList = 'FormattedList',\n // Note that this DisplayName is the locale display name, not to be confused with\n // the name of the enum, which is for React component display name in dev tools.\n formatDisplayName = 'FormattedDisplayName',\n}\n\nenum DisplayNameParts {\n formatDate = 'FormattedDateParts',\n formatTime = 'FormattedTimeParts',\n formatNumber = 'FormattedNumberParts',\n formatList = 'FormattedListParts',\n}\n\ntype Formatter = {\n formatDate: FormatDateOptions\n formatTime: FormatDateOptions\n formatNumber: FormatNumberOptions\n formatList: FormatListOptions\n formatDisplayName: FormatDisplayNameOptions\n}\n\nexport const FormattedNumberParts: React.FC<\n Formatter['formatNumber'] & {\n value: Parameters<IntlShape['formatNumber']>[0]\n\n children(val: Intl.NumberFormatPart[]): React.ReactElement | null\n }\n> = props => {\n const intl = useIntl()\n const {value, children, ...formatProps} = props\n return children(intl.formatNumberToParts(value, formatProps))\n}\nFormattedNumberParts.displayName = 'FormattedNumberParts'\n\nexport const FormattedListParts: React.FC<\n Formatter['formatList'] & {\n value: Parameters<IntlShape['formatList']>[0]\n\n children(\n val: ReturnType<Intl.ListFormat['formatToParts']>\n ): React.ReactElement | null\n }\n> = props => {\n const intl = useIntl()\n const {value, children, ...formatProps} = props\n return children(intl.formatListToParts(value, formatProps))\n}\nFormattedListParts.displayName = 'FormattedListParts'\n\nexport function createFormattedDateTimePartsComponent<\n Name extends 'formatDate' | 'formatTime',\n>(\n name: Name\n): React.FC<\n Formatter[Name] & {\n value: Parameters<IntlShape[Name]>[0]\n children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null\n }\n> {\n type FormatFn = IntlShape[Name]\n type Props = Formatter[Name] & {\n value: Parameters<FormatFn>[0]\n children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null\n }\n\n const ComponentParts: React.FC<Props> = props => {\n const intl = useIntl()\n const {value, children, ...formatProps} = props\n const date = typeof value === 'string' ? new Date(value || 0) : value\n const formattedParts: Intl.DateTimeFormatPart[] =\n name === 'formatDate'\n ? intl.formatDateToParts(date, formatProps)\n : intl.formatTimeToParts(date, formatProps)\n\n return children(formattedParts)\n }\n ComponentParts.displayName = DisplayNameParts[name]\n return ComponentParts\n}\n\nexport function createFormattedComponent<Name extends keyof Formatter>(\n name: Name\n): React.FC<\n Formatter[Name] & {\n value: Parameters<IntlShape[Name]>[0]\n children?(val: string): React.ReactElement | null\n }\n> {\n type FormatFn = IntlShape[Name]\n type Props = Formatter[Name] & {\n value: Parameters<FormatFn>[0]\n children?(val: string): React.ReactElement | null\n }\n\n const Component: React.FC<Props> = props => {\n const intl = useIntl()\n const {value, children, ...formatProps} = props\n // TODO: fix TS type definition for localeMatcher upstream\n const formattedValue = intl[name](value as never, formatProps as any)\n\n if (typeof children === 'function') {\n return children(formattedValue as any)\n }\n const Text = intl.textComponent || React.Fragment\n return <Text>{formattedValue}</Text>\n }\n\n Component.displayName = DisplayName[name]\n return Component\n}\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\n\nimport {\n type CreateIntlFn,\n type FormatMessageFn,\n createIntl as coreCreateIntl,\n formatMessage as coreFormatMessage,\n} from '@formatjs/intl'\nimport {\n type FormatXMLElementFn,\n type PrimitiveType,\n isFormatXMLElementFn,\n} from 'intl-messageformat'\nimport * as React from 'react'\nimport type {\n IntlConfig,\n IntlShape,\n ResolvedIntlConfig,\n} from '#packages/react-intl/types.js'\nimport {\n DEFAULT_INTL_CONFIG,\n assignUniqueKeysToParts,\n toKeyedReactNodeArray,\n} from '#packages/react-intl/utils.js'\n\nfunction assignUniqueKeysToFormatXMLElementFnArgument<\n T extends Record<\n string,\n | PrimitiveType\n | React.ReactNode\n | FormatXMLElementFn<React.ReactNode, React.ReactNode>\n > = Record<\n string,\n | PrimitiveType\n | React.ReactNode\n | FormatXMLElementFn<React.ReactNode, React.ReactNode>\n >,\n>(values?: T): T | undefined {\n if (!values) {\n return values\n }\n return Object.keys(values).reduce((acc: T, k) => {\n const v = values[k]\n ;(acc as any)[k] = isFormatXMLElementFn<React.ReactNode>(v)\n ? assignUniqueKeysToParts(v)\n : v\n return acc\n }, {} as T)\n}\n\nconst formatMessage: FormatMessageFn<React.ReactNode> = (\n config,\n formatters,\n descriptor,\n rawValues,\n ...rest\n) => {\n const values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues)\n const chunks = coreFormatMessage(\n config,\n formatters,\n descriptor,\n values as any,\n ...rest\n )\n if (Array.isArray(chunks)) {\n return toKeyedReactNodeArray(chunks)\n }\n return chunks\n}\n\n/**\n * Create intl object\n * @param config intl config\n * @param cache cache for formatter instances to prevent memory leak\n */\nexport const createIntl: CreateIntlFn<\n React.ReactNode,\n IntlConfig,\n IntlShape\n> = (\n {defaultRichTextElements: rawDefaultRichTextElements, ...config},\n cache\n) => {\n const defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(\n rawDefaultRichTextElements\n )\n const coreIntl = coreCreateIntl<React.ReactNode>(\n {\n ...DEFAULT_INTL_CONFIG,\n ...config,\n defaultRichTextElements,\n },\n cache\n )\n\n const resolvedConfig: ResolvedIntlConfig = {\n locale: coreIntl.locale,\n timeZone: coreIntl.timeZone,\n fallbackOnEmptyString: coreIntl.fallbackOnEmptyString,\n formats: coreIntl.formats,\n defaultLocale: coreIntl.defaultLocale,\n defaultFormats: coreIntl.defaultFormats,\n messages: coreIntl.messages,\n onError: coreIntl.onError,\n defaultRichTextElements,\n }\n\n return {\n ...coreIntl,\n formatMessage: formatMessage.bind(\n null,\n resolvedConfig,\n coreIntl.formatters\n ),\n $t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters),\n } as any\n}\n","import {type FormatDateTimeRangeOptions} from '@formatjs/intl'\nimport * as React from 'react'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\n\ninterface Props extends FormatDateTimeRangeOptions {\n from: Parameters<Intl.DateTimeFormat['formatRange']>[0]\n to: Parameters<Intl.DateTimeFormat['formatRange']>[1]\n children?(value: React.ReactNode): React.ReactElement | null\n}\n\nconst FormattedDateTimeRange: React.FC<Props> = props => {\n const intl = useIntl()\n\n const {from, to, children, ...formatProps} = props\n const formattedValue = intl.formatDateTimeRange(from, to, formatProps)\n\n if (typeof children === 'function') {\n return children(formattedValue as any)\n }\n const Text = intl.textComponent || React.Fragment\n return <Text>{formattedValue}</Text>\n}\n\nFormattedDateTimeRange.displayName = 'FormattedDateTimeRange'\nexport default FormattedDateTimeRange\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\n\nimport type {\n FormatXMLElementFn,\n Options as IntlMessageFormatOptions,\n PrimitiveType,\n} from 'intl-messageformat'\nimport * as React from 'react'\n\nimport {type MessageDescriptor} from '@formatjs/intl'\nimport {shallowEqual} from '#packages/react-intl/utils.js'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\n\nexport interface Props<\n V extends Record<string, any> = Record<\n string,\n React.ReactNode | PrimitiveType | FormatXMLElementFn<React.ReactNode>\n >,\n> extends MessageDescriptor {\n values?: V\n tagName?: React.ElementType<any>\n children?(nodes: React.ReactNode[]): React.ReactNode | null\n ignoreTag?: IntlMessageFormatOptions['ignoreTag']\n}\n\nfunction areEqual(prevProps: Props, nextProps: Props): boolean {\n const {values, ...otherProps} = prevProps\n const {values: nextValues, ...nextOtherProps} = nextProps\n return (\n shallowEqual(nextValues, values) &&\n shallowEqual(otherProps as any, nextOtherProps)\n )\n}\n\nfunction FormattedMessage(props: Props) {\n const intl = useIntl()\n const {formatMessage, textComponent: Text = React.Fragment} = intl\n const {\n id,\n description,\n defaultMessage,\n values,\n children,\n tagName: Component = Text,\n ignoreTag,\n } = props\n\n const descriptor = {id, description, defaultMessage}\n const nodes = formatMessage(descriptor, values, {\n ignoreTag,\n })\n\n if (typeof children === 'function') {\n return children(Array.isArray(nodes) ? nodes : [nodes])\n }\n\n if (Component) {\n return <Component>{nodes}</Component>\n }\n return <>{nodes}</>\n}\nFormattedMessage.displayName = 'FormattedMessage'\n\nconst MemoizedFormattedMessage: React.ComponentType<Props> = React.memo<Props>(\n FormattedMessage,\n areEqual\n)\nMemoizedFormattedMessage.displayName = 'MemoizedFormattedMessage'\n\nexport default MemoizedFormattedMessage\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\n\nimport * as React from 'react'\nimport {type FormatPluralOptions} from '@formatjs/intl'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\n\ninterface Props extends FormatPluralOptions {\n value: number\n other: React.ReactNode\n zero?: React.ReactNode\n one?: React.ReactNode\n two?: React.ReactNode\n few?: React.ReactNode\n many?: React.ReactNode\n children?(value: React.ReactNode): React.ReactElement | null\n}\n\nconst FormattedPlural: React.FC<Props> = props => {\n const {formatPlural, textComponent: Text} = useIntl()\n const {value, other, children} = props\n\n const pluralCategory = formatPlural(value, props)\n const formattedPlural = props[pluralCategory as 'one'] || other\n\n if (typeof children === 'function') {\n return children(formattedPlural)\n }\n if (Text) {\n return <Text>{formattedPlural}</Text>\n }\n // Work around @types/react where React.FC cannot return string\n return formattedPlural as any\n}\n\nFormattedPlural.displayName = 'FormattedPlural'\n\nexport default FormattedPlural\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\n\nimport {type IntlCache, createIntlCache} from '@formatjs/intl'\nimport * as React from 'react'\nimport type {IntlConfig, IntlShape} from '#packages/react-intl/types.js'\nimport {\n DEFAULT_INTL_CONFIG,\n invariantIntlContext,\n shallowEqual,\n} from '#packages/react-intl/utils.js'\nimport {createIntl} from '#packages/react-intl/components/createIntl.js'\nimport {Provider} from '#packages/react-intl/components/context.js'\n\nfunction processIntlConfig<P extends IntlConfig = IntlConfig>(\n config: P\n): IntlConfig {\n return {\n locale: config.locale,\n timeZone: config.timeZone,\n fallbackOnEmptyString: config.fallbackOnEmptyString,\n formats: config.formats,\n textComponent: config.textComponent,\n messages: config.messages,\n defaultLocale: config.defaultLocale,\n defaultFormats: config.defaultFormats,\n onError: config.onError,\n onWarn: config.onWarn,\n wrapRichTextChunksInFragment: config.wrapRichTextChunksInFragment,\n defaultRichTextElements: config.defaultRichTextElements,\n }\n}\n\nfunction IntlProviderImpl(\n props: React.PropsWithChildren<IntlConfig>\n): React.JSX.Element {\n const cacheRef = React.useRef<IntlCache>(createIntlCache())\n const prevConfigRef = React.useRef<IntlConfig | undefined>(undefined)\n const intlRef = React.useRef<IntlShape | undefined>(undefined)\n\n // Filter out undefined values from props so they don't override defaults.\n // React's defaultProps treated `prop={undefined}` as \"not provided\"; we\n // replicate that behaviour here after converting to a function component.\n const filteredProps: Record<string, unknown> = {}\n for (const key in props) {\n if ((props as any)[key] !== undefined) {\n filteredProps[key] = (props as any)[key]\n }\n }\n const config = processIntlConfig({\n ...DEFAULT_INTL_CONFIG,\n ...filteredProps,\n } as IntlConfig)\n\n if (!prevConfigRef.current || !shallowEqual(prevConfigRef.current, config)) {\n prevConfigRef.current = config\n intlRef.current = createIntl(config, cacheRef.current)\n }\n\n invariantIntlContext(intlRef.current)\n return <Provider value={intlRef.current}>{props.children}</Provider>\n}\n\nIntlProviderImpl.displayName = 'IntlProvider'\n\nconst IntlProvider: React.FC<React.PropsWithChildren<IntlConfig>> =\n IntlProviderImpl\nexport default IntlProvider\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\nimport * as React from 'react'\n\nimport {type FormatRelativeTimeOptions} from '@formatjs/intl'\nimport {invariant} from '#packages/react-intl/utils.js'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\n\nconst MINUTE = 60\nconst HOUR = 60 * 60\nconst DAY = 60 * 60 * 24\n\nfunction selectUnit(seconds: number): Intl.RelativeTimeFormatUnit {\n const absValue = Math.abs(seconds)\n\n if (absValue < MINUTE) {\n return 'second'\n }\n\n if (absValue < HOUR) {\n return 'minute'\n }\n\n if (absValue < DAY) {\n return 'hour'\n }\n\n return 'day'\n}\n\nfunction getDurationInSeconds(unit?: Intl.RelativeTimeFormatUnit): number {\n switch (unit) {\n case 'second':\n return 1\n case 'minute':\n return MINUTE\n case 'hour':\n return HOUR\n default:\n return DAY\n }\n}\n\nfunction valueToSeconds(\n value?: number,\n unit?: Intl.RelativeTimeFormatUnit\n): number {\n if (!value) {\n return 0\n }\n switch (unit) {\n case 'second':\n return value\n case 'minute':\n return value * MINUTE\n default:\n return value * HOUR\n }\n}\n\nexport interface Props extends FormatRelativeTimeOptions {\n value?: number\n unit?: Intl.RelativeTimeFormatUnit\n updateIntervalInSeconds?: number\n children?(value: string): React.ReactElement | null\n}\n\nconst INCREMENTABLE_UNITS: Intl.RelativeTimeFormatUnit[] = [\n 'second',\n 'minute',\n 'hour',\n]\nfunction canIncrement(unit: Intl.RelativeTimeFormatUnit = 'second'): boolean {\n return INCREMENTABLE_UNITS.indexOf(unit) > -1\n}\n\nconst SimpleFormattedRelativeTime: React.FC<\n Omit<Props, 'updateIntervalInSeconds'>\n> = props => {\n const {formatRelativeTime, textComponent: Text} = useIntl()\n const {children, value, unit, ...otherProps} = props\n\n const formattedRelativeTime = formatRelativeTime(value || 0, unit, otherProps)\n\n if (typeof children === 'function') {\n return children(formattedRelativeTime)\n }\n if (Text) {\n return <Text>{formattedRelativeTime}</Text>\n }\n return <>{formattedRelativeTime}</>\n}\n\nconst FormattedRelativeTime: React.FC<Props> = ({\n value = 0,\n unit = 'second',\n updateIntervalInSeconds,\n ...otherProps\n}) => {\n invariant(\n !updateIntervalInSeconds ||\n !!(updateIntervalInSeconds && canIncrement(unit)),\n 'Cannot schedule update with unit longer than hour'\n )\n const [prevUnit, setPrevUnit] = React.useState<\n Intl.RelativeTimeFormatUnit | undefined\n >()\n const [prevValue, setPrevValue] = React.useState<number>(0)\n const [currentValueInSeconds, setCurrentValueInSeconds] =\n React.useState<number>(0)\n const updateTimer = React.useRef<number | undefined>(undefined)\n\n if (unit !== prevUnit || value !== prevValue) {\n setPrevValue(value || 0)\n setPrevUnit(unit)\n setCurrentValueInSeconds(\n canIncrement(unit) ? valueToSeconds(value, unit) : 0\n )\n }\n\n React.useEffect(() => {\n function clearUpdateTimer() {\n clearTimeout(updateTimer.current)\n }\n clearUpdateTimer()\n // If there's no interval and we cannot increment this unit, do nothing\n if (!updateIntervalInSeconds || !canIncrement(unit)) {\n return clearUpdateTimer\n }\n // Figure out the next interesting time\n const nextValueInSeconds = currentValueInSeconds - updateIntervalInSeconds\n const nextUnit = selectUnit(nextValueInSeconds)\n // We've reached the max auto incrementable unit, don't schedule another update\n if (nextUnit === 'day') {\n return clearUpdateTimer\n }\n\n const unitDuration = getDurationInSeconds(nextUnit)\n const remainder = nextValueInSeconds % unitDuration\n const prevInterestingValueInSeconds = nextValueInSeconds - remainder\n const nextInterestingValueInSeconds =\n prevInterestingValueInSeconds >= currentValueInSeconds\n ? prevInterestingValueInSeconds - unitDuration\n : prevInterestingValueInSeconds\n const delayInSeconds = Math.abs(\n nextInterestingValueInSeconds - currentValueInSeconds\n )\n\n if (currentValueInSeconds !== nextInterestingValueInSeconds) {\n updateTimer.current = setTimeout(\n () => setCurrentValueInSeconds(nextInterestingValueInSeconds),\n delayInSeconds * 1e3\n ) as unknown as number\n }\n return clearUpdateTimer\n }, [currentValueInSeconds, updateIntervalInSeconds, unit])\n\n let currentValue = value || 0\n let currentUnit = unit\n\n if (\n canIncrement(unit) &&\n typeof currentValueInSeconds === 'number' &&\n updateIntervalInSeconds\n ) {\n currentUnit = selectUnit(currentValueInSeconds)\n const unitDuration = getDurationInSeconds(currentUnit)\n currentValue = Math.round(currentValueInSeconds / unitDuration)\n }\n return (\n <SimpleFormattedRelativeTime\n value={currentValue}\n unit={currentUnit}\n {...otherProps}\n />\n )\n}\n\nFormattedRelativeTime.displayName = 'FormattedRelativeTime'\n\nexport default FormattedRelativeTime\n","'use client'\n/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\nimport {type NumberFormatOptions} from '#packages/ecma402-abstract/types/number.js'\nimport {\n type CustomFormatConfig,\n type FormatDateOptions,\n type FormatTimeOptions,\n type MessageDescriptor,\n} from '@formatjs/intl'\nimport * as React from 'react'\nimport {\n createFormattedComponent,\n createFormattedDateTimePartsComponent,\n} from '#packages/react-intl/components/createFormattedComponent.js'\nimport {createIntl} from '#packages/react-intl/components/createIntl.js'\nimport {\n Context as IntlContext,\n Provider as RawIntlProvider,\n} from '#packages/react-intl/components/context.js'\nimport FormattedDateTimeRange from '#packages/react-intl/components/dateTimeRange.js'\nimport FormattedMessage from '#packages/react-intl/components/message.js'\nimport FormattedPlural from '#packages/react-intl/components/plural.js'\nimport IntlProvider from '#packages/react-intl/components/provider.js'\nimport FormattedRelativeTime from '#packages/react-intl/components/relative.js'\nimport useIntl from '#packages/react-intl/components/useIntl.js'\nimport {type IntlShape} from '#packages/react-intl/types.js'\nexport {\n createIntlCache,\n type CustomFormatConfig,\n type CustomFormats,\n type FormatDateOptions,\n type FormatDisplayNameOptions,\n type FormatListOptions,\n type FormatNumberOptions,\n type FormatPluralOptions,\n type FormatRelativeTimeOptions,\n type Formatters,\n type IntlCache,\n type IntlFormatters,\n InvalidConfigError,\n type MessageDescriptor,\n MessageFormatError,\n MissingDataError,\n MissingTranslationError,\n IntlError as ReactIntlError,\n IntlErrorCode as ReactIntlErrorCode,\n UnsupportedFormatterError,\n} from '@formatjs/intl'\nexport {\n type IntlConfig,\n type IntlShape,\n type ResolvedIntlConfig,\n} from '#packages/react-intl/types.js'\nexport {\n createIntl,\n FormattedDateTimeRange,\n FormattedMessage,\n FormattedPlural,\n FormattedRelativeTime,\n IntlContext,\n IntlProvider,\n RawIntlProvider,\n useIntl,\n}\n\nexport function defineMessages<\n K extends keyof any,\n T = MessageDescriptor,\n U extends Record<K, T> = Record<K, T>,\n>(msgs: U): U {\n return msgs\n}\n\nexport function defineMessage<T extends MessageDescriptor>(msg: T): T {\n return msg\n}\n// IMPORTANT: Explicit here to prevent api-extractor from outputing `import('./types').CustomFormatConfig`\nexport const FormattedDate: React.FC<\n Intl.DateTimeFormatOptions &\n CustomFormatConfig<'date'> & {\n value: string | number | Date | undefined\n children?(formattedDate: string): React.ReactElement | null\n }\n> = createFormattedComponent('formatDate')\nexport const FormattedTime: React.FC<\n Intl.DateTimeFormatOptions &\n CustomFormatConfig<'time'> & {\n value: string | number | Date | undefined\n children?(formattedTime: string): React.ReactElement | null\n }\n> = createFormattedComponent('formatTime')\nexport const FormattedNumber: React.FC<\n Omit<NumberFormatOptions, 'localeMatcher'> &\n CustomFormatConfig<'number'> & {\n value: Parameters<IntlShape['formatNumber']>[0]\n children?(formattedNumber: string): React.ReactElement | null\n }\n> = createFormattedComponent('formatNumber')\nexport const FormattedList: React.FC<\n Intl.ListFormatOptions & {\n value: readonly React.ReactNode[]\n }\n> = createFormattedComponent('formatList')\nexport const FormattedDisplayName: React.FC<\n Intl.DisplayNamesOptions & {\n value: string\n }\n> = createFormattedComponent('formatDisplayName')\nexport const FormattedDateParts: React.FC<\n FormatDateOptions & {\n value: Parameters<Intl.DateTimeFormat['format']>[0] | string\n children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null\n }\n> = createFormattedDateTimePartsComponent('formatDate')\nexport const FormattedTimeParts: React.FC<\n FormatTimeOptions & {\n value: Parameters<Intl.DateTimeFormat['format']>[0] | string\n children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null\n }\n> = createFormattedDateTimePartsComponent('formatTime')\n\nexport type {MessageFormatElement} from '@formatjs/icu-messageformat-parser'\nexport type {PrimitiveType} from 'intl-messageformat'\nexport {\n FormattedListParts,\n FormattedNumberParts,\n} from '#packages/react-intl/components/createFormattedComponent.js'\n"],"mappings":";;;;;;AAMA,SAAgB,UACd,WACA,SACA,MAAW,OACQ;CACnB,IAAI,CAAC,WACH,MAAM,IAAI,IAAI,QAAQ;;AAI1B,SAAgB,qBAAqB,MAA0B;CAC7D,UACE,MACA,+GAED;;AAeH,MAAaA,wBAAyC;CACpD,GAAGC;CACH,eAAe,MAAM;CACtB;;;;;;;;;;;AAYD,MAAa,yBACX,aAAY;CAGV,OAFsB,MAAM,SAAS,QAAQ,SAEzB,CAAC,KAAK,OAAO,UAAU;EAGzC,IAAI,MAAM,eAAe,MAAM,EAC7B,OAAO,oBAAC,MAAM,UAAP,EAAA,UAA6B,OAAuB,EAA/B,MAA+B;EAE7D,OAAO;GACP;;;;;;;;AASN,SAAgB,wBACd,oBACqC;CACrC,OAAO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AAa,gBAMT,yBAAyB,aAAa;AAC1C,MAAa,kBAMT,yBAAyB,eAAe;AAC5C,MAAa,gBAIT,yBAAyB,aAAa;AAC1C,MAAa,uBAIT,yBAAyB,oBAAoB;AACjD,MAAa,qBAKT,sCAAsC,aAAa;AACvD,MAAa,qBAKT,sCAAsC,aAAa"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-intl",
3
3
  "description": "Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.",
4
- "version": "10.1.7",
4
+ "version": "10.1.8",
5
5
  "license": "BSD-3-Clause",
6
6
  "author": "Eric Ferraiuolo <edf@ericf.me>",
7
7
  "type": "module",
@@ -544,46 +544,41 @@ let TYPE = /* @__PURE__ */ function(TYPE) {
544
544
  TYPE[TYPE["tag"] = 8] = "tag";
545
545
  return TYPE;
546
546
  }({});
547
- let SKELETON_TYPE = /* @__PURE__ */ function(SKELETON_TYPE) {
548
- SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number";
549
- SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime";
550
- return SKELETON_TYPE;
551
- }({});
552
547
  /**
553
548
  * Type Guards
554
549
  */
555
550
  function isLiteralElement(el) {
556
- return el.type === TYPE.literal;
551
+ return el.type === 0;
557
552
  }
558
553
  function isArgumentElement(el) {
559
- return el.type === TYPE.argument;
554
+ return el.type === 1;
560
555
  }
561
556
  function isNumberElement(el) {
562
- return el.type === TYPE.number;
557
+ return el.type === 2;
563
558
  }
564
559
  function isDateElement(el) {
565
- return el.type === TYPE.date;
560
+ return el.type === 3;
566
561
  }
567
562
  function isTimeElement(el) {
568
- return el.type === TYPE.time;
563
+ return el.type === 4;
569
564
  }
570
565
  function isSelectElement(el) {
571
- return el.type === TYPE.select;
566
+ return el.type === 5;
572
567
  }
573
568
  function isPluralElement(el) {
574
- return el.type === TYPE.plural;
569
+ return el.type === 6;
575
570
  }
576
571
  function isPoundElement(el) {
577
- return el.type === TYPE.pound;
572
+ return el.type === 7;
578
573
  }
579
574
  function isTagElement(el) {
580
- return el.type === TYPE.tag;
575
+ return el.type === 8;
581
576
  }
582
577
  function isNumberSkeleton(el) {
583
- return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.number);
578
+ return !!(el && typeof el === "object" && el.type === 0);
584
579
  }
585
580
  function isDateTimeSkeleton(el) {
586
- return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.dateTime);
581
+ return !!(el && typeof el === "object" && el.type === 1);
587
582
  }
588
583
  const SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/;
589
584
  const timeData = {
@@ -1859,11 +1854,11 @@ var Parser = class {
1859
1854
  const position = this.clonePosition();
1860
1855
  this.bump();
1861
1856
  elements.push({
1862
- type: TYPE.pound,
1857
+ type: 7,
1863
1858
  location: createLocation(position, this.clonePosition())
1864
1859
  });
1865
1860
  } else if (char === 60 && !this.ignoreTag && this.peek() === 47) if (expectingCloseTag) break;
1866
- else return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition()));
1861
+ else return this.error(26, createLocation(this.clonePosition(), this.clonePosition()));
1867
1862
  else if (char === 60 && !this.ignoreTag && _isAlpha(this.peek() || 0)) {
1868
1863
  const result = this.parseTag(nestingLevel, parentArgType);
1869
1864
  if (result.err) return result;
@@ -1904,7 +1899,7 @@ var Parser = class {
1904
1899
  this.bumpSpace();
1905
1900
  if (this.bumpIf("/>")) return {
1906
1901
  val: {
1907
- type: TYPE.literal,
1902
+ type: 0,
1908
1903
  value: `<${tagName}/>`,
1909
1904
  location: createLocation(startPosition, this.clonePosition())
1910
1905
  },
@@ -1916,22 +1911,22 @@ var Parser = class {
1916
1911
  const children = childrenResult.val;
1917
1912
  const endTagStartPosition = this.clonePosition();
1918
1913
  if (this.bumpIf("</")) {
1919
- if (this.isEOF() || !_isAlpha(this.char())) return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
1914
+ if (this.isEOF() || !_isAlpha(this.char())) return this.error(23, createLocation(endTagStartPosition, this.clonePosition()));
1920
1915
  const closingTagNameStartPosition = this.clonePosition();
1921
- if (tagName !== this.parseTagName()) return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition()));
1916
+ if (tagName !== this.parseTagName()) return this.error(26, createLocation(closingTagNameStartPosition, this.clonePosition()));
1922
1917
  this.bumpSpace();
1923
- if (!this.bumpIf(">")) return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
1918
+ if (!this.bumpIf(">")) return this.error(23, createLocation(endTagStartPosition, this.clonePosition()));
1924
1919
  return {
1925
1920
  val: {
1926
- type: TYPE.tag,
1921
+ type: 8,
1927
1922
  value: tagName,
1928
1923
  children,
1929
1924
  location: createLocation(startPosition, this.clonePosition())
1930
1925
  },
1931
1926
  err: null
1932
1927
  };
1933
- } else return this.error(ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition()));
1934
- } else return this.error(ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition()));
1928
+ } else return this.error(27, createLocation(startPosition, this.clonePosition()));
1929
+ } else return this.error(23, createLocation(startPosition, this.clonePosition()));
1935
1930
  }
1936
1931
  /**
1937
1932
  * This method assumes that the caller has peeked ahead for the first tag character.
@@ -1966,7 +1961,7 @@ var Parser = class {
1966
1961
  const location = createLocation(start, this.clonePosition());
1967
1962
  return {
1968
1963
  val: {
1969
- type: TYPE.literal,
1964
+ type: 0,
1970
1965
  value,
1971
1966
  location
1972
1967
  },
@@ -2031,21 +2026,21 @@ var Parser = class {
2031
2026
  const openingBracePosition = this.clonePosition();
2032
2027
  this.bump();
2033
2028
  this.bumpSpace();
2034
- if (this.isEOF()) return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
2029
+ if (this.isEOF()) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
2035
2030
  if (this.char() === 125) {
2036
2031
  this.bump();
2037
- return this.error(ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
2032
+ return this.error(2, createLocation(openingBracePosition, this.clonePosition()));
2038
2033
  }
2039
2034
  let value = this.parseIdentifierIfPossible().value;
2040
- if (!value) return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
2035
+ if (!value) return this.error(3, createLocation(openingBracePosition, this.clonePosition()));
2041
2036
  this.bumpSpace();
2042
- if (this.isEOF()) return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
2037
+ if (this.isEOF()) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
2043
2038
  switch (this.char()) {
2044
2039
  case 125:
2045
2040
  this.bump();
2046
2041
  return {
2047
2042
  val: {
2048
- type: TYPE.argument,
2043
+ type: 1,
2049
2044
  value,
2050
2045
  location: createLocation(openingBracePosition, this.clonePosition())
2051
2046
  },
@@ -2054,9 +2049,9 @@ var Parser = class {
2054
2049
  case 44:
2055
2050
  this.bump();
2056
2051
  this.bumpSpace();
2057
- if (this.isEOF()) return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
2052
+ if (this.isEOF()) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
2058
2053
  return this.parseArgumentOptions(nestingLevel, expectingCloseTag, value, openingBracePosition);
2059
- default: return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
2054
+ default: return this.error(3, createLocation(openingBracePosition, this.clonePosition()));
2060
2055
  }
2061
2056
  }
2062
2057
  /**
@@ -2079,7 +2074,7 @@ var Parser = class {
2079
2074
  let argType = this.parseIdentifierIfPossible().value;
2080
2075
  let typeEndPosition = this.clonePosition();
2081
2076
  switch (argType) {
2082
- case "": return this.error(ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
2077
+ case "": return this.error(4, createLocation(typeStartPosition, typeEndPosition));
2083
2078
  case "number":
2084
2079
  case "date":
2085
2080
  case "time": {
@@ -2091,7 +2086,7 @@ var Parser = class {
2091
2086
  const result = this.parseSimpleArgStyleIfPossible();
2092
2087
  if (result.err) return result;
2093
2088
  const style = trimEnd(result.val);
2094
- if (style.length === 0) return this.error(ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition()));
2089
+ if (style.length === 0) return this.error(6, createLocation(this.clonePosition(), this.clonePosition()));
2095
2090
  styleAndLocation = {
2096
2091
  style,
2097
2092
  styleLocation: createLocation(styleStartPosition, this.clonePosition())
@@ -2107,7 +2102,7 @@ var Parser = class {
2107
2102
  if (result.err) return result;
2108
2103
  return {
2109
2104
  val: {
2110
- type: TYPE.number,
2105
+ type: 2,
2111
2106
  value,
2112
2107
  location,
2113
2108
  style: result.val
@@ -2115,18 +2110,18 @@ var Parser = class {
2115
2110
  err: null
2116
2111
  };
2117
2112
  } else {
2118
- if (skeleton.length === 0) return this.error(ErrorKind.EXPECT_DATE_TIME_SKELETON, location);
2113
+ if (skeleton.length === 0) return this.error(10, location);
2119
2114
  let dateTimePattern = skeleton;
2120
2115
  if (this.locale) dateTimePattern = getBestPattern(skeleton, this.locale);
2121
2116
  const style = {
2122
- type: SKELETON_TYPE.dateTime,
2117
+ type: 1,
2123
2118
  pattern: dateTimePattern,
2124
2119
  location: styleAndLocation.styleLocation,
2125
2120
  parsedOptions: this.shouldParseSkeletons ? parseDateTimeSkeleton(dateTimePattern) : {}
2126
2121
  };
2127
2122
  return {
2128
2123
  val: {
2129
- type: argType === "date" ? TYPE.date : TYPE.time,
2124
+ type: argType === "date" ? 3 : 4,
2130
2125
  value,
2131
2126
  location,
2132
2127
  style
@@ -2137,7 +2132,7 @@ var Parser = class {
2137
2132
  }
2138
2133
  return {
2139
2134
  val: {
2140
- type: argType === "number" ? TYPE.number : argType === "date" ? TYPE.date : TYPE.time,
2135
+ type: argType === "number" ? 2 : argType === "date" ? 3 : 4,
2141
2136
  value,
2142
2137
  location,
2143
2138
  style: styleAndLocation?.style ?? null
@@ -2150,14 +2145,14 @@ var Parser = class {
2150
2145
  case "select": {
2151
2146
  const typeEndPosition = this.clonePosition();
2152
2147
  this.bumpSpace();
2153
- if (!this.bumpIf(",")) return this.error(ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition, { ...typeEndPosition }));
2148
+ if (!this.bumpIf(",")) return this.error(12, createLocation(typeEndPosition, { ...typeEndPosition }));
2154
2149
  this.bumpSpace();
2155
2150
  let identifierAndLocation = this.parseIdentifierIfPossible();
2156
2151
  let pluralOffset = 0;
2157
2152
  if (argType !== "select" && identifierAndLocation.value === "offset") {
2158
- if (!this.bumpIf(":")) return this.error(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition()));
2153
+ if (!this.bumpIf(":")) return this.error(13, createLocation(this.clonePosition(), this.clonePosition()));
2159
2154
  this.bumpSpace();
2160
- const result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, ErrorKind.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE);
2155
+ const result = this.tryParseDecimalInteger(13, 14);
2161
2156
  if (result.err) return result;
2162
2157
  this.bumpSpace();
2163
2158
  identifierAndLocation = this.parseIdentifierIfPossible();
@@ -2170,7 +2165,7 @@ var Parser = class {
2170
2165
  const location = createLocation(openingBracePosition, this.clonePosition());
2171
2166
  if (argType === "select") return {
2172
2167
  val: {
2173
- type: TYPE.select,
2168
+ type: 5,
2174
2169
  value,
2175
2170
  options: fromEntries(optionsResult.val),
2176
2171
  location
@@ -2179,7 +2174,7 @@ var Parser = class {
2179
2174
  };
2180
2175
  else return {
2181
2176
  val: {
2182
- type: TYPE.plural,
2177
+ type: 6,
2183
2178
  value,
2184
2179
  options: fromEntries(optionsResult.val),
2185
2180
  offset: pluralOffset,
@@ -2189,11 +2184,11 @@ var Parser = class {
2189
2184
  err: null
2190
2185
  };
2191
2186
  }
2192
- default: return this.error(ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
2187
+ default: return this.error(5, createLocation(typeStartPosition, typeEndPosition));
2193
2188
  }
2194
2189
  }
2195
2190
  tryParseArgumentClose(openingBracePosition) {
2196
- if (this.isEOF() || this.char() !== 125) return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
2191
+ if (this.isEOF() || this.char() !== 125) return this.error(1, createLocation(openingBracePosition, this.clonePosition()));
2197
2192
  this.bump();
2198
2193
  return {
2199
2194
  val: true,
@@ -2210,7 +2205,7 @@ var Parser = class {
2210
2205
  case 39: {
2211
2206
  this.bump();
2212
2207
  let apostrophePosition = this.clonePosition();
2213
- if (!this.bumpUntil("'")) return this.error(ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition()));
2208
+ if (!this.bumpUntil("'")) return this.error(11, createLocation(apostrophePosition, this.clonePosition()));
2214
2209
  this.bump();
2215
2210
  break;
2216
2211
  }
@@ -2239,11 +2234,11 @@ var Parser = class {
2239
2234
  try {
2240
2235
  tokens = parseNumberSkeletonFromString(skeleton);
2241
2236
  } catch {
2242
- return this.error(ErrorKind.INVALID_NUMBER_SKELETON, location);
2237
+ return this.error(7, location);
2243
2238
  }
2244
2239
  return {
2245
2240
  val: {
2246
- type: SKELETON_TYPE.number,
2241
+ type: 0,
2247
2242
  tokens,
2248
2243
  location,
2249
2244
  parsedOptions: this.shouldParseSkeletons ? parseNumberSkeleton(tokens) : {}
@@ -2270,17 +2265,17 @@ var Parser = class {
2270
2265
  if (selector.length === 0) {
2271
2266
  const startPosition = this.clonePosition();
2272
2267
  if (parentArgType !== "select" && this.bumpIf("=")) {
2273
- const result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR);
2268
+ const result = this.tryParseDecimalInteger(16, 19);
2274
2269
  if (result.err) return result;
2275
2270
  selectorLocation = createLocation(startPosition, this.clonePosition());
2276
2271
  selector = this.message.slice(startPosition.offset, this.offset());
2277
2272
  } else break;
2278
2273
  }
2279
- if (parsedSelectors.has(selector)) return this.error(parentArgType === "select" ? ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR : ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation);
2274
+ if (parsedSelectors.has(selector)) return this.error(parentArgType === "select" ? 21 : 20, selectorLocation);
2280
2275
  if (selector === "other") hasOtherClause = true;
2281
2276
  this.bumpSpace();
2282
2277
  const openingBracePosition = this.clonePosition();
2283
- if (!this.bumpIf("{")) return this.error(parentArgType === "select" ? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT : ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition()));
2278
+ if (!this.bumpIf("{")) return this.error(parentArgType === "select" ? 17 : 18, createLocation(this.clonePosition(), this.clonePosition()));
2284
2279
  const fragmentResult = this.parseMessage(nestingLevel + 1, parentArgType, expectCloseTag);
2285
2280
  if (fragmentResult.err) return fragmentResult;
2286
2281
  const argCloseResult = this.tryParseArgumentClose(openingBracePosition);
@@ -2293,8 +2288,8 @@ var Parser = class {
2293
2288
  this.bumpSpace();
2294
2289
  ({value: selector, location: selectorLocation} = this.parseIdentifierIfPossible());
2295
2290
  }
2296
- if (options.length === 0) return this.error(parentArgType === "select" ? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR : ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, createLocation(this.clonePosition(), this.clonePosition()));
2297
- if (this.requiresOtherClause && !hasOtherClause) return this.error(ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition()));
2291
+ if (options.length === 0) return this.error(parentArgType === "select" ? 15 : 16, createLocation(this.clonePosition(), this.clonePosition()));
2292
+ if (this.requiresOtherClause && !hasOtherClause) return this.error(22, createLocation(this.clonePosition(), this.clonePosition()));
2298
2293
  return {
2299
2294
  val: options,
2300
2295
  err: null
@@ -2498,29 +2493,24 @@ var FormatError = class extends Error {
2498
2493
  };
2499
2494
  var InvalidValueError = class extends FormatError {
2500
2495
  constructor(variableId, value, options, originalMessage) {
2501
- super(`Invalid values for "${variableId}": "${value}". Options are "${Object.keys(options).join("\", \"")}"`, ErrorCode.INVALID_VALUE, originalMessage);
2496
+ super(`Invalid values for "${variableId}": "${value}". Options are "${Object.keys(options).join("\", \"")}"`, "INVALID_VALUE", originalMessage);
2502
2497
  }
2503
2498
  };
2504
2499
  var InvalidValueTypeError = class extends FormatError {
2505
2500
  constructor(value, type, originalMessage) {
2506
- super(`Value for "${value}" must be of type ${type}`, ErrorCode.INVALID_VALUE, originalMessage);
2501
+ super(`Value for "${value}" must be of type ${type}`, "INVALID_VALUE", originalMessage);
2507
2502
  }
2508
2503
  };
2509
2504
  var MissingValueError = class extends FormatError {
2510
2505
  constructor(variableId, originalMessage) {
2511
- super(`The intl string context variable "${variableId}" was not provided to the string "${originalMessage}"`, ErrorCode.MISSING_VALUE, originalMessage);
2506
+ super(`The intl string context variable "${variableId}" was not provided to the string "${originalMessage}"`, "MISSING_VALUE", originalMessage);
2512
2507
  }
2513
2508
  };
2514
- let PART_TYPE = /* @__PURE__ */ function(PART_TYPE) {
2515
- PART_TYPE[PART_TYPE["literal"] = 0] = "literal";
2516
- PART_TYPE[PART_TYPE["object"] = 1] = "object";
2517
- return PART_TYPE;
2518
- }({});
2519
2509
  function mergeLiteral(parts) {
2520
2510
  if (parts.length < 2) return parts;
2521
2511
  return parts.reduce((all, part) => {
2522
2512
  const lastPart = all[all.length - 1];
2523
- if (!lastPart || lastPart.type !== PART_TYPE.literal || part.type !== PART_TYPE.literal) all.push(part);
2513
+ if (!lastPart || lastPart.type !== 0 || part.type !== 0) all.push(part);
2524
2514
  else lastPart.value += part.value;
2525
2515
  return all;
2526
2516
  }, []);
@@ -2530,21 +2520,21 @@ function isFormatXMLElementFn(el) {
2530
2520
  }
2531
2521
  function formatToParts(els, locales, formatters, formats, values, currentPluralValue, originalMessage) {
2532
2522
  if (els.length === 1 && isLiteralElement(els[0])) return [{
2533
- type: PART_TYPE.literal,
2523
+ type: 0,
2534
2524
  value: els[0].value
2535
2525
  }];
2536
2526
  const result = [];
2537
2527
  for (const el of els) {
2538
2528
  if (isLiteralElement(el)) {
2539
2529
  result.push({
2540
- type: PART_TYPE.literal,
2530
+ type: 0,
2541
2531
  value: el.value
2542
2532
  });
2543
2533
  continue;
2544
2534
  }
2545
2535
  if (isPoundElement(el)) {
2546
2536
  if (typeof currentPluralValue === "number") result.push({
2547
- type: PART_TYPE.literal,
2537
+ type: 0,
2548
2538
  value: formatters.getNumberFormat(locales).format(currentPluralValue)
2549
2539
  });
2550
2540
  continue;
@@ -2555,7 +2545,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2555
2545
  if (isArgumentElement(el)) {
2556
2546
  if (!value || typeof value === "string" || typeof value === "number" || typeof value === "bigint") value = typeof value === "string" || typeof value === "number" || typeof value === "bigint" ? String(value) : "";
2557
2547
  result.push({
2558
- type: typeof value === "string" ? PART_TYPE.literal : PART_TYPE.object,
2548
+ type: typeof value === "string" ? 0 : 1,
2559
2549
  value
2560
2550
  });
2561
2551
  continue;
@@ -2563,7 +2553,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2563
2553
  if (isDateElement(el)) {
2564
2554
  const style = typeof el.style === "string" ? formats.date[el.style] : isDateTimeSkeleton(el.style) ? el.style.parsedOptions : void 0;
2565
2555
  result.push({
2566
- type: PART_TYPE.literal,
2556
+ type: 0,
2567
2557
  value: formatters.getDateTimeFormat(locales, style).format(value)
2568
2558
  });
2569
2559
  continue;
@@ -2571,7 +2561,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2571
2561
  if (isTimeElement(el)) {
2572
2562
  const style = typeof el.style === "string" ? formats.time[el.style] : isDateTimeSkeleton(el.style) ? el.style.parsedOptions : formats.time.medium;
2573
2563
  result.push({
2574
- type: PART_TYPE.literal,
2564
+ type: 0,
2575
2565
  value: formatters.getDateTimeFormat(locales, style).format(value)
2576
2566
  });
2577
2567
  continue;
@@ -2586,7 +2576,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2586
2576
  } else value = value * scale;
2587
2577
  }
2588
2578
  result.push({
2589
- type: PART_TYPE.literal,
2579
+ type: 0,
2590
2580
  value: formatters.getNumberFormat(locales, style).format(value)
2591
2581
  });
2592
2582
  continue;
@@ -2599,7 +2589,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2599
2589
  if (!Array.isArray(chunks)) chunks = [chunks];
2600
2590
  result.push(...chunks.map((c) => {
2601
2591
  return {
2602
- type: typeof c === "string" ? PART_TYPE.literal : PART_TYPE.object,
2592
+ type: typeof c === "string" ? 0 : 1,
2603
2593
  value: c
2604
2594
  };
2605
2595
  }));
@@ -2617,7 +2607,7 @@ function formatToParts(els, locales, formatters, formats, values, currentPluralV
2617
2607
  if (!opt) {
2618
2608
  if (!Intl.PluralRules) throw new FormatError(`Intl.PluralRules is not available in this environment.
2619
2609
  Try polyfilling it using "@formatjs/intl-pluralrules"
2620
- `, ErrorCode.MISSING_INTL_API, originalMessage);
2610
+ `, "MISSING_INTL_API", originalMessage);
2621
2611
  const numericValue = typeof value === "bigint" ? Number(value) : value;
2622
2612
  const rule = formatters.getPluralRules(locales, { type: el.pluralType }).select(numericValue - (el.offset || 0));
2623
2613
  opt = (Object.prototype.hasOwnProperty.call(el.options, rule) ? el.options[rule] : void 0) || el.options.other;
@@ -2694,7 +2684,7 @@ var IntlMessageFormat = class IntlMessageFormat {
2694
2684
  const parts = this.formatToParts(values);
2695
2685
  if (parts.length === 1) return parts[0].value;
2696
2686
  const result = parts.reduce((all, part) => {
2697
- if (!all.length || part.type !== PART_TYPE.literal || typeof all[all.length - 1] !== "string") all.push(part.value);
2687
+ if (!all.length || part.type !== 0 || typeof all[all.length - 1] !== "string") all.push(part.value);
2698
2688
  else all[all.length - 1] += part.value;
2699
2689
  return all;
2700
2690
  }, []);
@@ -2814,22 +2804,22 @@ ${err ? `\n${err.message}\n${err.stack}` : ""}`);
2814
2804
  };
2815
2805
  var UnsupportedFormatterError = class extends IntlError {
2816
2806
  constructor(message, exception) {
2817
- super(IntlErrorCode.UNSUPPORTED_FORMATTER, message, exception);
2807
+ super("UNSUPPORTED_FORMATTER", message, exception);
2818
2808
  }
2819
2809
  };
2820
2810
  var InvalidConfigError = class extends IntlError {
2821
2811
  constructor(message, exception) {
2822
- super(IntlErrorCode.INVALID_CONFIG, message, exception);
2812
+ super("INVALID_CONFIG", message, exception);
2823
2813
  }
2824
2814
  };
2825
2815
  var MissingDataError = class extends IntlError {
2826
2816
  constructor(message, exception) {
2827
- super(IntlErrorCode.MISSING_DATA, message, exception);
2817
+ super("MISSING_DATA", message, exception);
2828
2818
  }
2829
2819
  };
2830
2820
  var IntlFormatError = class extends IntlError {
2831
2821
  constructor(message, locale, exception) {
2832
- super(IntlErrorCode.FORMAT_ERROR, `${message}
2822
+ super("FORMAT_ERROR", `${message}
2833
2823
  Locale: ${locale}
2834
2824
  `, exception);
2835
2825
  this.locale = locale;
@@ -2848,7 +2838,7 @@ Description: ${descriptor?.description}
2848
2838
  };
2849
2839
  var MissingTranslationError = class extends IntlError {
2850
2840
  constructor(descriptor, locale) {
2851
- super(IntlErrorCode.MISSING_TRANSLATION, `Missing message: "${descriptor.id}" for locale "${locale}", using ${descriptor.defaultMessage ? `default message (${typeof descriptor.defaultMessage === "string" ? descriptor.defaultMessage : descriptor.defaultMessage.map((e) => e.value ?? JSON.stringify(e)).join()})` : "id"} as fallback.`);
2841
+ super("MISSING_TRANSLATION", `Missing message: "${descriptor.id}" for locale "${locale}", using ${descriptor.defaultMessage ? `default message (${typeof descriptor.defaultMessage === "string" ? descriptor.defaultMessage : descriptor.defaultMessage.map((e) => e.value ?? JSON.stringify(e)).join()})` : "id"} as fallback.`);
2852
2842
  this.descriptor = descriptor;
2853
2843
  }
2854
2844
  };
@@ -3377,7 +3367,7 @@ const FormattedListParts = (props) => {
3377
3367
  const { value, children, ...formatProps } = props;
3378
3368
  return children(intl.formatListToParts(value, formatProps));
3379
3369
  };
3380
- FormattedNumberParts.displayName = "FormattedNumberParts";
3370
+ FormattedListParts.displayName = "FormattedListParts";
3381
3371
  function createFormattedDateTimePartsComponent(name) {
3382
3372
  const ComponentParts = (props) => {
3383
3373
  const intl = useIntl();
package/server.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","names":["DEFAULT_INTL_CONFIG","CORE_DEFAULT_INTL_CONFIG","formatMessage","coreFormatMessage","coreCreateIntl","DEFAULT_INTL_CONFIG"],"sources":["../utils.tsx","../components/createIntl.ts","../server.ts"],"sourcesContent":["import {type FormatXMLElementFn} from 'intl-messageformat'\nimport * as React from 'react'\nimport {type ResolvedIntlConfig} from '#packages/react-intl/types.js'\n\nimport {DEFAULT_INTL_CONFIG as CORE_DEFAULT_INTL_CONFIG} from '@formatjs/intl'\n\nexport function invariant(\n condition: boolean,\n message: string,\n Err: any = Error\n): asserts condition {\n if (!condition) {\n throw new Err(message)\n }\n}\n\nexport function invariantIntlContext(intl?: any): asserts intl {\n invariant(\n intl,\n '[React Intl] Could not find required `intl` object. ' +\n '<IntlProvider> needs to exist in the component ancestry.'\n )\n}\n\nexport type DefaultIntlConfig = Pick<\n ResolvedIntlConfig,\n | 'fallbackOnEmptyString'\n | 'formats'\n | 'messages'\n | 'timeZone'\n | 'textComponent'\n | 'defaultLocale'\n | 'defaultFormats'\n | 'onError'\n>\n\nexport const DEFAULT_INTL_CONFIG: DefaultIntlConfig = {\n ...CORE_DEFAULT_INTL_CONFIG,\n textComponent: React.Fragment,\n}\n\n/**\n * Builds an array of {@link React.ReactNode}s with index-based keys, similar to\n * {@link React.Children.toArray}. However, this function tells React that it\n * was intentional, so they won't produce a bunch of warnings about it.\n *\n * React doesn't recommend doing this because it makes reordering inefficient,\n * but we mostly need this for message chunks, which don't tend to reorder to\n * begin with.\n *\n */\nexport const toKeyedReactNodeArray: typeof React.Children.toArray =\n children => {\n const childrenArray = React.Children.toArray(children)\n\n return childrenArray.map((child, index) => {\n // For React elements, wrap in a keyed Fragment\n // This creates a new element with a key rather than trying to add one after creation\n if (React.isValidElement(child)) {\n return <React.Fragment key={index}>{child}</React.Fragment>\n }\n return child\n })\n }\n\n/**\n * Takes a `formatXMLElementFn`, and composes it in function, which passes\n * argument `parts` through, assigning unique key to each part, to prevent\n * \"Each child in a list should have a unique \"key\"\" React error.\n * @param formatXMLElementFn\n */\nexport function assignUniqueKeysToParts(\n formatXMLElementFn: FormatXMLElementFn<React.ReactNode>\n): FormatXMLElementFn<React.ReactNode> {\n return function (parts: any) {\n // eslint-disable-next-line prefer-rest-params\n return formatXMLElementFn(toKeyedReactNodeArray(parts)) as any\n }\n}\n\nexport function shallowEqual<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(objA?: T, objB?: T): boolean {\n if (objA === objB) {\n return true\n }\n\n if (!objA || !objB) {\n return false\n }\n\n var aKeys = Object.keys(objA)\n var bKeys = Object.keys(objB)\n var len = aKeys.length\n\n if (bKeys.length !== len) {\n return false\n }\n\n for (var i = 0; i < len; i++) {\n var key = aKeys[i]\n\n if (\n objA[key] !== objB[key] ||\n !Object.prototype.hasOwnProperty.call(objB, key)\n ) {\n return false\n }\n }\n\n return true\n}\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\n\nimport {\n type CreateIntlFn,\n type FormatMessageFn,\n createIntl as coreCreateIntl,\n formatMessage as coreFormatMessage,\n} from '@formatjs/intl'\nimport {\n type FormatXMLElementFn,\n type PrimitiveType,\n isFormatXMLElementFn,\n} from 'intl-messageformat'\nimport * as React from 'react'\nimport type {\n IntlConfig,\n IntlShape,\n ResolvedIntlConfig,\n} from '#packages/react-intl/types.js'\nimport {\n DEFAULT_INTL_CONFIG,\n assignUniqueKeysToParts,\n toKeyedReactNodeArray,\n} from '#packages/react-intl/utils.js'\n\nfunction assignUniqueKeysToFormatXMLElementFnArgument<\n T extends Record<\n string,\n | PrimitiveType\n | React.ReactNode\n | FormatXMLElementFn<React.ReactNode, React.ReactNode>\n > = Record<\n string,\n | PrimitiveType\n | React.ReactNode\n | FormatXMLElementFn<React.ReactNode, React.ReactNode>\n >,\n>(values?: T): T | undefined {\n if (!values) {\n return values\n }\n return Object.keys(values).reduce((acc: T, k) => {\n const v = values[k]\n ;(acc as any)[k] = isFormatXMLElementFn<React.ReactNode>(v)\n ? assignUniqueKeysToParts(v)\n : v\n return acc\n }, {} as T)\n}\n\nconst formatMessage: FormatMessageFn<React.ReactNode> = (\n config,\n formatters,\n descriptor,\n rawValues,\n ...rest\n) => {\n const values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues)\n const chunks = coreFormatMessage(\n config,\n formatters,\n descriptor,\n values as any,\n ...rest\n )\n if (Array.isArray(chunks)) {\n return toKeyedReactNodeArray(chunks)\n }\n return chunks\n}\n\n/**\n * Create intl object\n * @param config intl config\n * @param cache cache for formatter instances to prevent memory leak\n */\nexport const createIntl: CreateIntlFn<\n React.ReactNode,\n IntlConfig,\n IntlShape\n> = (\n {defaultRichTextElements: rawDefaultRichTextElements, ...config},\n cache\n) => {\n const defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(\n rawDefaultRichTextElements\n )\n const coreIntl = coreCreateIntl<React.ReactNode>(\n {\n ...DEFAULT_INTL_CONFIG,\n ...config,\n defaultRichTextElements,\n },\n cache\n )\n\n const resolvedConfig: ResolvedIntlConfig = {\n locale: coreIntl.locale,\n timeZone: coreIntl.timeZone,\n fallbackOnEmptyString: coreIntl.fallbackOnEmptyString,\n formats: coreIntl.formats,\n defaultLocale: coreIntl.defaultLocale,\n defaultFormats: coreIntl.defaultFormats,\n messages: coreIntl.messages,\n onError: coreIntl.onError,\n defaultRichTextElements,\n }\n\n return {\n ...coreIntl,\n formatMessage: formatMessage.bind(\n null,\n resolvedConfig,\n coreIntl.formatters\n ),\n $t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters),\n } as any\n}\n","import {type MessageDescriptor} from '@formatjs/intl'\n\nexport {\n createIntlCache,\n type IntlCache,\n type MessageDescriptor,\n} from '@formatjs/intl'\nexport {createIntl} from '#packages/react-intl/components/createIntl.js'\nexport type {\n IntlConfig,\n IntlShape,\n ResolvedIntlConfig,\n} from '#packages/react-intl/types.js'\n\n// Identity functions — duplicated here to avoid importing from \"use client\" index\nexport function defineMessages<\n K extends keyof any,\n T = MessageDescriptor,\n U extends Record<K, T> = Record<K, T>,\n>(msgs: U): U {\n return msgs\n}\n\nexport function defineMessage<T extends MessageDescriptor>(msg: T): T {\n return msg\n}\n"],"mappings":";;;;;AAoCA,MAAaA,wBAAyC;CACpD,GAAGC;CACH,eAAe,MAAM;CACtB;;;;;;;;;;;AAYD,MAAa,yBACX,aAAY;AAGV,QAFsB,MAAM,SAAS,QAAQ,SAAS,CAEjC,KAAK,OAAO,UAAU;AAGzC,MAAI,MAAM,eAAe,MAAM,CAC7B,QAAO,oBAAC,MAAM,UAAP,EAAA,UAA6B,OAAuB,EAA/B,MAA+B;AAE7D,SAAO;GACP;;;;;;;;AASN,SAAgB,wBACd,oBACqC;AACrC,QAAO,SAAU,OAAY;AAE3B,SAAO,mBAAmB,sBAAsB,MAAM,CAAC;;;;;AC/C3D,SAAS,6CAYP,QAA2B;AAC3B,KAAI,CAAC,OACH,QAAO;AAET,QAAO,OAAO,KAAK,OAAO,CAAC,QAAQ,KAAQ,MAAM;EAC/C,MAAM,IAAI,OAAO;AACf,MAAY,KAAK,qBAAsC,EAAE,GACvD,wBAAwB,EAAE,GAC1B;AACJ,SAAO;IACN,EAAE,CAAM;;AAGb,MAAMC,mBACJ,QACA,YACA,YACA,WACA,GAAG,SACA;CAEH,MAAM,SAASC,cACb,QACA,YACA,YAJa,6CAA6C,UAAU,EAMpE,GAAG,KACJ;AACD,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,sBAAsB,OAAO;AAEtC,QAAO;;;;;;;AAQT,MAAa,cAKX,EAAC,yBAAyB,4BAA4B,GAAG,UACzD,UACG;CACH,MAAM,0BAA0B,6CAC9B,2BACD;CACD,MAAM,WAAWC,aACf;EACE,GAAGC;EACH,GAAG;EACH;EACD,EACD,MACD;CAED,MAAM,iBAAqC;EACzC,QAAQ,SAAS;EACjB,UAAU,SAAS;EACnB,uBAAuB,SAAS;EAChC,SAAS,SAAS;EAClB,eAAe,SAAS;EACxB,gBAAgB,SAAS;EACzB,UAAU,SAAS;EACnB,SAAS,SAAS;EAClB;EACD;AAED,QAAO;EACL,GAAG;EACH,eAAeH,gBAAc,KAC3B,MACA,gBACA,SAAS,WACV;EACD,IAAIA,gBAAc,KAAK,MAAM,gBAAgB,SAAS,WAAW;EAClE;;;;ACzGH,SAAgB,eAId,MAAY;AACZ,QAAO;;AAGT,SAAgB,cAA2C,KAAW;AACpE,QAAO"}
1
+ {"version":3,"file":"server.js","names":["DEFAULT_INTL_CONFIG","CORE_DEFAULT_INTL_CONFIG","formatMessage","coreFormatMessage","coreCreateIntl","DEFAULT_INTL_CONFIG"],"sources":["../utils.tsx","../components/createIntl.ts","../server.ts"],"sourcesContent":["import {type FormatXMLElementFn} from 'intl-messageformat'\nimport * as React from 'react'\nimport {type ResolvedIntlConfig} from '#packages/react-intl/types.js'\n\nimport {DEFAULT_INTL_CONFIG as CORE_DEFAULT_INTL_CONFIG} from '@formatjs/intl'\n\nexport function invariant(\n condition: boolean,\n message: string,\n Err: any = Error\n): asserts condition {\n if (!condition) {\n throw new Err(message)\n }\n}\n\nexport function invariantIntlContext(intl?: any): asserts intl {\n invariant(\n intl,\n '[React Intl] Could not find required `intl` object. ' +\n '<IntlProvider> needs to exist in the component ancestry.'\n )\n}\n\nexport type DefaultIntlConfig = Pick<\n ResolvedIntlConfig,\n | 'fallbackOnEmptyString'\n | 'formats'\n | 'messages'\n | 'timeZone'\n | 'textComponent'\n | 'defaultLocale'\n | 'defaultFormats'\n | 'onError'\n>\n\nexport const DEFAULT_INTL_CONFIG: DefaultIntlConfig = {\n ...CORE_DEFAULT_INTL_CONFIG,\n textComponent: React.Fragment,\n}\n\n/**\n * Builds an array of {@link React.ReactNode}s with index-based keys, similar to\n * {@link React.Children.toArray}. However, this function tells React that it\n * was intentional, so they won't produce a bunch of warnings about it.\n *\n * React doesn't recommend doing this because it makes reordering inefficient,\n * but we mostly need this for message chunks, which don't tend to reorder to\n * begin with.\n *\n */\nexport const toKeyedReactNodeArray: typeof React.Children.toArray =\n children => {\n const childrenArray = React.Children.toArray(children)\n\n return childrenArray.map((child, index) => {\n // For React elements, wrap in a keyed Fragment\n // This creates a new element with a key rather than trying to add one after creation\n if (React.isValidElement(child)) {\n return <React.Fragment key={index}>{child}</React.Fragment>\n }\n return child\n })\n }\n\n/**\n * Takes a `formatXMLElementFn`, and composes it in function, which passes\n * argument `parts` through, assigning unique key to each part, to prevent\n * \"Each child in a list should have a unique \"key\"\" React error.\n * @param formatXMLElementFn\n */\nexport function assignUniqueKeysToParts(\n formatXMLElementFn: FormatXMLElementFn<React.ReactNode>\n): FormatXMLElementFn<React.ReactNode> {\n return function (parts: any) {\n // eslint-disable-next-line prefer-rest-params\n return formatXMLElementFn(toKeyedReactNodeArray(parts)) as any\n }\n}\n\nexport function shallowEqual<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(objA?: T, objB?: T): boolean {\n if (objA === objB) {\n return true\n }\n\n if (!objA || !objB) {\n return false\n }\n\n var aKeys = Object.keys(objA)\n var bKeys = Object.keys(objB)\n var len = aKeys.length\n\n if (bKeys.length !== len) {\n return false\n }\n\n for (var i = 0; i < len; i++) {\n var key = aKeys[i]\n\n if (\n objA[key] !== objB[key] ||\n !Object.prototype.hasOwnProperty.call(objB, key)\n ) {\n return false\n }\n }\n\n return true\n}\n","/*\n * Copyright 2015, Yahoo Inc.\n * Copyrights licensed under the New BSD License.\n * See the accompanying LICENSE file for terms.\n */\n\nimport {\n type CreateIntlFn,\n type FormatMessageFn,\n createIntl as coreCreateIntl,\n formatMessage as coreFormatMessage,\n} from '@formatjs/intl'\nimport {\n type FormatXMLElementFn,\n type PrimitiveType,\n isFormatXMLElementFn,\n} from 'intl-messageformat'\nimport * as React from 'react'\nimport type {\n IntlConfig,\n IntlShape,\n ResolvedIntlConfig,\n} from '#packages/react-intl/types.js'\nimport {\n DEFAULT_INTL_CONFIG,\n assignUniqueKeysToParts,\n toKeyedReactNodeArray,\n} from '#packages/react-intl/utils.js'\n\nfunction assignUniqueKeysToFormatXMLElementFnArgument<\n T extends Record<\n string,\n | PrimitiveType\n | React.ReactNode\n | FormatXMLElementFn<React.ReactNode, React.ReactNode>\n > = Record<\n string,\n | PrimitiveType\n | React.ReactNode\n | FormatXMLElementFn<React.ReactNode, React.ReactNode>\n >,\n>(values?: T): T | undefined {\n if (!values) {\n return values\n }\n return Object.keys(values).reduce((acc: T, k) => {\n const v = values[k]\n ;(acc as any)[k] = isFormatXMLElementFn<React.ReactNode>(v)\n ? assignUniqueKeysToParts(v)\n : v\n return acc\n }, {} as T)\n}\n\nconst formatMessage: FormatMessageFn<React.ReactNode> = (\n config,\n formatters,\n descriptor,\n rawValues,\n ...rest\n) => {\n const values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues)\n const chunks = coreFormatMessage(\n config,\n formatters,\n descriptor,\n values as any,\n ...rest\n )\n if (Array.isArray(chunks)) {\n return toKeyedReactNodeArray(chunks)\n }\n return chunks\n}\n\n/**\n * Create intl object\n * @param config intl config\n * @param cache cache for formatter instances to prevent memory leak\n */\nexport const createIntl: CreateIntlFn<\n React.ReactNode,\n IntlConfig,\n IntlShape\n> = (\n {defaultRichTextElements: rawDefaultRichTextElements, ...config},\n cache\n) => {\n const defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(\n rawDefaultRichTextElements\n )\n const coreIntl = coreCreateIntl<React.ReactNode>(\n {\n ...DEFAULT_INTL_CONFIG,\n ...config,\n defaultRichTextElements,\n },\n cache\n )\n\n const resolvedConfig: ResolvedIntlConfig = {\n locale: coreIntl.locale,\n timeZone: coreIntl.timeZone,\n fallbackOnEmptyString: coreIntl.fallbackOnEmptyString,\n formats: coreIntl.formats,\n defaultLocale: coreIntl.defaultLocale,\n defaultFormats: coreIntl.defaultFormats,\n messages: coreIntl.messages,\n onError: coreIntl.onError,\n defaultRichTextElements,\n }\n\n return {\n ...coreIntl,\n formatMessage: formatMessage.bind(\n null,\n resolvedConfig,\n coreIntl.formatters\n ),\n $t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters),\n } as any\n}\n","import {type MessageDescriptor} from '@formatjs/intl'\n\nexport {\n createIntlCache,\n type IntlCache,\n type MessageDescriptor,\n} from '@formatjs/intl'\nexport {createIntl} from '#packages/react-intl/components/createIntl.js'\nexport type {\n IntlConfig,\n IntlShape,\n ResolvedIntlConfig,\n} from '#packages/react-intl/types.js'\n\n// Identity functions — duplicated here to avoid importing from \"use client\" index\nexport function defineMessages<\n K extends keyof any,\n T = MessageDescriptor,\n U extends Record<K, T> = Record<K, T>,\n>(msgs: U): U {\n return msgs\n}\n\nexport function defineMessage<T extends MessageDescriptor>(msg: T): T {\n return msg\n}\n"],"mappings":";;;;;AAoCA,MAAaA,wBAAyC;CACpD,GAAGC;CACH,eAAe,MAAM;CACtB;;;;;;;;;;;AAYD,MAAa,yBACX,aAAY;CAGV,OAFsB,MAAM,SAAS,QAAQ,SAEzB,CAAC,KAAK,OAAO,UAAU;EAGzC,IAAI,MAAM,eAAe,MAAM,EAC7B,OAAO,oBAAC,MAAM,UAAP,EAAA,UAA6B,OAAuB,EAA/B,MAA+B;EAE7D,OAAO;GACP;;;;;;;;AASN,SAAgB,wBACd,oBACqC;CACrC,OAAO,SAAU,OAAY;EAE3B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