react-intl
Advanced tools
+44
-34
@@ -1,46 +0,56 @@ | ||
| import { NumberFormatOptions } from '@formatjs/ecma402-abstract'; | ||
| import { CustomFormatConfig, FormatDateOptions, FormatTimeOptions, MessageDescriptor } from '@formatjs/intl'; | ||
| import * as React from 'react'; | ||
| import { createIntl } from './src/components/createIntl.js'; | ||
| import FormattedDateTimeRange from './src/components/dateTimeRange.js'; | ||
| import injectIntl, { Context as IntlContext, Provider as RawIntlProvider, WithIntlProps, WrappedComponentProps } from './src/components/injectIntl.js'; | ||
| import FormattedMessage from './src/components/message.js'; | ||
| import FormattedPlural from './src/components/plural.js'; | ||
| import IntlProvider from './src/components/provider.js'; | ||
| import FormattedRelativeTime from './src/components/relative.js'; | ||
| import useIntl from './src/components/useIntl.js'; | ||
| import { IntlShape } from './src/types.js'; | ||
| export { createIntlCache, CustomFormatConfig, CustomFormats, FormatDateOptions, FormatDisplayNameOptions, FormatListOptions, FormatNumberOptions, FormatPluralOptions, FormatRelativeTimeOptions, Formatters, IntlCache, IntlFormatters, InvalidConfigError, MessageDescriptor, MessageFormatError, MissingDataError, MissingTranslationError, IntlError as ReactIntlError, IntlErrorCode as ReactIntlErrorCode, UnsupportedFormatterError, } from '@formatjs/intl'; | ||
| export { IntlConfig, IntlShape, ResolvedIntlConfig } from './src/types.js'; | ||
| export { createIntl, FormattedDateTimeRange, FormattedMessage, FormattedPlural, FormattedRelativeTime, injectIntl, IntlContext, IntlProvider, RawIntlProvider, useIntl, WithIntlProps, WrappedComponentProps, }; | ||
| export declare function defineMessages<K extends keyof any, T = MessageDescriptor, U extends Record<K, T> = Record<K, T>>(msgs: U): U; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import { type NumberFormatOptions } from "@formatjs/ecma402-abstract"; | ||
| import { type CustomFormatConfig, type FormatDateOptions, type FormatTimeOptions, type MessageDescriptor } from "@formatjs/intl"; | ||
| import * as React from "react"; | ||
| import { createIntl } from "./src/components/createIntl.js"; | ||
| import FormattedDateTimeRange from "./src/components/dateTimeRange.js"; | ||
| import injectIntl, { Context as IntlContext, Provider as RawIntlProvider, type WithIntlProps, type WrappedComponentProps } from "./src/components/injectIntl.js"; | ||
| import FormattedMessage from "./src/components/message.js"; | ||
| import FormattedPlural from "./src/components/plural.js"; | ||
| import IntlProvider from "./src/components/provider.js"; | ||
| import FormattedRelativeTime from "./src/components/relative.js"; | ||
| import useIntl from "./src/components/useIntl.js"; | ||
| import { type IntlShape } from "./src/types.js"; | ||
| export { createIntlCache, type CustomFormatConfig, type CustomFormats, type FormatDateOptions, type FormatDisplayNameOptions, type FormatListOptions, type FormatNumberOptions, type FormatPluralOptions, type FormatRelativeTimeOptions, type Formatters, type IntlCache, type IntlFormatters, InvalidConfigError, type MessageDescriptor, MessageFormatError, MissingDataError, MissingTranslationError, IntlError as ReactIntlError, IntlErrorCode as ReactIntlErrorCode, UnsupportedFormatterError } from "@formatjs/intl"; | ||
| export { type IntlConfig, type IntlShape, type ResolvedIntlConfig } from "./src/types.js"; | ||
| export { createIntl, FormattedDateTimeRange, FormattedMessage, FormattedPlural, FormattedRelativeTime, injectIntl, IntlContext, IntlProvider, RawIntlProvider, useIntl, type WithIntlProps, type WrappedComponentProps }; | ||
| export declare function defineMessages< | ||
| K extends keyof any, | ||
| T = MessageDescriptor, | ||
| U extends Record<K, T> = Record<K, T> | ||
| >(msgs: U): U; | ||
| export declare function defineMessage<T extends MessageDescriptor>(msg: T): T; | ||
| export declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig<'date'> & { | ||
| value: string | number | Date | undefined; | ||
| children?(formattedDate: string): React.ReactElement | null; | ||
| // IMPORTANT: Explicit here to prevent api-extractor from outputing `import('./src/types').CustomFormatConfig` | ||
| export declare const FormattedDate: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig<"date"> & { | ||
| value: string | number | Date | undefined; | ||
| children?(formattedDate: string): React.ReactElement | null; | ||
| }>; | ||
| export declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig<'time'> & { | ||
| value: string | number | Date | undefined; | ||
| children?(formattedTime: string): React.ReactElement | null; | ||
| export declare const FormattedTime: React.FC<Intl.DateTimeFormatOptions & CustomFormatConfig<"time"> & { | ||
| value: string | number | Date | undefined; | ||
| children?(formattedTime: string): React.ReactElement | null; | ||
| }>; | ||
| export declare const FormattedNumber: React.FC<Omit<NumberFormatOptions, 'localeMatcher'> & CustomFormatConfig<'number'> & { | ||
| value: Parameters<IntlShape['formatNumber']>[0]; | ||
| children?(formattedNumber: string): React.ReactElement | null; | ||
| export declare const FormattedNumber: React.FC<Omit<NumberFormatOptions, "localeMatcher"> & CustomFormatConfig<"number"> & { | ||
| value: Parameters<IntlShape["formatNumber"]>[0]; | ||
| children?(formattedNumber: string): React.ReactElement | null; | ||
| }>; | ||
| export declare const FormattedList: React.FC<Intl.ListFormatOptions & { | ||
| value: readonly React.ReactNode[]; | ||
| value: readonly React.ReactNode[]; | ||
| }>; | ||
| export declare const FormattedDisplayName: React.FC<Intl.DisplayNamesOptions & { | ||
| value: string; | ||
| value: string; | ||
| }>; | ||
| export declare const FormattedDateParts: React.FC<FormatDateOptions & { | ||
| value: Parameters<Intl.DateTimeFormat['format']>[0] | string; | ||
| children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null; | ||
| value: Parameters<Intl.DateTimeFormat["format"]>[0] | string; | ||
| children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null; | ||
| }>; | ||
| export declare const FormattedTimeParts: React.FC<FormatTimeOptions & { | ||
| value: Parameters<Intl.DateTimeFormat['format']>[0] | string; | ||
| children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null; | ||
| value: Parameters<Intl.DateTimeFormat["format"]>[0] | string; | ||
| children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null; | ||
| }>; | ||
| export type { MessageFormatElement } from '@formatjs/icu-messageformat-parser'; | ||
| export type { PrimitiveType } from 'intl-messageformat'; | ||
| export { FormattedListParts, FormattedNumberParts, } from './src/components/createFormattedComponent.js'; | ||
| export type { MessageFormatElement } from "@formatjs/icu-messageformat-parser"; | ||
| export type { PrimitiveType } from "intl-messageformat"; | ||
| export { FormattedListParts, FormattedNumberParts } from "./src/components/createFormattedComponent.js"; |
+30
-21
@@ -1,26 +0,35 @@ | ||
| import { createFormattedComponent, createFormattedDateTimePartsComponent, } from './src/components/createFormattedComponent.js'; | ||
| import { createIntl } from './src/components/createIntl.js'; | ||
| import FormattedDateTimeRange from './src/components/dateTimeRange.js'; | ||
| import injectIntl, { Context as IntlContext, Provider as RawIntlProvider, } from './src/components/injectIntl.js'; | ||
| import FormattedMessage from './src/components/message.js'; | ||
| import FormattedPlural from './src/components/plural.js'; | ||
| import IntlProvider from './src/components/provider.js'; | ||
| import FormattedRelativeTime from './src/components/relative.js'; | ||
| import useIntl from './src/components/useIntl.js'; | ||
| export { createIntlCache, InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, IntlError as ReactIntlError, IntlErrorCode as ReactIntlErrorCode, UnsupportedFormatterError, } from '@formatjs/intl'; | ||
| export { createIntl, FormattedDateTimeRange, FormattedMessage, FormattedPlural, FormattedRelativeTime, injectIntl, IntlContext, IntlProvider, RawIntlProvider, useIntl, }; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import "@formatjs/ecma402-abstract"; | ||
| import "@formatjs/intl"; | ||
| import * as React from "react"; | ||
| import { createFormattedComponent, createFormattedDateTimePartsComponent } from "./src/components/createFormattedComponent.js"; | ||
| import { createIntl } from "./src/components/createIntl.js"; | ||
| import FormattedDateTimeRange from "./src/components/dateTimeRange.js"; | ||
| import injectIntl, { Context as IntlContext, Provider as RawIntlProvider } from "./src/components/injectIntl.js"; | ||
| import FormattedMessage from "./src/components/message.js"; | ||
| import FormattedPlural from "./src/components/plural.js"; | ||
| import IntlProvider from "./src/components/provider.js"; | ||
| import FormattedRelativeTime from "./src/components/relative.js"; | ||
| import useIntl from "./src/components/useIntl.js"; | ||
| import "./src/types.js"; | ||
| export { createIntlCache, InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, IntlError as ReactIntlError, IntlErrorCode as ReactIntlErrorCode, UnsupportedFormatterError } from "@formatjs/intl"; | ||
| export { createIntl, FormattedDateTimeRange, FormattedMessage, FormattedPlural, FormattedRelativeTime, injectIntl, IntlContext, IntlProvider, RawIntlProvider, useIntl }; | ||
| export function defineMessages(msgs) { | ||
| return msgs; | ||
| return msgs; | ||
| } | ||
| export function defineMessage(msg) { | ||
| return msg; | ||
| return msg; | ||
| } | ||
| // IMPORTANT: Explicit here to prevent api-extractor from outputing `import('./src/types').CustomFormatConfig` | ||
| export var FormattedDate = createFormattedComponent('formatDate'); | ||
| export var FormattedTime = createFormattedComponent('formatTime'); | ||
| export var FormattedNumber = createFormattedComponent('formatNumber'); | ||
| export var FormattedList = createFormattedComponent('formatList'); | ||
| export var FormattedDisplayName = createFormattedComponent('formatDisplayName'); | ||
| export var FormattedDateParts = createFormattedDateTimePartsComponent('formatDate'); | ||
| export var FormattedTimeParts = createFormattedDateTimePartsComponent('formatTime'); | ||
| export { FormattedListParts, FormattedNumberParts, } from './src/components/createFormattedComponent.js'; | ||
| export const FormattedDate = createFormattedComponent("formatDate"); | ||
| export const FormattedTime = createFormattedComponent("formatTime"); | ||
| export const FormattedNumber = createFormattedComponent("formatNumber"); | ||
| export const FormattedList = createFormattedComponent("formatList"); | ||
| export const FormattedDisplayName = createFormattedComponent("formatDisplayName"); | ||
| export const FormattedDateParts = createFormattedDateTimePartsComponent("formatDate"); | ||
| export const FormattedTimeParts = createFormattedDateTimePartsComponent("formatTime"); | ||
| export { FormattedListParts, FormattedNumberParts } from "./src/components/createFormattedComponent.js"; |
+5
-5
| { | ||
| "name": "react-intl", | ||
| "description": "Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.", | ||
| "version": "8.0.10", | ||
| "version": "8.0.11", | ||
| "license": "BSD-3-Clause", | ||
@@ -17,6 +17,6 @@ "author": "Eric Ferraiuolo <edf@ericf.me>", | ||
| "tslib": "^2.8.0", | ||
| "@formatjs/ecma402-abstract": "3.0.7", | ||
| "@formatjs/intl": "4.0.8", | ||
| "@formatjs/icu-messageformat-parser": "3.2.1", | ||
| "intl-messageformat": "11.0.8" | ||
| "@formatjs/ecma402-abstract": "3.0.8", | ||
| "@formatjs/icu-messageformat-parser": "3.3.0", | ||
| "intl-messageformat": "11.0.9", | ||
| "@formatjs/intl": "4.0.9" | ||
| }, | ||
@@ -23,0 +23,0 @@ "peerDependencies": { |
@@ -1,27 +0,27 @@ | ||
| import { FormatDateOptions, FormatDisplayNameOptions, FormatListOptions, FormatNumberOptions } from '@formatjs/intl'; | ||
| import * as React from 'react'; | ||
| import { IntlShape } from '../types.js'; | ||
| import { type FormatDateOptions, type FormatDisplayNameOptions, type FormatListOptions, type FormatNumberOptions } from "@formatjs/intl"; | ||
| import * as React from "react"; | ||
| import { type IntlShape } from "../types.js"; | ||
| type Formatter = { | ||
| formatDate: FormatDateOptions; | ||
| formatTime: FormatDateOptions; | ||
| formatNumber: FormatNumberOptions; | ||
| formatList: FormatListOptions; | ||
| formatDisplayName: FormatDisplayNameOptions; | ||
| formatDate: FormatDateOptions; | ||
| formatTime: FormatDateOptions; | ||
| formatNumber: FormatNumberOptions; | ||
| formatList: FormatListOptions; | ||
| formatDisplayName: FormatDisplayNameOptions; | ||
| }; | ||
| export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] & { | ||
| value: Parameters<IntlShape['formatNumber']>[0]; | ||
| children(val: Intl.NumberFormatPart[]): React.ReactElement | null; | ||
| export declare const FormattedNumberParts: React.FC<Formatter["formatNumber"] & { | ||
| value: Parameters<IntlShape["formatNumber"]>[0]; | ||
| children(val: Intl.NumberFormatPart[]): React.ReactElement | null; | ||
| }>; | ||
| export declare const FormattedListParts: React.FC<Formatter['formatList'] & { | ||
| value: Parameters<IntlShape['formatList']>[0]; | ||
| children(val: ReturnType<Intl.ListFormat['formatToParts']>): React.ReactElement | null; | ||
| export declare const FormattedListParts: React.FC<Formatter["formatList"] & { | ||
| value: Parameters<IntlShape["formatList"]>[0]; | ||
| children(val: ReturnType<Intl.ListFormat["formatToParts"]>): React.ReactElement | null; | ||
| }>; | ||
| export declare function createFormattedDateTimePartsComponent<Name extends 'formatDate' | 'formatTime'>(name: Name): React.FC<Formatter[Name] & { | ||
| value: Parameters<IntlShape[Name]>[0]; | ||
| children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null; | ||
| export declare function createFormattedDateTimePartsComponent<Name extends "formatDate" | "formatTime">(name: Name): React.FC<Formatter[Name] & { | ||
| value: Parameters<IntlShape[Name]>[0]; | ||
| children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null; | ||
| }>; | ||
| export declare function createFormattedComponent<Name extends keyof Formatter>(name: Name): React.FC<Formatter[Name] & { | ||
| value: Parameters<IntlShape[Name]>[0]; | ||
| children?(val: string): React.ReactElement | null; | ||
| value: Parameters<IntlShape[Name]>[0]; | ||
| children?(val: string): React.ReactElement | null; | ||
| }>; | ||
| export {}; |
@@ -1,63 +0,60 @@ | ||
| import { __rest } from "tslib"; | ||
| import "@formatjs/intl"; | ||
| import * as React from "react"; | ||
| import "../types.js"; | ||
| import useIntl from "./useIntl.js"; | ||
| import { jsx as _jsx } from "react/jsx-runtime"; | ||
| import * as React from 'react'; | ||
| import useIntl from './useIntl.js'; | ||
| var DisplayName; | ||
| (function (DisplayName) { | ||
| DisplayName["formatDate"] = "FormattedDate"; | ||
| DisplayName["formatTime"] = "FormattedTime"; | ||
| DisplayName["formatNumber"] = "FormattedNumber"; | ||
| DisplayName["formatList"] = "FormattedList"; | ||
| // Note that this DisplayName is the locale display name, not to be confused with | ||
| // the name of the enum, which is for React component display name in dev tools. | ||
| DisplayName["formatDisplayName"] = "FormattedDisplayName"; | ||
| })(DisplayName || (DisplayName = {})); | ||
| var DisplayNameParts; | ||
| (function (DisplayNameParts) { | ||
| DisplayNameParts["formatDate"] = "FormattedDateParts"; | ||
| DisplayNameParts["formatTime"] = "FormattedTimeParts"; | ||
| DisplayNameParts["formatNumber"] = "FormattedNumberParts"; | ||
| DisplayNameParts["formatList"] = "FormattedListParts"; | ||
| })(DisplayNameParts || (DisplayNameParts = {})); | ||
| export var FormattedNumberParts = function (props) { | ||
| var intl = useIntl(); | ||
| var value = props.value, children = props.children, formatProps = __rest(props, ["value", "children"]); | ||
| return children(intl.formatNumberToParts(value, formatProps)); | ||
| var DisplayName = /* @__PURE__ */ function(DisplayName) { | ||
| DisplayName["formatDate"] = "FormattedDate"; | ||
| DisplayName["formatTime"] = "FormattedTime"; | ||
| DisplayName["formatNumber"] = "FormattedNumber"; | ||
| DisplayName["formatList"] = "FormattedList"; | ||
| // Note that this DisplayName is the locale display name, not to be confused with | ||
| // the name of the enum, which is for React component display name in dev tools. | ||
| DisplayName["formatDisplayName"] = "FormattedDisplayName"; | ||
| return DisplayName; | ||
| }(DisplayName || {}); | ||
| var DisplayNameParts = /* @__PURE__ */ function(DisplayNameParts) { | ||
| DisplayNameParts["formatDate"] = "FormattedDateParts"; | ||
| DisplayNameParts["formatTime"] = "FormattedTimeParts"; | ||
| DisplayNameParts["formatNumber"] = "FormattedNumberParts"; | ||
| DisplayNameParts["formatList"] = "FormattedListParts"; | ||
| return DisplayNameParts; | ||
| }(DisplayNameParts || {}); | ||
| export const FormattedNumberParts = (props) => { | ||
| const intl = useIntl(); | ||
| const { value, children, ...formatProps } = props; | ||
| return children(intl.formatNumberToParts(value, formatProps)); | ||
| }; | ||
| FormattedNumberParts.displayName = 'FormattedNumberParts'; | ||
| export var FormattedListParts = function (props) { | ||
| var intl = useIntl(); | ||
| var value = props.value, children = props.children, formatProps = __rest(props, ["value", "children"]); | ||
| return children(intl.formatListToParts(value, formatProps)); | ||
| FormattedNumberParts.displayName = "FormattedNumberParts"; | ||
| export const FormattedListParts = (props) => { | ||
| const intl = useIntl(); | ||
| const { value, children, ...formatProps } = props; | ||
| return children(intl.formatListToParts(value, formatProps)); | ||
| }; | ||
| FormattedNumberParts.displayName = 'FormattedNumberParts'; | ||
| FormattedNumberParts.displayName = "FormattedNumberParts"; | ||
| export function createFormattedDateTimePartsComponent(name) { | ||
| var ComponentParts = function (props) { | ||
| var intl = useIntl(); | ||
| var value = props.value, children = props.children, formatProps = __rest(props, ["value", "children"]); | ||
| var date = typeof value === 'string' ? new Date(value || 0) : value; | ||
| var formattedParts = name === 'formatDate' | ||
| ? intl.formatDateToParts(date, formatProps) | ||
| : intl.formatTimeToParts(date, formatProps); | ||
| return children(formattedParts); | ||
| }; | ||
| ComponentParts.displayName = DisplayNameParts[name]; | ||
| return ComponentParts; | ||
| const ComponentParts = (props) => { | ||
| const intl = useIntl(); | ||
| const { value, children, ...formatProps } = props; | ||
| const date = typeof value === "string" ? new Date(value || 0) : value; | ||
| const formattedParts = name === "formatDate" ? intl.formatDateToParts(date, formatProps) : intl.formatTimeToParts(date, formatProps); | ||
| return children(formattedParts); | ||
| }; | ||
| ComponentParts.displayName = DisplayNameParts[name]; | ||
| return ComponentParts; | ||
| } | ||
| export function createFormattedComponent(name) { | ||
| var Component = function (props) { | ||
| var intl = useIntl(); | ||
| var value = props.value, children = props.children, formatProps = __rest(props | ||
| // TODO: fix TS type definition for localeMatcher upstream | ||
| , ["value", "children"]); | ||
| // TODO: fix TS type definition for localeMatcher upstream | ||
| var formattedValue = intl[name](value, formatProps); | ||
| if (typeof children === 'function') { | ||
| return children(formattedValue); | ||
| } | ||
| var Text = intl.textComponent || React.Fragment; | ||
| return _jsx(Text, { children: formattedValue }); | ||
| }; | ||
| Component.displayName = DisplayName[name]; | ||
| return Component; | ||
| const Component = (props) => { | ||
| const intl = useIntl(); | ||
| const { value, children, ...formatProps } = props; | ||
| // TODO: fix TS type definition for localeMatcher upstream | ||
| const formattedValue = intl[name](value, formatProps); | ||
| if (typeof children === "function") { | ||
| return children(formattedValue); | ||
| } | ||
| const Text = intl.textComponent || React.Fragment; | ||
| return /* @__PURE__ */ _jsx(Text, { children: formattedValue }); | ||
| }; | ||
| Component.displayName = DisplayName[name]; | ||
| return Component; | ||
| } |
@@ -1,9 +0,14 @@ | ||
| import { CreateIntlFn } from '@formatjs/intl'; | ||
| import * as React from 'react'; | ||
| import type { IntlConfig, IntlShape } from '../types.js'; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import { type CreateIntlFn } from "@formatjs/intl"; | ||
| import * as React from "react"; | ||
| import type { IntlConfig, IntlShape } from "../types.js"; | ||
| /** | ||
| * Create intl object | ||
| * @param config intl config | ||
| * @param cache cache for formatter instances to prevent memory leak | ||
| */ | ||
| * Create intl object | ||
| * @param config intl config | ||
| * @param cache cache for formatter instances to prevent memory leak | ||
| */ | ||
| export declare const createIntl: CreateIntlFn<React.ReactNode, IntlConfig, IntlShape>; |
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import { __assign, __rest, __spreadArray } from "tslib"; | ||
| import { createIntl as coreCreateIntl, formatMessage as coreFormatMessage, } from '@formatjs/intl'; | ||
| import { isFormatXMLElementFn, } from 'intl-messageformat'; | ||
| import { DEFAULT_INTL_CONFIG, assignUniqueKeysToParts, toKeyedReactNodeArray, } from '../utils.js'; | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import { createIntl as coreCreateIntl, formatMessage as coreFormatMessage } from "@formatjs/intl"; | ||
| import { isFormatXMLElementFn } from "intl-messageformat"; | ||
| import * as React from "react"; | ||
| import { DEFAULT_INTL_CONFIG, assignUniqueKeysToParts, toKeyedReactNodeArray } from "../utils.js"; | ||
| function assignUniqueKeysToFormatXMLElementFnArgument(values) { | ||
| if (!values) { | ||
| return values; | ||
| } | ||
| return Object.keys(values).reduce(function (acc, k) { | ||
| var v = values[k]; | ||
| acc[k] = isFormatXMLElementFn(v) | ||
| ? assignUniqueKeysToParts(v) | ||
| : v; | ||
| return acc; | ||
| }, {}); | ||
| if (!values) { | ||
| return values; | ||
| } | ||
| return Object.keys(values).reduce((acc, k) => { | ||
| const v = values[k]; | ||
| acc[k] = isFormatXMLElementFn(v) ? assignUniqueKeysToParts(v) : v; | ||
| return acc; | ||
| }, {}); | ||
| } | ||
| var formatMessage = function (config, formatters, descriptor, rawValues) { | ||
| var rest = []; | ||
| for (var _i = 4; _i < arguments.length; _i++) { | ||
| rest[_i - 4] = arguments[_i]; | ||
| } | ||
| var values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues); | ||
| var chunks = coreFormatMessage.apply(void 0, __spreadArray([config, | ||
| formatters, | ||
| descriptor, | ||
| values], rest, false)); | ||
| if (Array.isArray(chunks)) { | ||
| return toKeyedReactNodeArray(chunks); | ||
| } | ||
| return chunks; | ||
| const formatMessage = (config, formatters, descriptor, rawValues, ...rest) => { | ||
| const values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues); | ||
| const chunks = coreFormatMessage(config, formatters, descriptor, values, ...rest); | ||
| if (Array.isArray(chunks)) { | ||
| return toKeyedReactNodeArray(chunks); | ||
| } | ||
| return chunks; | ||
| }; | ||
| /** | ||
| * Create intl object | ||
| * @param config intl config | ||
| * @param cache cache for formatter instances to prevent memory leak | ||
| */ | ||
| export var createIntl = function (_a, cache) { | ||
| var rawDefaultRichTextElements = _a.defaultRichTextElements, config = __rest(_a, ["defaultRichTextElements"]); | ||
| var defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(rawDefaultRichTextElements); | ||
| var coreIntl = coreCreateIntl(__assign(__assign(__assign({}, DEFAULT_INTL_CONFIG), config), { defaultRichTextElements: defaultRichTextElements }), cache); | ||
| var resolvedConfig = { | ||
| locale: coreIntl.locale, | ||
| timeZone: coreIntl.timeZone, | ||
| fallbackOnEmptyString: coreIntl.fallbackOnEmptyString, | ||
| formats: coreIntl.formats, | ||
| defaultLocale: coreIntl.defaultLocale, | ||
| defaultFormats: coreIntl.defaultFormats, | ||
| messages: coreIntl.messages, | ||
| onError: coreIntl.onError, | ||
| defaultRichTextElements: defaultRichTextElements, | ||
| }; | ||
| return __assign(__assign({}, coreIntl), { formatMessage: formatMessage.bind(null, resolvedConfig, coreIntl.formatters), $t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters) }); | ||
| * Create intl object | ||
| * @param config intl config | ||
| * @param cache cache for formatter instances to prevent memory leak | ||
| */ | ||
| export const createIntl = ({ defaultRichTextElements: rawDefaultRichTextElements, ...config }, cache) => { | ||
| const defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(rawDefaultRichTextElements); | ||
| const coreIntl = coreCreateIntl({ | ||
| ...DEFAULT_INTL_CONFIG, | ||
| ...config, | ||
| defaultRichTextElements | ||
| }, cache); | ||
| const resolvedConfig = { | ||
| locale: coreIntl.locale, | ||
| timeZone: coreIntl.timeZone, | ||
| fallbackOnEmptyString: coreIntl.fallbackOnEmptyString, | ||
| formats: coreIntl.formats, | ||
| defaultLocale: coreIntl.defaultLocale, | ||
| defaultFormats: coreIntl.defaultFormats, | ||
| messages: coreIntl.messages, | ||
| onError: coreIntl.onError, | ||
| defaultRichTextElements | ||
| }; | ||
| return { | ||
| ...coreIntl, | ||
| formatMessage: formatMessage.bind(null, resolvedConfig, coreIntl.formatters), | ||
| $t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters) | ||
| }; | ||
| }; |
@@ -1,9 +0,9 @@ | ||
| import { FormatDateTimeRangeOptions } from '@formatjs/intl'; | ||
| import * as React from 'react'; | ||
| import { type FormatDateTimeRangeOptions } from "@formatjs/intl"; | ||
| import * as React from "react"; | ||
| interface Props extends FormatDateTimeRangeOptions { | ||
| from: Parameters<Intl.DateTimeFormat['formatRange']>[0]; | ||
| to: Parameters<Intl.DateTimeFormat['formatRange']>[1]; | ||
| children?(value: React.ReactNode): React.ReactElement | null; | ||
| from: Parameters<Intl.DateTimeFormat["formatRange"]>[0]; | ||
| to: Parameters<Intl.DateTimeFormat["formatRange"]>[1]; | ||
| children?(value: React.ReactNode): React.ReactElement | null; | ||
| } | ||
| declare const FormattedDateTimeRange: React.FC<Props>; | ||
| export default FormattedDateTimeRange; |
@@ -1,16 +0,16 @@ | ||
| import { __rest } from "tslib"; | ||
| import "@formatjs/intl"; | ||
| import * as React from "react"; | ||
| import useIntl from "./useIntl.js"; | ||
| import { jsx as _jsx } from "react/jsx-runtime"; | ||
| import * as React from 'react'; | ||
| import useIntl from './useIntl.js'; | ||
| var FormattedDateTimeRange = function (props) { | ||
| var intl = useIntl(); | ||
| var from = props.from, to = props.to, children = props.children, formatProps = __rest(props, ["from", "to", "children"]); | ||
| var formattedValue = intl.formatDateTimeRange(from, to, formatProps); | ||
| if (typeof children === 'function') { | ||
| return children(formattedValue); | ||
| } | ||
| var Text = intl.textComponent || React.Fragment; | ||
| return _jsx(Text, { children: formattedValue }); | ||
| const FormattedDateTimeRange = (props) => { | ||
| const intl = useIntl(); | ||
| const { from, to, children, ...formatProps } = props; | ||
| const formattedValue = intl.formatDateTimeRange(from, to, formatProps); | ||
| if (typeof children === "function") { | ||
| return children(formattedValue); | ||
| } | ||
| const Text = intl.textComponent || React.Fragment; | ||
| return /* @__PURE__ */ _jsx(Text, { children: formattedValue }); | ||
| }; | ||
| FormattedDateTimeRange.displayName = 'FormattedDateTimeRange'; | ||
| FormattedDateTimeRange.displayName = "FormattedDateTimeRange"; | ||
| export default FormattedDateTimeRange; |
@@ -1,39 +0,53 @@ | ||
| import * as React from 'react'; | ||
| import { IntlShape } from '../types.js'; | ||
| import * as React from "react"; | ||
| import { type IntlShape } from "../types.js"; | ||
| declare global { | ||
| interface Window { | ||
| /** | ||
| * Set this to `true` prior to mounting to bypass using a globally-exposed context. | ||
| */ | ||
| __REACT_INTL_BYPASS_GLOBAL_CONTEXT__: boolean | undefined; | ||
| __REACT_INTL_CONTEXT__: React.Context<IntlShape> | undefined; | ||
| } | ||
| interface Window { | ||
| /** | ||
| * Set this to `true` prior to mounting to bypass using a globally-exposed context. | ||
| */ | ||
| __REACT_INTL_BYPASS_GLOBAL_CONTEXT__: boolean | undefined; | ||
| __REACT_INTL_CONTEXT__: React.Context<IntlShape> | undefined; | ||
| } | ||
| } | ||
| export declare const Provider: React.Provider<IntlShape>; | ||
| export declare const Context: React.Context<IntlShape>; | ||
| export interface Opts<IntlPropName extends string = 'intl', ForwardRef extends boolean = false> { | ||
| intlPropName?: IntlPropName; | ||
| forwardRef?: ForwardRef; | ||
| enforceContext?: boolean; | ||
| export interface Opts< | ||
| IntlPropName extends string = "intl", | ||
| ForwardRef extends boolean = false | ||
| > { | ||
| intlPropName?: IntlPropName; | ||
| forwardRef?: ForwardRef; | ||
| enforceContext?: boolean; | ||
| } | ||
| export type WrappedComponentProps<IntlPropName extends string = 'intl'> = { | ||
| [k in IntlPropName]: IntlShape; | ||
| }; | ||
| export type WrappedComponentProps<IntlPropName extends string = "intl"> = { [k in IntlPropName] : IntlShape }; | ||
| /** | ||
| * Utility type to help deal with the fact that `Omit` doesn't play well with unions: | ||
| * - https://github.com/microsoft/TypeScript/issues/31501 | ||
| * - https://github.com/microsoft/TypeScript/issues/28339 | ||
| * | ||
| * @example | ||
| * DistributedOmit<X | Y, K> --> Omit<X, K> | Omit<Y, K> | ||
| */ | ||
| export type DistributedOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never; | ||
| * Utility type to help deal with the fact that `Omit` doesn't play well with unions: | ||
| * - https://github.com/microsoft/TypeScript/issues/31501 | ||
| * - https://github.com/microsoft/TypeScript/issues/28339 | ||
| * | ||
| * @example | ||
| * DistributedOmit<X | Y, K> --> Omit<X, K> | Omit<Y, K> | ||
| */ | ||
| export type DistributedOmit< | ||
| T, | ||
| K extends PropertyKey | ||
| > = T extends unknown ? Omit<T, K> : never; | ||
| export type WithIntlProps<P> = DistributedOmit<P, keyof WrappedComponentProps> & { | ||
| forwardedRef?: React.Ref<any>; | ||
| forwardedRef?: React.Ref<any>; | ||
| }; | ||
| export default function injectIntl<IntlPropName extends string = 'intl', P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, false>): React.FC<WithIntlProps<P>> & { | ||
| WrappedComponent: React.ComponentType<P>; | ||
| // TODO: type hoisted static methods. | ||
| // Non ref forwarding overload | ||
| export default function injectIntl< | ||
| IntlPropName extends string = "intl", | ||
| P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any> | ||
| >(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, false>): React.FC<WithIntlProps<P>> & { | ||
| WrappedComponent: React.ComponentType<P>; | ||
| }; | ||
| export default function injectIntl<IntlPropName extends string = 'intl', P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>, T extends React.ComponentType<P> = any>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, true>): React.ForwardRefExoticComponent<React.PropsWithoutRef<WithIntlProps<React.PropsWithChildren<P>>> & React.RefAttributes<T>> & { | ||
| WrappedComponent: React.ComponentType<P>; | ||
| // Ref forwarding overload. | ||
| export default function injectIntl< | ||
| IntlPropName extends string = "intl", | ||
| P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>, | ||
| T extends React.ComponentType<P> = any | ||
| >(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, true>): React.ForwardRefExoticComponent<React.PropsWithoutRef<WithIntlProps<React.PropsWithChildren<P>>> & React.RefAttributes<T>> & { | ||
| WrappedComponent: React.ComponentType<P>; | ||
| }; |
@@ -1,38 +0,42 @@ | ||
| var _a; | ||
| import { __assign } from "tslib"; | ||
| import * as hoistNonReactStaticsNs from "hoist-non-react-statics"; | ||
| import * as React from "react"; | ||
| import "../types.js"; | ||
| import { invariantIntlContext } from "../utils.js"; | ||
| import { jsx as _jsx } from "react/jsx-runtime"; | ||
| import * as hoistNonReactStaticsNs from 'hoist-non-react-statics'; | ||
| import * as React from 'react'; | ||
| import { invariantIntlContext } from '../utils.js'; | ||
| var hoistNonReactStatics = (_a = hoistNonReactStaticsNs.default) !== null && _a !== void 0 ? _a : hoistNonReactStaticsNs; | ||
| const hoistNonReactStatics = hoistNonReactStaticsNs.default ?? hoistNonReactStaticsNs; | ||
| function getDisplayName(Component) { | ||
| return Component.displayName || Component.name || 'Component'; | ||
| return Component.displayName || Component.name || "Component"; | ||
| } | ||
| // This is primarily dealing with packaging systems where multiple copies of react-intl | ||
| // might exist | ||
| var IntlContext = typeof window !== 'undefined' && !window.__REACT_INTL_BYPASS_GLOBAL_CONTEXT__ | ||
| ? window.__REACT_INTL_CONTEXT__ || | ||
| (window.__REACT_INTL_CONTEXT__ = React.createContext(null)) | ||
| : React.createContext(null); | ||
| var IntlConsumer = IntlContext.Consumer, IntlProvider = IntlContext.Provider; | ||
| export var Provider = IntlProvider; | ||
| export var Context = IntlContext; | ||
| const IntlContext = typeof window !== "undefined" && !window.__REACT_INTL_BYPASS_GLOBAL_CONTEXT__ ? window.__REACT_INTL_CONTEXT__ || (window.__REACT_INTL_CONTEXT__ = React.createContext(null)) : React.createContext(null); | ||
| const { Consumer: IntlConsumer, Provider: IntlProvider } = IntlContext; | ||
| export const Provider = IntlProvider; | ||
| export const Context = IntlContext; | ||
| export default function injectIntl(WrappedComponent, options) { | ||
| var _a = options || {}, _b = _a.intlPropName, intlPropName = _b === void 0 ? 'intl' : _b, _c = _a.forwardRef, forwardRef = _c === void 0 ? false : _c, _d = _a.enforceContext, enforceContext = _d === void 0 ? true : _d; | ||
| var WithIntl = function (props) { return (_jsx(IntlConsumer, { children: function (intl) { | ||
| var _a; | ||
| if (enforceContext) { | ||
| invariantIntlContext(intl); | ||
| } | ||
| var intlProp = (_a = {}, _a[intlPropName] = intl, _a); | ||
| return (_jsx(WrappedComponent, __assign({}, props, intlProp, { ref: forwardRef ? props.forwardedRef : null }))); | ||
| } })); }; | ||
| WithIntl.displayName = "injectIntl(".concat(getDisplayName(WrappedComponent), ")"); | ||
| WithIntl.WrappedComponent = WrappedComponent; | ||
| if (forwardRef) { | ||
| return hoistNonReactStatics( | ||
| // @ts-expect-error | ||
| React.forwardRef(function (props, ref) { return (_jsx(WithIntl, __assign({}, props, { forwardedRef: ref }))); }), WrappedComponent); | ||
| } | ||
| return hoistNonReactStatics(WithIntl, WrappedComponent); | ||
| const { intlPropName = "intl", forwardRef = false, enforceContext = true } = options || {}; | ||
| const WithIntl = (props) => /* @__PURE__ */ _jsx(IntlConsumer, { children: (intl) => { | ||
| if (enforceContext) { | ||
| invariantIntlContext(intl); | ||
| } | ||
| const intlProp = { [intlPropName]: intl }; | ||
| return /* @__PURE__ */ _jsx(WrappedComponent, { | ||
| ...props, | ||
| ...intlProp, | ||
| ref: forwardRef ? props.forwardedRef : null | ||
| }); | ||
| } }); | ||
| WithIntl.displayName = `injectIntl(${getDisplayName(WrappedComponent)})`; | ||
| WithIntl.WrappedComponent = WrappedComponent; | ||
| if (forwardRef) { | ||
| return hoistNonReactStatics( | ||
| // @ts-expect-error | ||
| React.forwardRef((props, ref) => /* @__PURE__ */ _jsx(WithIntl, { | ||
| ...props, | ||
| forwardedRef: ref | ||
| })), | ||
| WrappedComponent | ||
| ); | ||
| } | ||
| return hoistNonReactStatics(WithIntl, WrappedComponent); | ||
| } |
@@ -1,11 +0,16 @@ | ||
| import type { FormatXMLElementFn, Options as IntlMessageFormatOptions, PrimitiveType } from 'intl-messageformat'; | ||
| import * as React from 'react'; | ||
| import { MessageDescriptor } from '@formatjs/intl'; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import type { FormatXMLElementFn, Options as IntlMessageFormatOptions, PrimitiveType } from "intl-messageformat"; | ||
| import * as React from "react"; | ||
| import { type MessageDescriptor } from "@formatjs/intl"; | ||
| export interface Props<V extends Record<string, any> = Record<string, React.ReactNode | PrimitiveType | FormatXMLElementFn<React.ReactNode>>> extends MessageDescriptor { | ||
| values?: V; | ||
| tagName?: React.ElementType<any>; | ||
| children?(nodes: React.ReactNode[]): React.ReactNode | null; | ||
| ignoreTag?: IntlMessageFormatOptions['ignoreTag']; | ||
| values?: V; | ||
| tagName?: React.ElementType<any>; | ||
| children?(nodes: React.ReactNode[]): React.ReactNode | null; | ||
| ignoreTag?: IntlMessageFormatOptions["ignoreTag"]; | ||
| } | ||
| declare const MemoizedFormattedMessage: React.ComponentType<Props>; | ||
| export default MemoizedFormattedMessage; |
@@ -1,31 +0,32 @@ | ||
| import { __rest } from "tslib"; | ||
| import * as React from "react"; | ||
| import "@formatjs/intl"; | ||
| import { shallowEqual } from "../utils.js"; | ||
| import useIntl from "./useIntl.js"; | ||
| import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; | ||
| import * as React from 'react'; | ||
| import { shallowEqual } from '../utils.js'; | ||
| import useIntl from './useIntl.js'; | ||
| function areEqual(prevProps, nextProps) { | ||
| var values = prevProps.values, otherProps = __rest(prevProps, ["values"]); | ||
| var nextValues = nextProps.values, nextOtherProps = __rest(nextProps, ["values"]); | ||
| return (shallowEqual(nextValues, values) && | ||
| shallowEqual(otherProps, nextOtherProps)); | ||
| const { values, ...otherProps } = prevProps; | ||
| const { values: nextValues, ...nextOtherProps } = nextProps; | ||
| return shallowEqual(nextValues, values) && shallowEqual(otherProps, nextOtherProps); | ||
| } | ||
| function FormattedMessage(props) { | ||
| var intl = useIntl(); | ||
| var formatMessage = intl.formatMessage, _a = intl.textComponent, Text = _a === void 0 ? React.Fragment : _a; | ||
| var id = props.id, description = props.description, defaultMessage = props.defaultMessage, values = props.values, children = props.children, _b = props.tagName, Component = _b === void 0 ? Text : _b, ignoreTag = props.ignoreTag; | ||
| var descriptor = { id: id, description: description, defaultMessage: defaultMessage }; | ||
| var nodes = formatMessage(descriptor, values, { | ||
| ignoreTag: ignoreTag, | ||
| }); | ||
| if (typeof children === 'function') { | ||
| return children(Array.isArray(nodes) ? nodes : [nodes]); | ||
| } | ||
| if (Component) { | ||
| return _jsx(Component, { children: nodes }); | ||
| } | ||
| return _jsx(_Fragment, { children: nodes }); | ||
| const intl = useIntl(); | ||
| const { formatMessage, textComponent: Text = React.Fragment } = intl; | ||
| const { id, description, defaultMessage, values, children, tagName: Component = Text, ignoreTag } = props; | ||
| const descriptor = { | ||
| id, | ||
| description, | ||
| defaultMessage | ||
| }; | ||
| const nodes = formatMessage(descriptor, values, { ignoreTag }); | ||
| if (typeof children === "function") { | ||
| return children(Array.isArray(nodes) ? nodes : [nodes]); | ||
| } | ||
| if (Component) { | ||
| return /* @__PURE__ */ _jsx(Component, { children: nodes }); | ||
| } | ||
| return /* @__PURE__ */ _jsx(_Fragment, { children: nodes }); | ||
| } | ||
| FormattedMessage.displayName = 'FormattedMessage'; | ||
| var MemoizedFormattedMessage = React.memo(FormattedMessage, areEqual); | ||
| MemoizedFormattedMessage.displayName = 'MemoizedFormattedMessage'; | ||
| FormattedMessage.displayName = "FormattedMessage"; | ||
| const MemoizedFormattedMessage = React.memo(FormattedMessage, areEqual); | ||
| MemoizedFormattedMessage.displayName = "MemoizedFormattedMessage"; | ||
| export default MemoizedFormattedMessage; |
@@ -1,14 +0,19 @@ | ||
| import * as React from 'react'; | ||
| import { FormatPluralOptions } from '@formatjs/intl'; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import * as React from "react"; | ||
| import { type FormatPluralOptions } from "@formatjs/intl"; | ||
| interface Props extends FormatPluralOptions { | ||
| value: number; | ||
| other: React.ReactNode; | ||
| zero?: React.ReactNode; | ||
| one?: React.ReactNode; | ||
| two?: React.ReactNode; | ||
| few?: React.ReactNode; | ||
| many?: React.ReactNode; | ||
| children?(value: React.ReactNode): React.ReactElement | null; | ||
| value: number; | ||
| other: React.ReactNode; | ||
| zero?: React.ReactNode; | ||
| one?: React.ReactNode; | ||
| two?: React.ReactNode; | ||
| few?: React.ReactNode; | ||
| many?: React.ReactNode; | ||
| children?(value: React.ReactNode): React.ReactElement | null; | ||
| } | ||
| declare const FormattedPlural: React.FC<Props>; | ||
| export default FormattedPlural; |
+22
-15
@@ -0,18 +1,25 @@ | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import * as React from "react"; | ||
| import "@formatjs/intl"; | ||
| import useIntl from "./useIntl.js"; | ||
| import { jsx as _jsx } from "react/jsx-runtime"; | ||
| import useIntl from './useIntl.js'; | ||
| var FormattedPlural = function (props) { | ||
| var _a = useIntl(), formatPlural = _a.formatPlural, Text = _a.textComponent; | ||
| var value = props.value, other = props.other, children = props.children; | ||
| var pluralCategory = formatPlural(value, props); | ||
| var formattedPlural = props[pluralCategory] || other; | ||
| if (typeof children === 'function') { | ||
| return children(formattedPlural); | ||
| } | ||
| if (Text) { | ||
| return _jsx(Text, { children: formattedPlural }); | ||
| } | ||
| // Work around @types/react where React.FC cannot return string | ||
| return formattedPlural; | ||
| const FormattedPlural = (props) => { | ||
| const { formatPlural, textComponent: Text } = useIntl(); | ||
| const { value, other, children } = props; | ||
| const pluralCategory = formatPlural(value, props); | ||
| const formattedPlural = props[pluralCategory] || other; | ||
| if (typeof children === "function") { | ||
| return children(formattedPlural); | ||
| } | ||
| if (Text) { | ||
| return /* @__PURE__ */ _jsx(Text, { children: formattedPlural }); | ||
| } | ||
| // Work around @types/react where React.FC cannot return string | ||
| return formattedPlural; | ||
| }; | ||
| FormattedPlural.displayName = 'FormattedPlural'; | ||
| FormattedPlural.displayName = "FormattedPlural"; | ||
| export default FormattedPlural; |
@@ -1,29 +0,33 @@ | ||
| import { IntlCache } from '@formatjs/intl'; | ||
| import * as React from 'react'; | ||
| import type { IntlConfig, IntlShape } from '../types.js'; | ||
| import { DefaultIntlConfig } from '../utils.js'; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import { type IntlCache } from "@formatjs/intl"; | ||
| import * as React from "react"; | ||
| import type { IntlConfig, IntlShape } from "../types.js"; | ||
| import { type DefaultIntlConfig } from "../utils.js"; | ||
| interface State { | ||
| /** | ||
| * Explicit intl cache to prevent memory leaks | ||
| */ | ||
| cache: IntlCache; | ||
| /** | ||
| * Intl object we created | ||
| */ | ||
| intl?: IntlShape; | ||
| /** | ||
| * list of memoized config we care about. | ||
| * This is important since creating intl is | ||
| * very expensive | ||
| */ | ||
| prevConfig: IntlConfig; | ||
| /** | ||
| * Explicit intl cache to prevent memory leaks | ||
| */ | ||
| cache: IntlCache; | ||
| /** | ||
| * Intl object we created | ||
| */ | ||
| intl?: IntlShape; | ||
| /** | ||
| * list of memoized config we care about. | ||
| * This is important since creating intl is | ||
| * very expensive | ||
| */ | ||
| prevConfig: IntlConfig; | ||
| } | ||
| export default class IntlProvider extends React.PureComponent<React.PropsWithChildren<IntlConfig>, State> { | ||
| static displayName: string; | ||
| static defaultProps: DefaultIntlConfig; | ||
| private cache; | ||
| state: State; | ||
| static getDerivedStateFromProps(props: Readonly<IntlConfig>, { prevConfig, cache }: State): Partial<State> | null; | ||
| render(): React.JSX.Element; | ||
| static displayName: string; | ||
| static defaultProps: DefaultIntlConfig; | ||
| private cache; | ||
| state: State; | ||
| static getDerivedStateFromProps(props: Readonly<IntlConfig>, { prevConfig, cache }: State): Partial<State> | null; | ||
| render(): React.JSX.Element; | ||
| } | ||
| export {}; |
@@ -1,60 +0,54 @@ | ||
| import { __extends } from "tslib"; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import { createIntlCache } from "@formatjs/intl"; | ||
| import * as React from "react"; | ||
| import { DEFAULT_INTL_CONFIG, invariantIntlContext, shallowEqual } from "../utils.js"; | ||
| import { createIntl } from "./createIntl.js"; | ||
| import { Provider } from "./injectIntl.js"; | ||
| import { jsx as _jsx } from "react/jsx-runtime"; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import { createIntlCache } from '@formatjs/intl'; | ||
| import * as React from 'react'; | ||
| import { DEFAULT_INTL_CONFIG, invariantIntlContext, shallowEqual, } from '../utils.js'; | ||
| import { createIntl } from './createIntl.js'; | ||
| import { Provider } from './injectIntl.js'; | ||
| function processIntlConfig(config) { | ||
| return { | ||
| locale: config.locale, | ||
| timeZone: config.timeZone, | ||
| fallbackOnEmptyString: config.fallbackOnEmptyString, | ||
| formats: config.formats, | ||
| textComponent: config.textComponent, | ||
| messages: config.messages, | ||
| defaultLocale: config.defaultLocale, | ||
| defaultFormats: config.defaultFormats, | ||
| onError: config.onError, | ||
| onWarn: config.onWarn, | ||
| wrapRichTextChunksInFragment: config.wrapRichTextChunksInFragment, | ||
| defaultRichTextElements: config.defaultRichTextElements, | ||
| }; | ||
| return { | ||
| locale: config.locale, | ||
| timeZone: config.timeZone, | ||
| fallbackOnEmptyString: config.fallbackOnEmptyString, | ||
| formats: config.formats, | ||
| textComponent: config.textComponent, | ||
| messages: config.messages, | ||
| defaultLocale: config.defaultLocale, | ||
| defaultFormats: config.defaultFormats, | ||
| onError: config.onError, | ||
| onWarn: config.onWarn, | ||
| wrapRichTextChunksInFragment: config.wrapRichTextChunksInFragment, | ||
| defaultRichTextElements: config.defaultRichTextElements | ||
| }; | ||
| } | ||
| var IntlProvider = /** @class */ (function (_super) { | ||
| __extends(IntlProvider, _super); | ||
| function IntlProvider() { | ||
| var _this = _super !== null && _super.apply(this, arguments) || this; | ||
| _this.cache = createIntlCache(); | ||
| _this.state = { | ||
| cache: _this.cache, | ||
| intl: createIntl(processIntlConfig(_this.props), _this.cache), | ||
| prevConfig: processIntlConfig(_this.props), | ||
| }; | ||
| return _this; | ||
| } | ||
| IntlProvider.getDerivedStateFromProps = function (props, _a) { | ||
| var prevConfig = _a.prevConfig, cache = _a.cache; | ||
| var config = processIntlConfig(props); | ||
| if (!shallowEqual(prevConfig, config)) { | ||
| return { | ||
| intl: createIntl(config, cache), | ||
| prevConfig: config, | ||
| }; | ||
| } | ||
| return null; | ||
| }; | ||
| IntlProvider.prototype.render = function () { | ||
| invariantIntlContext(this.state.intl); | ||
| return _jsx(Provider, { value: this.state.intl, children: this.props.children }); | ||
| }; | ||
| IntlProvider.displayName = 'IntlProvider'; | ||
| IntlProvider.defaultProps = DEFAULT_INTL_CONFIG; | ||
| return IntlProvider; | ||
| }(React.PureComponent)); | ||
| export default IntlProvider; | ||
| export default class IntlProvider extends React.PureComponent { | ||
| static displayName = "IntlProvider"; | ||
| static defaultProps = DEFAULT_INTL_CONFIG; | ||
| cache = createIntlCache(); | ||
| state = { | ||
| cache: this.cache, | ||
| intl: createIntl(processIntlConfig(this.props), this.cache), | ||
| prevConfig: processIntlConfig(this.props) | ||
| }; | ||
| static getDerivedStateFromProps(props, { prevConfig, cache }) { | ||
| const config = processIntlConfig(props); | ||
| if (!shallowEqual(prevConfig, config)) { | ||
| return { | ||
| intl: createIntl(config, cache), | ||
| prevConfig: config | ||
| }; | ||
| } | ||
| return null; | ||
| } | ||
| render() { | ||
| invariantIntlContext(this.state.intl); | ||
| return /* @__PURE__ */ _jsx(Provider, { | ||
| value: this.state.intl, | ||
| children: this.props.children | ||
| }); | ||
| } | ||
| } |
@@ -1,10 +0,15 @@ | ||
| import * as React from 'react'; | ||
| import { FormatRelativeTimeOptions } from '@formatjs/intl'; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import * as React from "react"; | ||
| import { type FormatRelativeTimeOptions } from "@formatjs/intl"; | ||
| export interface Props extends FormatRelativeTimeOptions { | ||
| value?: number; | ||
| unit?: Intl.RelativeTimeFormatUnit; | ||
| updateIntervalInSeconds?: number; | ||
| children?(value: string): React.ReactElement | null; | ||
| value?: number; | ||
| unit?: Intl.RelativeTimeFormatUnit; | ||
| updateIntervalInSeconds?: number; | ||
| children?(value: string): React.ReactElement | null; | ||
| } | ||
| declare const FormattedRelativeTime: React.FC<Props>; | ||
| export default FormattedRelativeTime; |
+108
-114
@@ -1,126 +0,120 @@ | ||
| import { __assign, __rest } from "tslib"; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import * as React from "react"; | ||
| import "@formatjs/intl"; | ||
| import { invariant } from "../utils.js"; | ||
| import useIntl from "./useIntl.js"; | ||
| import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import * as React from 'react'; | ||
| import { invariant } from '../utils.js'; | ||
| import useIntl from './useIntl.js'; | ||
| var MINUTE = 60; | ||
| var HOUR = 60 * 60; | ||
| var DAY = 60 * 60 * 24; | ||
| const MINUTE = 60; | ||
| const HOUR = 60 * 60; | ||
| const DAY = 60 * 60 * 24; | ||
| function selectUnit(seconds) { | ||
| var absValue = Math.abs(seconds); | ||
| if (absValue < MINUTE) { | ||
| return 'second'; | ||
| } | ||
| if (absValue < HOUR) { | ||
| return 'minute'; | ||
| } | ||
| if (absValue < DAY) { | ||
| return 'hour'; | ||
| } | ||
| return 'day'; | ||
| const absValue = Math.abs(seconds); | ||
| if (absValue < MINUTE) { | ||
| return "second"; | ||
| } | ||
| if (absValue < HOUR) { | ||
| return "minute"; | ||
| } | ||
| if (absValue < DAY) { | ||
| return "hour"; | ||
| } | ||
| return "day"; | ||
| } | ||
| function getDurationInSeconds(unit) { | ||
| switch (unit) { | ||
| case 'second': | ||
| return 1; | ||
| case 'minute': | ||
| return MINUTE; | ||
| case 'hour': | ||
| return HOUR; | ||
| default: | ||
| return DAY; | ||
| } | ||
| switch (unit) { | ||
| case "second": return 1; | ||
| case "minute": return MINUTE; | ||
| case "hour": return HOUR; | ||
| default: return DAY; | ||
| } | ||
| } | ||
| function valueToSeconds(value, unit) { | ||
| if (!value) { | ||
| return 0; | ||
| } | ||
| switch (unit) { | ||
| case 'second': | ||
| return value; | ||
| case 'minute': | ||
| return value * MINUTE; | ||
| default: | ||
| return value * HOUR; | ||
| } | ||
| if (!value) { | ||
| return 0; | ||
| } | ||
| switch (unit) { | ||
| case "second": return value; | ||
| case "minute": return value * MINUTE; | ||
| default: return value * HOUR; | ||
| } | ||
| } | ||
| var INCREMENTABLE_UNITS = [ | ||
| 'second', | ||
| 'minute', | ||
| 'hour', | ||
| const INCREMENTABLE_UNITS = [ | ||
| "second", | ||
| "minute", | ||
| "hour" | ||
| ]; | ||
| function canIncrement(unit) { | ||
| if (unit === void 0) { unit = 'second'; } | ||
| return INCREMENTABLE_UNITS.indexOf(unit) > -1; | ||
| function canIncrement(unit = "second") { | ||
| return INCREMENTABLE_UNITS.indexOf(unit) > -1; | ||
| } | ||
| var SimpleFormattedRelativeTime = function (props) { | ||
| var _a = useIntl(), formatRelativeTime = _a.formatRelativeTime, Text = _a.textComponent; | ||
| var children = props.children, value = props.value, unit = props.unit, otherProps = __rest(props, ["children", "value", "unit"]); | ||
| var formattedRelativeTime = formatRelativeTime(value || 0, unit, otherProps); | ||
| if (typeof children === 'function') { | ||
| return children(formattedRelativeTime); | ||
| } | ||
| if (Text) { | ||
| return _jsx(Text, { children: formattedRelativeTime }); | ||
| } | ||
| return _jsx(_Fragment, { children: formattedRelativeTime }); | ||
| const SimpleFormattedRelativeTime = (props) => { | ||
| const { formatRelativeTime, textComponent: Text } = useIntl(); | ||
| const { children, value, unit, ...otherProps } = props; | ||
| const formattedRelativeTime = formatRelativeTime(value || 0, unit, otherProps); | ||
| if (typeof children === "function") { | ||
| return children(formattedRelativeTime); | ||
| } | ||
| if (Text) { | ||
| return /* @__PURE__ */ _jsx(Text, { children: formattedRelativeTime }); | ||
| } | ||
| return /* @__PURE__ */ _jsx(_Fragment, { children: formattedRelativeTime }); | ||
| }; | ||
| var FormattedRelativeTime = function (_a) { | ||
| var _b = _a.value, value = _b === void 0 ? 0 : _b, _c = _a.unit, unit = _c === void 0 ? 'second' : _c, updateIntervalInSeconds = _a.updateIntervalInSeconds, otherProps = __rest(_a, ["value", "unit", "updateIntervalInSeconds"]); | ||
| invariant(!updateIntervalInSeconds || | ||
| !!(updateIntervalInSeconds && canIncrement(unit)), 'Cannot schedule update with unit longer than hour'); | ||
| var _d = React.useState(), prevUnit = _d[0], setPrevUnit = _d[1]; | ||
| var _e = React.useState(0), prevValue = _e[0], setPrevValue = _e[1]; | ||
| var _f = React.useState(0), currentValueInSeconds = _f[0], setCurrentValueInSeconds = _f[1]; | ||
| var updateTimer; | ||
| if (unit !== prevUnit || value !== prevValue) { | ||
| setPrevValue(value || 0); | ||
| setPrevUnit(unit); | ||
| setCurrentValueInSeconds(canIncrement(unit) ? valueToSeconds(value, unit) : 0); | ||
| } | ||
| React.useEffect(function () { | ||
| function clearUpdateTimer() { | ||
| clearTimeout(updateTimer); | ||
| } | ||
| clearUpdateTimer(); | ||
| // If there's no interval and we cannot increment this unit, do nothing | ||
| if (!updateIntervalInSeconds || !canIncrement(unit)) { | ||
| return clearUpdateTimer; | ||
| } | ||
| // Figure out the next interesting time | ||
| var nextValueInSeconds = currentValueInSeconds - updateIntervalInSeconds; | ||
| var nextUnit = selectUnit(nextValueInSeconds); | ||
| // We've reached the max auto incrementable unit, don't schedule another update | ||
| if (nextUnit === 'day') { | ||
| return clearUpdateTimer; | ||
| } | ||
| var unitDuration = getDurationInSeconds(nextUnit); | ||
| var remainder = nextValueInSeconds % unitDuration; | ||
| var prevInterestingValueInSeconds = nextValueInSeconds - remainder; | ||
| var nextInterestingValueInSeconds = prevInterestingValueInSeconds >= currentValueInSeconds | ||
| ? prevInterestingValueInSeconds - unitDuration | ||
| : prevInterestingValueInSeconds; | ||
| var delayInSeconds = Math.abs(nextInterestingValueInSeconds - currentValueInSeconds); | ||
| if (currentValueInSeconds !== nextInterestingValueInSeconds) { | ||
| updateTimer = setTimeout(function () { return setCurrentValueInSeconds(nextInterestingValueInSeconds); }, delayInSeconds * 1e3); | ||
| } | ||
| return clearUpdateTimer; | ||
| }, [currentValueInSeconds, updateIntervalInSeconds, unit]); | ||
| var currentValue = value || 0; | ||
| var currentUnit = unit; | ||
| if (canIncrement(unit) && | ||
| typeof currentValueInSeconds === 'number' && | ||
| updateIntervalInSeconds) { | ||
| currentUnit = selectUnit(currentValueInSeconds); | ||
| var unitDuration = getDurationInSeconds(currentUnit); | ||
| currentValue = Math.round(currentValueInSeconds / unitDuration); | ||
| } | ||
| return (_jsx(SimpleFormattedRelativeTime, __assign({ value: currentValue, unit: currentUnit }, otherProps))); | ||
| const FormattedRelativeTime = ({ value = 0, unit = "second", updateIntervalInSeconds, ...otherProps }) => { | ||
| invariant(!updateIntervalInSeconds || !!(updateIntervalInSeconds && canIncrement(unit)), "Cannot schedule update with unit longer than hour"); | ||
| const [prevUnit, setPrevUnit] = React.useState(); | ||
| const [prevValue, setPrevValue] = React.useState(0); | ||
| const [currentValueInSeconds, setCurrentValueInSeconds] = React.useState(0); | ||
| const updateTimer = React.useRef(undefined); | ||
| if (unit !== prevUnit || value !== prevValue) { | ||
| setPrevValue(value || 0); | ||
| setPrevUnit(unit); | ||
| setCurrentValueInSeconds(canIncrement(unit) ? valueToSeconds(value, unit) : 0); | ||
| } | ||
| React.useEffect(() => { | ||
| function clearUpdateTimer() { | ||
| clearTimeout(updateTimer.current); | ||
| } | ||
| clearUpdateTimer(); | ||
| // If there's no interval and we cannot increment this unit, do nothing | ||
| if (!updateIntervalInSeconds || !canIncrement(unit)) { | ||
| return clearUpdateTimer; | ||
| } | ||
| // Figure out the next interesting time | ||
| const nextValueInSeconds = currentValueInSeconds - updateIntervalInSeconds; | ||
| const nextUnit = selectUnit(nextValueInSeconds); | ||
| // We've reached the max auto incrementable unit, don't schedule another update | ||
| if (nextUnit === "day") { | ||
| return clearUpdateTimer; | ||
| } | ||
| const unitDuration = getDurationInSeconds(nextUnit); | ||
| const remainder = nextValueInSeconds % unitDuration; | ||
| const prevInterestingValueInSeconds = nextValueInSeconds - remainder; | ||
| const nextInterestingValueInSeconds = prevInterestingValueInSeconds >= currentValueInSeconds ? prevInterestingValueInSeconds - unitDuration : prevInterestingValueInSeconds; | ||
| const delayInSeconds = Math.abs(nextInterestingValueInSeconds - currentValueInSeconds); | ||
| if (currentValueInSeconds !== nextInterestingValueInSeconds) { | ||
| updateTimer.current = setTimeout(() => setCurrentValueInSeconds(nextInterestingValueInSeconds), delayInSeconds * 1e3); | ||
| } | ||
| return clearUpdateTimer; | ||
| }, [ | ||
| currentValueInSeconds, | ||
| updateIntervalInSeconds, | ||
| unit | ||
| ]); | ||
| let currentValue = value || 0; | ||
| let currentUnit = unit; | ||
| if (canIncrement(unit) && typeof currentValueInSeconds === "number" && updateIntervalInSeconds) { | ||
| currentUnit = selectUnit(currentValueInSeconds); | ||
| const unitDuration = getDurationInSeconds(currentUnit); | ||
| currentValue = Math.round(currentValueInSeconds / unitDuration); | ||
| } | ||
| return /* @__PURE__ */ _jsx(SimpleFormattedRelativeTime, { | ||
| value: currentValue, | ||
| unit: currentUnit, | ||
| ...otherProps | ||
| }); | ||
| }; | ||
| FormattedRelativeTime.displayName = 'FormattedRelativeTime'; | ||
| FormattedRelativeTime.displayName = "FormattedRelativeTime"; | ||
| export default FormattedRelativeTime; |
@@ -1,2 +0,2 @@ | ||
| import { IntlShape } from '../types.js'; | ||
| import { type IntlShape } from "../types.js"; | ||
| export default function useIntl(this: void): IntlShape; |
@@ -1,8 +0,9 @@ | ||
| import * as React from 'react'; | ||
| import { invariantIntlContext } from '../utils.js'; | ||
| import { Context } from './injectIntl.js'; | ||
| import * as React from "react"; | ||
| import "../types.js"; | ||
| import { invariantIntlContext } from "../utils.js"; | ||
| import { Context } from "./injectIntl.js"; | ||
| export default function useIntl() { | ||
| var intl = React.useContext(Context); | ||
| invariantIntlContext(intl); | ||
| return intl; | ||
| const intl = React.useContext(Context); | ||
| invariantIntlContext(intl); | ||
| return intl; | ||
| } |
+14
-9
@@ -1,14 +0,19 @@ | ||
| import { ResolvedIntlConfig as CoreResolvedIntlConfig, Formatters, IntlFormatters, MessageDescriptor } from '@formatjs/intl'; | ||
| import { FormatXMLElementFn, Options as IntlMessageFormatOptions, PrimitiveType } from 'intl-messageformat'; | ||
| import * as React from 'react'; | ||
| import { DEFAULT_INTL_CONFIG } from './utils.js'; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import { type ResolvedIntlConfig as CoreResolvedIntlConfig, type Formatters, type IntlFormatters, type MessageDescriptor } from "@formatjs/intl"; | ||
| import { type FormatXMLElementFn, type Options as IntlMessageFormatOptions, type PrimitiveType } from "intl-messageformat"; | ||
| import * as React from "react"; | ||
| import type { DEFAULT_INTL_CONFIG } from "./utils.js"; | ||
| export type IntlConfig = Omit<ResolvedIntlConfig, keyof typeof DEFAULT_INTL_CONFIG> & Partial<typeof DEFAULT_INTL_CONFIG>; | ||
| export interface ResolvedIntlConfig extends CoreResolvedIntlConfig<React.ReactNode> { | ||
| textComponent?: React.ComponentType | keyof React.JSX.IntrinsicElements; | ||
| wrapRichTextChunksInFragment?: boolean; | ||
| textComponent?: React.ComponentType | keyof React.JSX.IntrinsicElements; | ||
| wrapRichTextChunksInFragment?: boolean; | ||
| } | ||
| export interface IntlShape extends ResolvedIntlConfig, IntlFormatters<React.ReactNode> { | ||
| formatMessage(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string; | ||
| formatMessage(this: void, descriptor: MessageDescriptor, values?: Record<string, React.ReactNode | PrimitiveType | FormatXMLElementFn<string, React.ReactNode>>, opts?: IntlMessageFormatOptions): Array<React.ReactNode>; | ||
| formatters: Formatters; | ||
| formatMessage(this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>, opts?: IntlMessageFormatOptions): string; | ||
| formatMessage(this: void, descriptor: MessageDescriptor, values?: Record<string, React.ReactNode | PrimitiveType | FormatXMLElementFn<string, React.ReactNode>>, opts?: IntlMessageFormatOptions): Array<React.ReactNode>; | ||
| formatters: Formatters; | ||
| } |
+8
-1
@@ -1,1 +0,8 @@ | ||
| export {}; | ||
| /* | ||
| * Copyright 2015, Yahoo Inc. | ||
| * Copyrights licensed under the New BSD License. | ||
| * See the accompanying LICENSE file for terms. | ||
| */ | ||
| import "@formatjs/intl"; | ||
| import "intl-messageformat"; | ||
| import * as React from "react"; |
+18
-18
@@ -1,26 +0,26 @@ | ||
| import { FormatXMLElementFn } from 'intl-messageformat'; | ||
| import * as React from 'react'; | ||
| import { ResolvedIntlConfig } from './types.js'; | ||
| import { type FormatXMLElementFn } from "intl-messageformat"; | ||
| import * as React from "react"; | ||
| import { type ResolvedIntlConfig } from "./types.js"; | ||
| export declare function invariant(condition: boolean, message: string, Err?: any): asserts condition; | ||
| export declare function invariantIntlContext(intl?: any): asserts intl; | ||
| export type DefaultIntlConfig = Pick<ResolvedIntlConfig, 'fallbackOnEmptyString' | 'formats' | 'messages' | 'timeZone' | 'textComponent' | 'defaultLocale' | 'defaultFormats' | 'onError'>; | ||
| export type DefaultIntlConfig = Pick<ResolvedIntlConfig, "fallbackOnEmptyString" | "formats" | "messages" | "timeZone" | "textComponent" | "defaultLocale" | "defaultFormats" | "onError">; | ||
| export declare const DEFAULT_INTL_CONFIG: DefaultIntlConfig; | ||
| /** | ||
| * Builds an array of {@link React.ReactNode}s with index-based keys, similar to | ||
| * {@link React.Children.toArray}. However, this function tells React that it | ||
| * was intentional, so they won't produce a bunch of warnings about it. | ||
| * | ||
| * React doesn't recommend doing this because it makes reordering inefficient, | ||
| * but we mostly need this for message chunks, which don't tend to reorder to | ||
| * begin with. | ||
| * | ||
| */ | ||
| * Builds an array of {@link React.ReactNode}s with index-based keys, similar to | ||
| * {@link React.Children.toArray}. However, this function tells React that it | ||
| * was intentional, so they won't produce a bunch of warnings about it. | ||
| * | ||
| * React doesn't recommend doing this because it makes reordering inefficient, | ||
| * but we mostly need this for message chunks, which don't tend to reorder to | ||
| * begin with. | ||
| * | ||
| */ | ||
| export declare const toKeyedReactNodeArray: typeof React.Children.toArray; | ||
| /** | ||
| * Takes a `formatXMLElementFn`, and composes it in function, which passes | ||
| * argument `parts` through, assigning unique key to each part, to prevent | ||
| * "Each child in a list should have a unique "key"" React error. | ||
| * @param formatXMLElementFn | ||
| */ | ||
| * Takes a `formatXMLElementFn`, and composes it in function, which passes | ||
| * argument `parts` through, assigning unique key to each part, to prevent | ||
| * "Each child in a list should have a unique "key"" React error. | ||
| * @param formatXMLElementFn | ||
| */ | ||
| export declare function assignUniqueKeysToParts(formatXMLElementFn: FormatXMLElementFn<React.ReactNode>): FormatXMLElementFn<React.ReactNode>; | ||
| export declare function shallowEqual<T extends Record<string, unknown> = Record<string, unknown>>(objA?: T, objB?: T): boolean; |
+60
-59
@@ -1,70 +0,71 @@ | ||
| import { __assign } from "tslib"; | ||
| import "intl-messageformat"; | ||
| import * as React from "react"; | ||
| import "./types.js"; | ||
| import { DEFAULT_INTL_CONFIG as CORE_DEFAULT_INTL_CONFIG } from "@formatjs/intl"; | ||
| import { jsx as _jsx } from "react/jsx-runtime"; | ||
| import * as React from 'react'; | ||
| import { DEFAULT_INTL_CONFIG as CORE_DEFAULT_INTL_CONFIG } from '@formatjs/intl'; | ||
| export function invariant(condition, message, Err) { | ||
| if (Err === void 0) { Err = Error; } | ||
| if (!condition) { | ||
| throw new Err(message); | ||
| } | ||
| export function invariant(condition, message, Err = Error) { | ||
| if (!condition) { | ||
| throw new Err(message); | ||
| } | ||
| } | ||
| export function invariantIntlContext(intl) { | ||
| invariant(intl, '[React Intl] Could not find required `intl` object. ' + | ||
| '<IntlProvider> needs to exist in the component ancestry.'); | ||
| invariant(intl, "[React Intl] Could not find required `intl` object. " + "<IntlProvider> needs to exist in the component ancestry."); | ||
| } | ||
| export var DEFAULT_INTL_CONFIG = __assign(__assign({}, CORE_DEFAULT_INTL_CONFIG), { textComponent: React.Fragment }); | ||
| export const DEFAULT_INTL_CONFIG = { | ||
| ...CORE_DEFAULT_INTL_CONFIG, | ||
| textComponent: React.Fragment | ||
| }; | ||
| /** | ||
| * Builds an array of {@link React.ReactNode}s with index-based keys, similar to | ||
| * {@link React.Children.toArray}. However, this function tells React that it | ||
| * was intentional, so they won't produce a bunch of warnings about it. | ||
| * | ||
| * React doesn't recommend doing this because it makes reordering inefficient, | ||
| * but we mostly need this for message chunks, which don't tend to reorder to | ||
| * begin with. | ||
| * | ||
| */ | ||
| export var toKeyedReactNodeArray = function (children) { | ||
| var childrenArray = React.Children.toArray(children); | ||
| return childrenArray.map(function (child, index) { | ||
| // For React elements, wrap in a keyed Fragment | ||
| // This creates a new element with a key rather than trying to add one after creation | ||
| if (React.isValidElement(child)) { | ||
| return _jsx(React.Fragment, { children: child }, index); | ||
| } | ||
| return child; | ||
| }); | ||
| * Builds an array of {@link React.ReactNode}s with index-based keys, similar to | ||
| * {@link React.Children.toArray}. However, this function tells React that it | ||
| * was intentional, so they won't produce a bunch of warnings about it. | ||
| * | ||
| * React doesn't recommend doing this because it makes reordering inefficient, | ||
| * but we mostly need this for message chunks, which don't tend to reorder to | ||
| * begin with. | ||
| * | ||
| */ | ||
| export const toKeyedReactNodeArray = (children) => { | ||
| const childrenArray = React.Children.toArray(children); | ||
| return childrenArray.map((child, index) => { | ||
| // For React elements, wrap in a keyed Fragment | ||
| // This creates a new element with a key rather than trying to add one after creation | ||
| if (React.isValidElement(child)) { | ||
| return /* @__PURE__ */ _jsx(React.Fragment, { children: child }, index); | ||
| } | ||
| return child; | ||
| }); | ||
| }; | ||
| /** | ||
| * Takes a `formatXMLElementFn`, and composes it in function, which passes | ||
| * argument `parts` through, assigning unique key to each part, to prevent | ||
| * "Each child in a list should have a unique "key"" React error. | ||
| * @param formatXMLElementFn | ||
| */ | ||
| * Takes a `formatXMLElementFn`, and composes it in function, which passes | ||
| * argument `parts` through, assigning unique key to each part, to prevent | ||
| * "Each child in a list should have a unique "key"" React error. | ||
| * @param formatXMLElementFn | ||
| */ | ||
| export function assignUniqueKeysToParts(formatXMLElementFn) { | ||
| return function (parts) { | ||
| // eslint-disable-next-line prefer-rest-params | ||
| return formatXMLElementFn(toKeyedReactNodeArray(parts)); | ||
| }; | ||
| return function(parts) { | ||
| // eslint-disable-next-line prefer-rest-params | ||
| return formatXMLElementFn(toKeyedReactNodeArray(parts)); | ||
| }; | ||
| } | ||
| export function shallowEqual(objA, objB) { | ||
| if (objA === objB) { | ||
| return true; | ||
| } | ||
| if (!objA || !objB) { | ||
| return false; | ||
| } | ||
| var aKeys = Object.keys(objA); | ||
| var bKeys = Object.keys(objB); | ||
| var len = aKeys.length; | ||
| if (bKeys.length !== len) { | ||
| return false; | ||
| } | ||
| for (var i = 0; i < len; i++) { | ||
| var key = aKeys[i]; | ||
| if (objA[key] !== objB[key] || | ||
| !Object.prototype.hasOwnProperty.call(objB, key)) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| if (objA === objB) { | ||
| return true; | ||
| } | ||
| if (!objA || !objB) { | ||
| return false; | ||
| } | ||
| var aKeys = Object.keys(objA); | ||
| var bKeys = Object.keys(objB); | ||
| var len = aKeys.length; | ||
| if (bKeys.length !== len) { | ||
| return false; | ||
| } | ||
| for (var i = 0; i < len; i++) { | ||
| var key = aKeys[i]; | ||
| if (objA[key] !== objB[key] || !Object.prototype.hasOwnProperty.call(objB, key)) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
308928
63.03%10948
97.8%18
350%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated