react-intl 10.1.1 → 10.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +169 -49
- package/index.js +346 -30
- package/index.js.map +1 -0
- package/package.json +4 -5
- package/react-intl.iife.js +3612 -8108
- package/server.d.ts +34 -10
- package/server.js +88 -6
- package/server.js.map +1 -0
- package/src/components/context.d.ts +0 -5
- package/src/components/context.js +0 -5
- package/src/components/createFormattedComponent.d.ts +0 -27
- package/src/components/createFormattedComponent.js +0 -60
- package/src/components/createIntl.d.ts +0 -9
- package/src/components/createIntl.js +0 -56
- package/src/components/dateTimeRange.d.ts +0 -9
- package/src/components/dateTimeRange.js +0 -16
- package/src/components/message.d.ts +0 -11
- package/src/components/message.js +0 -32
- package/src/components/plural.d.ts +0 -14
- package/src/components/plural.js +0 -25
- package/src/components/provider.d.ts +0 -4
- package/src/components/provider.js +0 -57
- package/src/components/relative.d.ts +0 -10
- package/src/components/relative.js +0 -120
- package/src/components/useIntl.d.ts +0 -2
- package/src/components/useIntl.js +0 -9
- package/src/types.d.ts +0 -14
- package/src/types.js +0 -8
- package/src/utils.d.ts +0 -26
- package/src/utils.js +0 -71
package/index.js.map
ADDED
|
@@ -0,0 +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,QA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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.
|
|
4
|
+
"version": "10.1.2",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"author": "Eric Ferraiuolo <edf@ericf.me>",
|
|
7
7
|
"type": "module",
|
|
@@ -12,10 +12,9 @@
|
|
|
12
12
|
"./server": "./server.js"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@formatjs/
|
|
16
|
-
"
|
|
17
|
-
"@formatjs/intl": "4.1.
|
|
18
|
-
"intl-messageformat": "11.2.0"
|
|
15
|
+
"@formatjs/icu-messageformat-parser": "3.5.4",
|
|
16
|
+
"intl-messageformat": "11.2.1",
|
|
17
|
+
"@formatjs/intl": "4.1.6"
|
|
19
18
|
},
|
|
20
19
|
"peerDependencies": {
|
|
21
20
|
"@types/react": "19",
|