@intlayer/react-intl 9.9.3-canary.1 → 9.9.4

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.
@@ -119,6 +119,22 @@ const FormattedListParts = ({ value, children, ...options }) => {
119
119
  const parts = intl.formatListToParts(strings, options);
120
120
  return /* @__PURE__ */ jsx(Fragment, { children: children(parts) });
121
121
  };
122
+ /**
123
+ * Drop-in for react-intl's `<FormattedDuration>`.
124
+ * Renders a locale-aware duration using `Intl.DurationFormat`.
125
+ */
126
+ const FormattedDuration = (({ value, children, ...options }) => {
127
+ const formatted = useIntl().formatDuration(value, options);
128
+ if (typeof children === "function") return children(formatted);
129
+ return /* @__PURE__ */ jsx(Fragment, { children: formatted });
130
+ });
131
+ /**
132
+ * Drop-in for react-intl's `<FormattedDurationParts>`.
133
+ * Renders duration format parts via a `children` render-prop.
134
+ */
135
+ const FormattedDurationParts = (({ value, children, ...options }) => {
136
+ return children(useIntl().formatDurationToParts(value, options));
137
+ });
122
138
 
123
- export { FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedList, FormattedListParts, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts };
139
+ export { FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedDuration, FormattedDurationParts, FormattedList, FormattedListParts, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts };
124
140
  //# sourceMappingURL=FormattedComponents.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormattedComponents.mjs","names":[],"sources":["../../src/FormattedComponents.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactElement } from 'react';\nimport type {\n FormattedDate as _FormattedDate,\n FormattedDateParts as _FormattedDateParts,\n FormattedDateTimeRange as _FormattedDateTimeRange,\n FormattedDisplayName as _FormattedDisplayName,\n FormattedList as _FormattedList,\n FormattedListParts as _FormattedListParts,\n FormattedNumber as _FormattedNumber,\n FormattedNumberParts as _FormattedNumberParts,\n FormattedPlural as _FormattedPlural,\n FormattedRelativeTime as _FormattedRelativeTime,\n FormattedTime as _FormattedTime,\n FormattedTimeParts as _FormattedTimeParts,\n} from 'react-intl';\nimport { useIntl } from './useIntl';\n\nconst toDate = (value: Date | number | string | undefined): Date =>\n value instanceof Date\n ? value\n : typeof value === 'undefined'\n ? new Date()\n : new Date(value);\n\n/**\n * Drop-in for react-intl's `<FormattedDate>`.\n * Renders a locale-aware date string using `Intl.DateTimeFormat`.\n */\nexport const FormattedDate: typeof _FormattedDate = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatDate(value, options);\n if (typeof children === 'function') {\n return (children(formatted) ?? null) as ReactElement | null;\n }\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedTime>`.\n * Renders a locale-aware time string using `Intl.DateTimeFormat`.\n */\nexport const FormattedTime: typeof _FormattedTime = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatTime(value, options);\n if (typeof children === 'function') {\n return (children(formatted) ?? null) as ReactElement | null;\n }\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedNumber>`.\n * Renders a locale-aware number string using `Intl.NumberFormat`.\n */\nexport const FormattedNumber: typeof _FormattedNumber = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatNumber(value, options);\n if (typeof children === 'function') {\n return (children(formatted) ?? null) as ReactElement | null;\n }\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedList>`.\n * Renders a locale-aware list string using `Intl.ListFormat`.\n */\nexport const FormattedList: typeof _FormattedList = ({ value, ...options }) => {\n const intl = useIntl();\n const strings = (value as unknown[]).filter(\n (item): item is string => typeof item === 'string'\n );\n const formatted = intl.formatList(strings, options);\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedDisplayName>`.\n * Renders a locale-aware display name using `Intl.DisplayNames`.\n */\nexport const FormattedDisplayName: typeof _FormattedDisplayName = ({\n value,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatDisplayName(\n value,\n options as Intl.DisplayNamesOptions\n );\n return <>{formatted ?? value}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedRelativeTime>`.\n * Renders a locale-aware relative time string using `Intl.RelativeTimeFormat`.\n * Auto-update (`updateIntervalInSeconds`) is not implemented.\n */\nexport const FormattedRelativeTime: typeof _FormattedRelativeTime = ({\n value = 0,\n unit = 'second',\n children,\n updateIntervalInSeconds: _updateIntervalInSeconds,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatRelativeTime(value, unit, options);\n if (typeof children === 'function') {\n return (children(formatted) ?? null) as ReactElement | null;\n }\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedPlural>`.\n * Selects the matching plural slot using `Intl.PluralRules`.\n */\nexport const FormattedPlural: typeof _FormattedPlural = ({\n value,\n other,\n zero,\n one,\n two,\n few,\n many,\n children,\n ...options\n}) => {\n const intl = useIntl();\n const rule = intl.formatPlural(value, options);\n const slots: Record<Intl.LDMLPluralRule, unknown> = {\n zero,\n one,\n two,\n few,\n many,\n other,\n };\n const selected = slots[rule] ?? other;\n\n if (typeof children === 'function') {\n return (children(selected as import('react').ReactNode) ??\n null) as ReactElement | null;\n }\n\n return <>{selected}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedDateTimeRange>`.\n * Renders a locale-aware date range string using `Intl.DateTimeFormat#formatRange`.\n */\nexport const FormattedDateTimeRange: typeof _FormattedDateTimeRange = ({\n from,\n to,\n children,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatDateTimeRange(from, to, options);\n if (typeof children === 'function') {\n return (children(formatted) ?? null) as ReactElement | null;\n }\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedDateParts>`.\n * Renders format parts via a `children` render-prop.\n */\nexport const FormattedDateParts: typeof _FormattedDateParts = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const parts = intl.formatDateToParts(\n value as Parameters<Intl.DateTimeFormat['format']>[0],\n options\n );\n return <>{children(parts)}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedTimeParts>`.\n * Renders format parts via a `children` render-prop.\n */\nexport const FormattedTimeParts: typeof _FormattedTimeParts = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const parts = intl.formatTimeToParts(\n value as Parameters<Intl.DateTimeFormat['format']>[0],\n options\n );\n return <>{children(parts)}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedNumberParts>`.\n * Renders format parts via a `children` render-prop.\n */\nexport const FormattedNumberParts: typeof _FormattedNumberParts = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const parts = intl.formatNumberToParts(value, options);\n return <>{children(parts)}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedListParts>`.\n * Renders list format parts via a `children` render-prop.\n */\nexport const FormattedListParts: typeof _FormattedListParts = ({\n value,\n children,\n ...options\n}) => {\n const intl = useIntl();\n const strings = Array.from(value).filter(\n (item): item is string => typeof item === 'string'\n );\n const parts = intl.formatListToParts(strings, options);\n return <>{children(parts)}</>;\n};\n"],"mappings":";;;;;;;;;;AA8BA,MAAa,iBAAwC,EACnD,OACA,UACA,QAAQ,SACR,GAAG,cACC;CAEJ,MAAM,YADO,QACQ,CAAC,CAAC,WAAW,OAAO,OAAO;CAChD,IAAI,OAAO,aAAa,YACtB,OAAQ,SAAS,SAAS,KAAK;CAEjC,OAAO,0CAAG,UAAY;AACxB;;;;;AAMA,MAAa,iBAAwC,EACnD,OACA,UACA,QAAQ,SACR,GAAG,cACC;CAEJ,MAAM,YADO,QACQ,CAAC,CAAC,WAAW,OAAO,OAAO;CAChD,IAAI,OAAO,aAAa,YACtB,OAAQ,S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AM,IAAI,OAAO;CAC5D,IAAI,OAAO,aAAa,YACtB,OAAQ,SAAS,SAAS,KAAK;CAEjC,OAAO,0CAAG,UAAY;AACxB;;;;;AAMA,MAAa,sBAAkD,EAC7D,OACA,UACA,QAAQ,SACR,GAAG,cACC;CAEJ,MAAM,QADO,QACI,CAAC,CAAC,kBACjB,OACA,OACF;CACA,OAAO,0CAAG,SAAS,KAAK,EAAI;AAC9B;;;;;AAMA,MAAa,sBAAkD,EAC7D,OACA,UACA,QAAQ,SACR,GAAG,cACC;CAEJ,MAAM,QADO,QACI,CAAC,CAAC,kBACjB,OACA,OACF;CACA,OAAO,0CAAG,SAAS,KAAK,EAAI;AAC9B;;;;;AAMA,MAAa,wBAAsD,EACjE,OACA,UACA,QAAQ,SACR,GAAG,cACC;CAEJ,MAAM,QADO,QACI,CAAC,CAAC,oBAAoB,OAAO,OAAO;CACrD,OAAO,0CAAG,SAAS,KAAK,EAAI;AAC9B;;;;;AAMA,MAAa,sBAAkD,EAC7D,OACA,UACA,GAAG,cACC;CACJ,MAAM,OAAO,QAAQ;CACrB,MAAM,UAAU,MAAM,KAAK,KAAK,CAAC,CAAC,QAC/B,SAAyB,OAAO,SAAS,QAC5C;CACA,MAAM,QAAQ,KAAK,kBAAkB,SAAS,OAAO;CACrD,OAAO,0CAAG,SAAS,KAAK,EAAI;AAC9B"}
1
+ {"version":3,"file":"FormattedComponents.mjs","names":[],"sources":["../../src/FormattedComponents.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactElement } from 'react';\nimport type {\n FormattedDate as _FormattedDate,\n FormattedDateParts as _FormattedDateParts,\n FormattedDateTimeRange as _FormattedDateTimeRange,\n FormattedDisplayName as _FormattedDisplayName,\n FormattedDuration as _FormattedDuration,\n FormattedDurationParts as _FormattedDurationParts,\n FormattedList as _FormattedList,\n FormattedListParts as _FormattedListParts,\n FormattedNumber as _FormattedNumber,\n FormattedNumberParts as _FormattedNumberParts,\n FormattedPlural as _FormattedPlural,\n FormattedRelativeTime as _FormattedRelativeTime,\n FormattedTime as _FormattedTime,\n FormattedTimeParts as _FormattedTimeParts,\n} from 'react-intl';\nimport { useIntl } from './useIntl';\n\nconst toDate = (value: Date | number | string | undefined): Date =>\n value instanceof Date\n ? value\n : typeof value === 'undefined'\n ? new Date()\n : new Date(value);\n\n/**\n * Drop-in for react-intl's `<FormattedDate>`.\n * Renders a locale-aware date string using `Intl.DateTimeFormat`.\n */\nexport const FormattedDate: typeof _FormattedDate = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatDate(value, options);\n if (typeof children === 'function') {\n return (children(formatted) ?? null) as ReactElement | null;\n }\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedTime>`.\n * Renders a locale-aware time string using `Intl.DateTimeFormat`.\n */\nexport const FormattedTime: typeof _FormattedTime = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatTime(value, options);\n if (typeof children === 'function') {\n return (children(formatted) ?? null) as ReactElement | null;\n }\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedNumber>`.\n * Renders a locale-aware number string using `Intl.NumberFormat`.\n */\nexport const FormattedNumber: typeof _FormattedNumber = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatNumber(value, options);\n if (typeof children === 'function') {\n return (children(formatted) ?? null) as ReactElement | null;\n }\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedList>`.\n * Renders a locale-aware list string using `Intl.ListFormat`.\n */\nexport const FormattedList: typeof _FormattedList = ({ value, ...options }) => {\n const intl = useIntl();\n const strings = (value as unknown[]).filter(\n (item): item is string => typeof item === 'string'\n );\n const formatted = intl.formatList(strings, options);\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedDisplayName>`.\n * Renders a locale-aware display name using `Intl.DisplayNames`.\n */\nexport const FormattedDisplayName: typeof _FormattedDisplayName = ({\n value,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatDisplayName(\n value,\n options as Intl.DisplayNamesOptions\n );\n return <>{formatted ?? value}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedRelativeTime>`.\n * Renders a locale-aware relative time string using `Intl.RelativeTimeFormat`.\n * Auto-update (`updateIntervalInSeconds`) is not implemented.\n */\nexport const FormattedRelativeTime: typeof _FormattedRelativeTime = ({\n value = 0,\n unit = 'second',\n children,\n updateIntervalInSeconds: _updateIntervalInSeconds,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatRelativeTime(value, unit, options);\n if (typeof children === 'function') {\n return (children(formatted) ?? null) as ReactElement | null;\n }\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedPlural>`.\n * Selects the matching plural slot using `Intl.PluralRules`.\n */\nexport const FormattedPlural: typeof _FormattedPlural = ({\n value,\n other,\n zero,\n one,\n two,\n few,\n many,\n children,\n ...options\n}) => {\n const intl = useIntl();\n const rule = intl.formatPlural(value, options);\n const slots: Record<Intl.LDMLPluralRule, unknown> = {\n zero,\n one,\n two,\n few,\n many,\n other,\n };\n const selected = slots[rule] ?? other;\n\n if (typeof children === 'function') {\n return (children(selected as import('react').ReactNode) ??\n null) as ReactElement | null;\n }\n\n return <>{selected}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedDateTimeRange>`.\n * Renders a locale-aware date range string using `Intl.DateTimeFormat#formatRange`.\n */\nexport const FormattedDateTimeRange: typeof _FormattedDateTimeRange = ({\n from,\n to,\n children,\n ...options\n}) => {\n const intl = useIntl();\n const formatted = intl.formatDateTimeRange(from, to, options);\n if (typeof children === 'function') {\n return (children(formatted) ?? null) as ReactElement | null;\n }\n return <>{formatted}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedDateParts>`.\n * Renders format parts via a `children` render-prop.\n */\nexport const FormattedDateParts: typeof _FormattedDateParts = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const parts = intl.formatDateToParts(\n value as Parameters<Intl.DateTimeFormat['format']>[0],\n options\n );\n return <>{children(parts)}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedTimeParts>`.\n * Renders format parts via a `children` render-prop.\n */\nexport const FormattedTimeParts: typeof _FormattedTimeParts = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const parts = intl.formatTimeToParts(\n value as Parameters<Intl.DateTimeFormat['format']>[0],\n options\n );\n return <>{children(parts)}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedNumberParts>`.\n * Renders format parts via a `children` render-prop.\n */\nexport const FormattedNumberParts: typeof _FormattedNumberParts = ({\n value,\n children,\n format: _format,\n ...options\n}) => {\n const intl = useIntl();\n const parts = intl.formatNumberToParts(value, options);\n return <>{children(parts)}</>;\n};\n\n/**\n * Drop-in for react-intl's `<FormattedListParts>`.\n * Renders list format parts via a `children` render-prop.\n */\nexport const FormattedListParts: typeof _FormattedListParts = ({\n value,\n children,\n ...options\n}) => {\n const intl = useIntl();\n const strings = Array.from(value).filter(\n (item): item is string => typeof item === 'string'\n );\n const parts = intl.formatListToParts(strings, options);\n return <>{children(parts)}</>;\n};\n\n/** `IntlShape` with react-intl's duration formatters. */\ntype IntlWithDuration = {\n formatDuration: (value: unknown, options: object) => string;\n formatDurationToParts: (value: unknown, options: object) => unknown[];\n};\n\n/**\n * Drop-in for react-intl's `<FormattedDuration>`.\n * Renders a locale-aware duration using `Intl.DurationFormat`.\n */\nexport const FormattedDuration = (({\n value,\n children,\n ...options\n}: {\n value: unknown;\n children?: (formatted: string) => ReactElement | null;\n}) => {\n const intl = useIntl() as unknown as IntlWithDuration;\n const formatted = intl.formatDuration(value, options);\n if (typeof children === 'function') return children(formatted);\n return <>{formatted}</>;\n}) as unknown as typeof _FormattedDuration;\n\n/**\n * Drop-in for react-intl's `<FormattedDurationParts>`.\n * Renders duration format parts via a `children` render-prop.\n */\nexport const FormattedDurationParts = (({\n value,\n children,\n ...options\n}: {\n value: unknown;\n children: (parts: unknown[]) => ReactElement | null;\n}) => {\n const intl = useIntl() as unknown as IntlWithDuration;\n return children(intl.formatDurationToParts(value, options));\n}) as unknown as typeof _FormattedDurationParts;\n"],"mappings":";;;;;;;;;;AAgCA,MAAa,iBAAwC,EACnD,OACA,UACA,QAAQ,SACR,GAAG,cACC;CAEJ,MAAM,YADO,QACQ,CAAC,CAAC,WAAW,OAAO,OAAO;CAChD,IAAI,OAAO,aAAa,YACtB,OAAQ,SAAS,SAAS,KAAK;CAEjC,OAAO,0CAAG,UAAY;AACxB;;;;;AAMA,MAAa,iBAAwC,EACnD,OACA,UACA,QAAQ,SACR,GAAG,cACC;CAEJ,MAAM,YADO,QACQ,CAAC,CAAC,WAAW,OAAO,OAAO;CAChD,IAAI,OAAO,aAAa,YACtB,OAAQ,SAAS,SAAS,KAAK;CAEjC,OAAO,0CAAG,UAAY;AACxB;;;;;AAMA,MAAa,mBAA4C,EACvD,OACA,UACA,QAAQ,SACR,GAAG,cACC;CAEJ,MAAM,YADO,QACQ,CAAC,CAAC,aAAa,OAAO,OAAO;CAClD,IAAI,OAAO,aAAa,YACtB,OAAQ,SAAS,SAAS,KAAK;CAEjC,OAAO,0CAAG,UAAY;AACxB;;;;;AAMA,MAAa,iBAAwC,EAAE,OAAO,GAAG,cAAc;CAC7E,MAAM,OAAO,QAAQ;CACrB,MAAM,UAAW,MAAoB,QAClC,SAAyB,OAAO,SAAS,QAC5C;CACA,MAAM,YAAY,KAAK,WAAW,SAAS,OAAO;CAClD,OAAO,0CAAG,UAAY;AACxB;;;;;AAMA,MAAa,wBAAsD,EACjE,OACA,GAAG,cACC;CAEJ,MAAM,YADO,QACQ,CAAC,CAAC,kBACrB,OACA,OACF;CACA,OAAO,0CAAG,aAAa,MAAQ;AACjC;;;;;;AAOA,MAAa,yBAAwD,EACnE,QAAQ,GACR,OAAO,UACP,UACA,yBAAyB,0BACzB,GAAG,cACC;CAEJ,M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AK,KAAK,CAAC,CAAC,QAC/B,SAAyB,OAAO,SAAS,QAC5C;CACA,MAAM,QAAQ,KAAK,kBAAkB,SAAS,OAAO;CACrD,OAAO,0CAAG,SAAS,KAAK,EAAI;AAC9B;;;;;AAYA,MAAa,sBAAsB,EACjC,OACA,UACA,GAAG,cAIC;CAEJ,MAAM,YADO,QACQ,CAAC,CAAC,eAAe,OAAO,OAAO;CACpD,IAAI,OAAO,aAAa,YAAY,OAAO,SAAS,SAAS;CAC7D,OAAO,0CAAG,UAAY;AACxB;;;;;AAMA,MAAa,2BAA2B,EACtC,OACA,UACA,GAAG,cAIC;CAEJ,OAAO,SADM,QACM,CAAC,CAAC,sBAAsB,OAAO,OAAO,CAAC;AAC5D"}
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { useIntl } from "./useIntl.mjs";
4
- import { Fragment } from "react";
4
+ import { Fragment, memo } from "react";
5
5
  import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
6
6
 
7
7
  // src/FormattedMessage.tsx
@@ -26,7 +26,7 @@ import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
26
26
  * />
27
27
  * ```
28
28
  */
29
- const FormattedMessage = (({ id = "", description: _description, defaultMessage, values, tagName: TagName, children, ignoreTag: _ignoreTag }) => {
29
+ const FormattedMessageComponent = ({ id = "", description: _description, defaultMessage, values, tagName: TagName, children, ignoreTag: _ignoreTag }) => {
30
30
  const intl = useIntl();
31
31
  const stringDefaultMessage = typeof defaultMessage === "string" ? defaultMessage : void 0;
32
32
  const result = intl.formatMessage({
@@ -37,7 +37,19 @@ const FormattedMessage = (({ id = "", description: _description, defaultMessage,
37
37
  if (typeof children === "function") return children(nodes) ?? null;
38
38
  if (TagName && TagName !== Fragment) return /* @__PURE__ */ jsx(TagName, { children: nodes });
39
39
  return /* @__PURE__ */ jsx(Fragment$1, { children: nodes });
40
- });
40
+ };
41
+ /** Whether two objects hold the same values under the same keys. */
42
+ const isShallowEqual = (first, second) => {
43
+ if (first === second) return true;
44
+ if (!first || !second) return false;
45
+ const firstKeys = Object.keys(first);
46
+ return firstKeys.length === Object.keys(second).length && firstKeys.every((key) => Object.hasOwn(second, key) && first[key] === second[key]);
47
+ };
48
+ /** Re-render only when `values` or another prop changes, as upstream. */
49
+ const arePropsEqual = ({ values, ...otherProps }, { values: nextValues, ...nextOtherProps }) => isShallowEqual(nextValues, values) && isShallowEqual(otherProps, nextOtherProps);
50
+ const MemoizedFormattedMessage = memo(FormattedMessageComponent, arePropsEqual);
51
+ MemoizedFormattedMessage.displayName = "MemoizedFormattedMessage";
52
+ const FormattedMessage = MemoizedFormattedMessage;
41
53
 
42
54
  export { FormattedMessage };
43
55
  //# sourceMappingURL=FormattedMessage.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormattedMessage.mjs","names":[],"sources":["../../src/FormattedMessage.tsx"],"sourcesContent":["'use client';\n\nimport {\n type ComponentProps,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { FormattedMessage as _FormattedMessage } from 'react-intl';\nimport { useIntl } from './useIntl';\n\n/**\n * Drop-in for react-intl's `<FormattedMessage>`.\n *\n * Translates the message identified by `id` using the active intl context.\n * Full ICU MessageFormat syntax is supported.\n *\n * When `values` contains render functions, rich text tags\n * (`<b>chunks</b>`) are mapped through them. When a `tagName` is provided,\n * the output is wrapped in that element; otherwise a fragment is used.\n * A `children` render-prop receives the resolved nodes.\n *\n * @example\n * ```tsx\n * <FormattedMessage id=\"home.title\" />\n * <FormattedMessage id=\"home.greeting\" values={{ name: 'Alice' }} />\n * <FormattedMessage\n * id=\"terms.agreement\"\n * values={{ b: (chunks) => <strong>{chunks}</strong> }}\n * />\n * ```\n */\nexport const FormattedMessage: typeof _FormattedMessage = (({\n id = '',\n description: _description,\n defaultMessage,\n values,\n tagName: TagName,\n children,\n ignoreTag: _ignoreTag,\n}: ComponentProps<typeof _FormattedMessage>) => {\n const intl = useIntl();\n const stringDefaultMessage =\n typeof defaultMessage === 'string' ? defaultMessage : undefined;\n const result = (\n intl.formatMessage as (\n descriptor: { id: string; defaultMessage?: string },\n values?: Record<string, unknown>\n ) => string | ReactNode[]\n )(\n { id, defaultMessage: stringDefaultMessage },\n values as Record<string, unknown>\n );\n const nodes: ReactNode[] = Array.isArray(result) ? result : [result];\n\n if (typeof children === 'function') {\n return (children(nodes) ?? null) as ReactElement | null;\n }\n\n if (TagName && TagName !== Fragment) {\n return <TagName>{nodes}</TagName>;\n }\n\n return <>{nodes}</>;\n}) as unknown as typeof _FormattedMessage;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,qBAA+C,EAC1D,KAAK,IACL,aAAa,cACb,gBACA,QACA,SAAS,SACT,UACA,WAAW,iBACmC;CAC9C,MAAM,OAAO,QAAQ;CACrB,MAAM,uBACJ,OAAO,mBAAmB,WAAW,iBAAiB;CACxD,MAAM,SACJ,KAAK,cAKL;EAAE;EAAI,gBAAgB;CAAqB,GAC3C,MACF;CACA,MAAM,QAAqB,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;CAEnE,IAAI,OAAO,aAAa,YACtB,OAAQ,SAAS,KAAK,KAAK;CAG7B,IAAI,WAAW,YAAY,UACzB,OAAO,oBAAC,SAAD,YAAU,MAAe;CAGlC,OAAO,4CAAG,MAAQ;AACpB"}
1
+ {"version":3,"file":"FormattedMessage.mjs","names":[],"sources":["../../src/FormattedMessage.tsx"],"sourcesContent":["'use client';\n\nimport {\n type ComponentProps,\n Fragment,\n memo,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { FormattedMessage as _FormattedMessage } from 'react-intl';\nimport { useIntl } from './useIntl';\n\n/**\n * Drop-in for react-intl's `<FormattedMessage>`.\n *\n * Translates the message identified by `id` using the active intl context.\n * Full ICU MessageFormat syntax is supported.\n *\n * When `values` contains render functions, rich text tags\n * (`<b>chunks</b>`) are mapped through them. When a `tagName` is provided,\n * the output is wrapped in that element; otherwise a fragment is used.\n * A `children` render-prop receives the resolved nodes.\n *\n * @example\n * ```tsx\n * <FormattedMessage id=\"home.title\" />\n * <FormattedMessage id=\"home.greeting\" values={{ name: 'Alice' }} />\n * <FormattedMessage\n * id=\"terms.agreement\"\n * values={{ b: (chunks) => <strong>{chunks}</strong> }}\n * />\n * ```\n */\nconst FormattedMessageComponent = ({\n id = '',\n description: _description,\n defaultMessage,\n values,\n tagName: TagName,\n children,\n ignoreTag: _ignoreTag,\n}: ComponentProps<typeof _FormattedMessage>) => {\n const intl = useIntl();\n const stringDefaultMessage =\n typeof defaultMessage === 'string' ? defaultMessage : undefined;\n const result = (\n intl.formatMessage as (\n descriptor: { id: string; defaultMessage?: string },\n values?: Record<string, unknown>\n ) => string | ReactNode[]\n )(\n { id, defaultMessage: stringDefaultMessage },\n values as Record<string, unknown>\n );\n const nodes: ReactNode[] = Array.isArray(result) ? result : [result];\n\n if (typeof children === 'function') {\n return (children(nodes) ?? null) as ReactElement | null;\n }\n\n if (TagName && TagName !== Fragment) {\n return <TagName>{nodes}</TagName>;\n }\n\n return <>{nodes}</>;\n};\n\ntype FormattedMessageProps = ComponentProps<typeof _FormattedMessage>;\n\n/** Whether two objects hold the same values under the same keys. */\nconst isShallowEqual = (\n first: object | undefined,\n second: object | undefined\n): boolean => {\n if (first === second) return true;\n if (!first || !second) return false;\n\n const firstKeys = Object.keys(first);\n return (\n firstKeys.length === Object.keys(second).length &&\n firstKeys.every(\n (key) =>\n Object.hasOwn(second, key) &&\n (first as Record<string, unknown>)[key] ===\n (second as Record<string, unknown>)[key]\n )\n );\n};\n\n/** Re-render only when `values` or another prop changes, as upstream. */\nconst arePropsEqual = (\n { values, ...otherProps }: FormattedMessageProps,\n { values: nextValues, ...nextOtherProps }: FormattedMessageProps\n): boolean =>\n isShallowEqual(nextValues, values) &&\n isShallowEqual(otherProps, nextOtherProps);\n\nconst MemoizedFormattedMessage = memo(FormattedMessageComponent, arePropsEqual);\nMemoizedFormattedMessage.displayName = 'MemoizedFormattedMessage';\n\nexport const FormattedMessage =\n MemoizedFormattedMessage as unknown as typeof _FormattedMessage;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAM,6BAA6B,EACjC,KAAK,IACL,aAAa,cACb,gBACA,QACA,SAAS,SACT,UACA,WAAW,iBACmC;CAC9C,MAAM,OAAO,QAAQ;CACrB,MAAM,uBACJ,OAAO,mBAAmB,WAAW,iBAAiB;CACxD,MAAM,SACJ,KAAK,cAKL;EAAE;EAAI,gBAAgB;CAAqB,GAC3C,MACF;CACA,MAAM,QAAqB,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;CAEnE,IAAI,OAAO,aAAa,YACtB,OAAQ,SAAS,KAAK,KAAK;CAG7B,IAAI,WAAW,YAAY,UACzB,OAAO,oBAAC,SAAD,YAAU,MAAe;CAGlC,OAAO,4CAAG,MAAQ;AACpB;;AAKA,MAAM,kBACJ,OACA,WACY;CACZ,IAAI,UAAU,QAAQ,OAAO;CAC7B,IAAI,CAAC,SAAS,CAAC,QAAQ,OAAO;CAE9B,MAAM,YAAY,OAAO,KAAK,KAAK;CACnC,OACE,UAAU,WAAW,OAAO,KAAK,MAAM,CAAC,CAAC,UACzC,UAAU,OACP,QACC,OAAO,OAAO,QAAQ,GAAG,KACxB,MAAkC,SAChC,OAAmC,IAC1C;AAEJ;;AAGA,MAAM,iBACJ,EAAE,QAAQ,GAAG,cACb,EAAE,QAAQ,YAAY,GAAG,qBAEzB,eAAe,YAAY,MAAM,KACjC,eAAe,YAAY,cAAc;AAE3C,MAAM,2BAA2B,KAAK,2BAA2B,aAAa;AAC9E,yBAAyB,cAAc;AAEvC,MAAa,mBACX"}
@@ -13,14 +13,21 @@ import { IntlayerProvider } from "react-intlayer";
13
13
  /**
14
14
  * Drop-in for react-intl's `IntlProvider`.
15
15
  *
16
- * `messages`, `formats`, `timeZone`, `now`, `defaultRichTextElements`,
17
- * and `onError`/`onWarn` are accepted for API compatibility but have no
18
- * effect — Intlayer uses its own compiled dictionaries.
16
+ * `defaultRichTextElements` and `onError` apply to every message. `messages`,
17
+ * `formats`, `timeZone`, `now` and `onWarn` are accepted for API
18
+ * compatibility only — Intlayer uses its own compiled dictionaries.
19
19
  *
20
20
  * The `locale` prop is forwarded to `IntlayerClientProvider`.
21
21
  */
22
- const IntlProvider = ({ locale, children, messages: _messages, formats: _formats, timeZone: _timeZone, defaultRichTextElements: _defaultRichTextElements, onError: _onError, ...rest }) => {
23
- const intlObject = useMemo(() => createIntlObject(locale), [locale]);
22
+ const IntlProvider = ({ locale, children, messages: _messages, formats: _formats, timeZone: _timeZone, defaultRichTextElements, onError, ...rest }) => {
23
+ const intlObject = useMemo(() => createIntlObject(locale, void 0, {
24
+ defaultRichTextElements,
25
+ onError
26
+ }), [
27
+ locale,
28
+ defaultRichTextElements,
29
+ onError
30
+ ]);
24
31
  if (process.env.NODE_ENV === "development" && typeof _messages !== "undefined") getAppLogger({ log })(`${colorize("IntlProvider", CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reasons.`);
25
32
  return /* @__PURE__ */ jsx(IntlContext.Provider, {
26
33
  value: intlObject,
@@ -1 +1 @@
1
- {"version":3,"file":"IntlProvider.mjs","names":[],"sources":["../../src/IntlProvider.tsx"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useMemo } from 'react';\nimport type { IntlProvider as _IntlProvider } from 'react-intl';\nimport { IntlayerProvider } from 'react-intlayer';\nimport { IntlContext } from './context';\nimport { createIntlObject } from './createIntlObject';\n\n/**\n * Drop-in for react-intl's `IntlProvider`.\n *\n * `messages`, `formats`, `timeZone`, `now`, `defaultRichTextElements`,\n * and `onError`/`onWarn` are accepted for API compatibility but have no\n * effect — Intlayer uses its own compiled dictionaries.\n *\n * The `locale` prop is forwarded to `IntlayerClientProvider`.\n */\nexport const IntlProvider: typeof _IntlProvider = ({\n locale,\n children,\n messages: _messages,\n formats: _formats,\n timeZone: _timeZone,\n defaultRichTextElements: _defaultRichTextElements,\n onError: _onError,\n ...rest\n}) => {\n const intlObject = useMemo(\n () => createIntlObject(locale as LocalesValues),\n [locale]\n );\n\n if (\n process.env.NODE_ENV === 'development' &&\n typeof _messages !== 'undefined'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('IntlProvider', CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reasons.`\n );\n }\n\n return (\n <IntlContext.Provider value={intlObject}>\n <IntlayerProvider locale={locale as LocalesValues} {...(rest as object)}>\n {children}\n </IntlayerProvider>\n </IntlContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,gBAAsC,EACjD,QACA,UACA,UAAU,WACV,SAAS,UACT,UAAU,WACV,yBAAyB,0BACzB,SAAS,UACT,GAAG,WACC;CACJ,MAAM,aAAa,cACX,iBAAiB,MAAuB,GAC9C,CAAC,MAAM,CACT;CAEA,6BAC2B,iBACzB,OAAO,cAAc,aAGrB,AADkB,aAAa,EAAE,IAAI,CAC7B,CAAC,CACP,GAAG,SAAS,gBAAgB,IAAI,EAAE,gIACpC;CAGF,OACE,oBAAC,YAAY,UAAb;EAAsB,OAAO;YAC3B,oBAAC,kBAAD;GAA0B;GAAyB,GAAK;GACrD;EACe;CACE;AAE1B"}
1
+ {"version":3,"file":"IntlProvider.mjs","names":[],"sources":["../../src/IntlProvider.tsx"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useMemo } from 'react';\nimport type { IntlProvider as _IntlProvider } from 'react-intl';\nimport { IntlayerProvider } from 'react-intlayer';\nimport { IntlContext } from './context';\nimport { createIntlObject } from './createIntlObject';\n\n/**\n * Drop-in for react-intl's `IntlProvider`.\n *\n * `defaultRichTextElements` and `onError` apply to every message. `messages`,\n * `formats`, `timeZone`, `now` and `onWarn` are accepted for API\n * compatibility only — Intlayer uses its own compiled dictionaries.\n *\n * The `locale` prop is forwarded to `IntlayerClientProvider`.\n */\nexport const IntlProvider: typeof _IntlProvider = ({\n locale,\n children,\n messages: _messages,\n formats: _formats,\n timeZone: _timeZone,\n defaultRichTextElements,\n onError,\n ...rest\n}) => {\n const intlObject = useMemo(\n () =>\n createIntlObject(locale as LocalesValues, undefined, {\n defaultRichTextElements: defaultRichTextElements as\n | Record<string, unknown>\n | undefined,\n onError: onError as ((error: Error) => void) | undefined,\n }),\n [locale, defaultRichTextElements, onError]\n );\n\n if (\n process.env.NODE_ENV === 'development' &&\n typeof _messages !== 'undefined'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('IntlProvider', CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reasons.`\n );\n }\n\n return (\n <IntlContext.Provider value={intlObject}>\n <IntlayerProvider locale={locale as LocalesValues} {...(rest as object)}>\n {children}\n </IntlayerProvider>\n </IntlContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,gBAAsC,EACjD,QACA,UACA,UAAU,WACV,SAAS,UACT,UAAU,WACV,yBACA,SACA,GAAG,WACC;CACJ,MAAM,aAAa,cAEf,iBAAiB,QAAyB,QAAW;EAC1B;EAGhB;CACX,CAAC,GACH;EAAC;EAAQ;EAAyB;CAAO,CAC3C;CAEA,6BAC2B,iBACzB,OAAO,cAAc,aAGrB,AADkB,aAAa,EAAE,IAAI,CAC7B,CAAC,CACP,GAAG,SAAS,gBAAgB,IAAI,EAAE,gIACpC;CAGF,OACE,oBAAC,YAAY,UAAb;EAAsB,OAAO;YAC3B,oBAAC,kBAAD;GAA0B;GAAyB,GAAK;GACrD;EACe;CACE;AAE1B"}
@@ -27,9 +27,9 @@ const createIntlCache = () => ({
27
27
  * for the given `locale`. Use this in non-React contexts (e.g. server-side
28
28
  * route handlers).
29
29
  *
30
- * `messages`, `formats`, `timeZone`, `onError`, and `cache` are accepted for
31
- * API compatibility but have no effect — Intlayer uses its own compiled
32
- * dictionaries.
30
+ * `defaultRichTextElements` and `onError` apply to every message. `messages`,
31
+ * `formats`, `timeZone` and `cache` are accepted for API compatibility only —
32
+ * Intlayer uses its own compiled dictionaries.
33
33
  *
34
34
  * @example
35
35
  * ```ts
@@ -37,7 +37,10 @@ const createIntlCache = () => ({
37
37
  * intl.formatMessage({ id: 'home.title' });
38
38
  * ```
39
39
  */
40
- const createIntl = ({ locale }, _cache) => createIntlObject(locale);
40
+ const createIntl = ({ locale, defaultRichTextElements, onError }, _cache) => createIntlObject(locale, void 0, {
41
+ defaultRichTextElements,
42
+ onError
43
+ });
41
44
 
42
45
  export { createIntl, createIntlCache };
43
46
  //# sourceMappingURL=createIntl.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"createIntl.mjs","names":[],"sources":["../../src/createIntl.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type {\n createIntl as _createIntl,\n createIntlCache as _createIntlCache,\n IntlCache,\n IntlConfig,\n IntlShape,\n} from 'react-intl';\nimport { createIntlObject } from './createIntlObject';\n\n/**\n * Drop-in for react-intl's `createIntlCache`.\n *\n * Returns an empty cache token. In the intlayer compat adapter, formatter\n * instances are not pooled (all backed by native `Intl.*` constructors), so\n * the cache object serves only as an API-compatibility token.\n *\n * @deprecated\n * Has no practical effect with intlayer — no formatter pooling is needed.\n */\nexport const createIntlCache: typeof _createIntlCache = (): IntlCache =>\n ({\n dateTime: {},\n number: {},\n message: {},\n relativeTime: {},\n pluralRules: {},\n list: {},\n displayNames: {},\n }) as IntlCache;\n\n/**\n * Drop-in for react-intl's `createIntl`.\n *\n * Creates an `IntlShape` instance backed by intlayer compiled dictionaries\n * for the given `locale`. Use this in non-React contexts (e.g. server-side\n * route handlers).\n *\n * `messages`, `formats`, `timeZone`, `onError`, and `cache` are accepted for\n * API compatibility but have no effect — Intlayer uses its own compiled\n * dictionaries.\n *\n * @example\n * ```ts\n * const intl = createIntl({ locale: 'en' });\n * intl.formatMessage({ id: 'home.title' });\n * ```\n */\nexport const createIntl: typeof _createIntl = (\n { locale }: IntlConfig,\n _cache?: IntlCache\n): IntlShape => createIntlObject(locale as LocalesValues);\n"],"mappings":";;;;;;;;;;;;;AAoBA,MAAa,yBACV;CACC,UAAU,CAAC;CACX,QAAQ,CAAC;CACT,SAAS,CAAC;CACV,cAAc,CAAC;CACf,aAAa,CAAC;CACd,MAAM,CAAC;CACP,cAAc,CAAC;AACjB;;;;;;;;;;;;;;;;;;AAmBF,MAAa,cACX,EAAE,UACF,WACc,iBAAiB,MAAuB"}
1
+ {"version":3,"file":"createIntl.mjs","names":[],"sources":["../../src/createIntl.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type {\n createIntl as _createIntl,\n createIntlCache as _createIntlCache,\n IntlCache,\n IntlConfig,\n IntlShape,\n} from 'react-intl';\nimport { createIntlObject } from './createIntlObject';\n\n/**\n * Drop-in for react-intl's `createIntlCache`.\n *\n * Returns an empty cache token. In the intlayer compat adapter, formatter\n * instances are not pooled (all backed by native `Intl.*` constructors), so\n * the cache object serves only as an API-compatibility token.\n *\n * @deprecated\n * Has no practical effect with intlayer — no formatter pooling is needed.\n */\nexport const createIntlCache: typeof _createIntlCache = (): IntlCache =>\n ({\n dateTime: {},\n number: {},\n message: {},\n relativeTime: {},\n pluralRules: {},\n list: {},\n displayNames: {},\n }) as IntlCache;\n\n/**\n * Drop-in for react-intl's `createIntl`.\n *\n * Creates an `IntlShape` instance backed by intlayer compiled dictionaries\n * for the given `locale`. Use this in non-React contexts (e.g. server-side\n * route handlers).\n *\n * `defaultRichTextElements` and `onError` apply to every message. `messages`,\n * `formats`, `timeZone` and `cache` are accepted for API compatibility only —\n * Intlayer uses its own compiled dictionaries.\n *\n * @example\n * ```ts\n * const intl = createIntl({ locale: 'en' });\n * intl.formatMessage({ id: 'home.title' });\n * ```\n */\nexport const createIntl: typeof _createIntl = (\n { locale, defaultRichTextElements, onError }: IntlConfig,\n _cache?: IntlCache\n): IntlShape =>\n createIntlObject(locale as LocalesValues, undefined, {\n defaultRichTextElements: defaultRichTextElements as\n | Record<string, unknown>\n | undefined,\n onError: onError as ((error: Error) => void) | undefined,\n });\n"],"mappings":";;;;;;;;;;;;;AAoBA,MAAa,yBACV;CACC,UAAU,CAAC;CACX,QAAQ,CAAC;CACT,SAAS,CAAC;CACV,cAAc,CAAC;CACf,aAAa,CAAC;CACd,MAAM,CAAC;CACP,cAAc,CAAC;AACjB;;;;;;;;;;;;;;;;;;AAmBF,MAAa,cACX,EAAE,QAAQ,yBAAyB,WACnC,WAEA,iBAAiB,QAAyB,QAAW;CAC1B;CAGhB;AACX,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { UnsupportedFormatterError, defaultErrorHandler } from "./errors.mjs";
1
2
  import { getIntlayer } from "@intlayer/core/interpreter";
2
3
  import { createMessageResolver, icuToIntlayerFormatter, navigatePath, parseTaggedMessage } from "@intlayer/core/messageFormat";
3
4
  import { Fragment } from "react";
@@ -66,14 +67,18 @@ const isRichValues = (values) => Object.values(values).some((value) => typeof va
66
67
  * @param lookupOverride - Optional message lookup replacing the registry-based
67
68
  * id resolution; used by the dictionary-bound `useDictionary` variant.
68
69
  */
69
- const createIntlObject = (locale, lookupOverride) => {
70
+ const createIntlObject = (locale, lookupOverride, { defaultRichTextElements, onError = defaultErrorHandler } = {}) => {
70
71
  const localeString = locale;
71
72
  const formatMessage = (descriptor, values) => {
72
73
  const { id = "", defaultMessage } = descriptor;
74
+ const mergedValues = defaultRichTextElements ? {
75
+ ...defaultRichTextElements,
76
+ ...values
77
+ } : values;
73
78
  const rawValue = lookupOverride ? lookupOverride(id) : lookupMessage(id, locale);
74
79
  const messageTemplate = rawValue !== void 0 && rawValue !== null ? rawValue : typeof defaultMessage === "string" ? defaultMessage : id;
75
- if (!values || !isRichValues(values)) return resolveMessage(messageTemplate, values ?? {}, locale) ?? id;
76
- const { scalarValues, renderers } = splitRichValues(values);
80
+ if (!mergedValues || !isRichValues(mergedValues)) return resolveMessage(messageTemplate, mergedValues ?? {}, locale) ?? id;
81
+ const { scalarValues, renderers } = splitRichValues(mergedValues);
77
82
  const message = resolveMessage(messageTemplate, scalarValues, locale) ?? id;
78
83
  return renderRichTokens(parseTaggedMessage(message), renderers);
79
84
  };
@@ -100,6 +105,32 @@ const createIntlObject = (locale, lookupOverride) => {
100
105
  const formatDateTimeRange = (from, to, options) => new Intl.DateTimeFormat(localeString, options).formatRange(toDate(from), toDate(to));
101
106
  const formatDateToParts = (value, options) => new Intl.DateTimeFormat(localeString, options).formatToParts(typeof value === "string" ? new Date(value) : value);
102
107
  const formatNumberToParts = (value, options) => new Intl.NumberFormat(localeString, options).formatToParts(value);
108
+ /** The `Intl.DurationFormat` for `options`, or `undefined` where it is missing. */
109
+ const getDurationFormat = (options) => {
110
+ const DurationFormatConstructor = Intl.DurationFormat;
111
+ if (!DurationFormatConstructor) {
112
+ onError(new UnsupportedFormatterError("Intl.DurationFormat is not available in this environment.\nTry polyfilling it using \"@formatjs/intl-durationformat\""));
113
+ return;
114
+ }
115
+ const { format: _namedFormat, ...durationOptions } = options ?? {};
116
+ return new DurationFormatConstructor(localeString, durationOptions);
117
+ };
118
+ const formatDuration = (value, options) => {
119
+ try {
120
+ return getDurationFormat(options)?.format(value) ?? "";
121
+ } catch (error) {
122
+ onError(error);
123
+ return "";
124
+ }
125
+ };
126
+ const formatDurationToParts = (value, options) => {
127
+ try {
128
+ return getDurationFormat(options)?.formatToParts(value) ?? [];
129
+ } catch (error) {
130
+ onError(error);
131
+ return [];
132
+ }
133
+ };
103
134
  return {
104
135
  locale: localeString,
105
136
  defaultLocale: localeString,
@@ -110,7 +141,8 @@ const createIntlObject = (locale, lookupOverride) => {
110
141
  textComponent: Fragment,
111
142
  wrapRichTextChunksInFragment: false,
112
143
  fallbackOnEmptyString: true,
113
- onError: () => {},
144
+ defaultRichTextElements,
145
+ onError,
114
146
  onWarn: () => {},
115
147
  formatters: {},
116
148
  formatMessage,
@@ -126,7 +158,9 @@ const createIntlObject = (locale, lookupOverride) => {
126
158
  formatDateTimeRange,
127
159
  formatDateToParts,
128
160
  formatTimeToParts: formatDateToParts,
129
- formatNumberToParts
161
+ formatNumberToParts,
162
+ formatDuration,
163
+ formatDurationToParts
130
164
  };
131
165
  };
132
166
 
@@ -1 +1 @@
1
- {"version":3,"file":"createIntlObject.mjs","names":[],"sources":["../../src/createIntlObject.tsx"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n createMessageResolver,\n icuToIntlayerFormatter,\n type MessageValues,\n navigatePath,\n parseTaggedMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { Fragment, type ReactNode } from 'react';\nimport type { IntlShape, MessageDescriptor } from 'react-intl';\n\n/**\n * ICU-bound `resolveMessage`.\n *\n * Binding the converter here, instead of selecting it by dialect at runtime,\n * leaves the other message-format parsers unreferenced so they tree-shake out\n * of the app bundle.\n */\nconst resolveMessage = createMessageResolver(icuToIntlayerFormatter);\n\ntype RichRenderer = (chunks: ReactNode) => ReactNode;\n\n/** Splits a full dotted id into the dictionary key and remaining path. */\nconst splitId = (id: string): { dictionaryKey: string; path: string } => {\n const dotIndex = id.indexOf('.');\n if (dotIndex === -1) return { dictionaryKey: id, path: '' };\n return {\n dictionaryKey: id.slice(0, dotIndex),\n path: id.slice(dotIndex + 1),\n };\n};\n\n/** Looks up a message value by full dotted id; first segment = dictionary key. */\nconst lookupMessage = (id: string, locale: LocalesValues): unknown => {\n const { dictionaryKey, path } = splitId(id);\n if (!dictionaryKey) return undefined;\n try {\n const dictionary = getIntlayer(dictionaryKey as DictionaryKeys, locale);\n return navigatePath(dictionary, path);\n } catch {\n return undefined;\n }\n};\n\n/** Maps tagged tokens to React nodes using the provided renderer functions. */\nconst renderRichTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): ReactNode[] =>\n tokens.map((token, tokenIndex) => {\n if (typeof token === 'string') return token;\n const children = renderRichTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n if (typeof renderer === 'function') {\n return (\n <Fragment key={tokenIndex}>\n {(renderer as RichRenderer)(<>{children}</>)}\n </Fragment>\n );\n }\n return <Fragment key={tokenIndex}>{children}</Fragment>;\n });\n\n/** Partitions values into scalar interpolation params and tag renderers. */\nconst splitRichValues = (\n values: Record<string, unknown>\n): { scalarValues: MessageValues; renderers: Record<string, unknown> } => {\n const scalarValues: MessageValues = {};\n const renderers: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(values)) {\n if (typeof value === 'function') renderers[key] = value;\n else scalarValues[key] = value as MessageValues[string];\n }\n return { scalarValues, renderers };\n};\n\nconst isRichValues = (values: Record<string, unknown>): boolean =>\n Object.values(values).some((value) => typeof value === 'function');\n\n/**\n * Builds an intlayer-backed `IntlShape` object for the given locale.\n *\n * - Translation ids use the first dot-path segment as the dictionary key.\n * - Full ICU MessageFormat syntax is supported via `@intlayer/core/messageFormat`.\n * - Rich text tags (`<b>chunks</b>`) are resolved through render functions in `values`.\n *\n * @param locale - The locale messages are resolved for.\n * @param lookupOverride - Optional message lookup replacing the registry-based\n * id resolution; used by the dictionary-bound `useDictionary` variant.\n */\nexport const createIntlObject = (\n locale: LocalesValues,\n lookupOverride?: (id: string) => unknown\n): IntlShape => {\n const localeString = locale as string;\n\n const formatMessage = (\n descriptor: MessageDescriptor,\n values?: Record<string, unknown>\n ): string | ReactNode[] => {\n const { id = '', defaultMessage } = descriptor;\n const rawValue = lookupOverride\n ? lookupOverride(id)\n : lookupMessage(id, locale);\n const messageTemplate =\n rawValue !== undefined && rawValue !== null\n ? (rawValue as string)\n : typeof defaultMessage === 'string'\n ? defaultMessage\n : id;\n\n if (!values || !isRichValues(values)) {\n return (\n resolveMessage(\n messageTemplate,\n (values ?? {}) as MessageValues,\n locale\n ) ?? id\n );\n }\n\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveMessage(messageTemplate, scalarValues, locale) ?? id;\n return renderRichTokens(parseTaggedMessage(message), renderers);\n };\n\n const toDate = (value: Date | number | string): Date =>\n value instanceof Date ? value : new Date(value);\n\n const formatDate = (\n value: string | number | Date | undefined,\n options?: Intl.DateTimeFormatOptions\n ): string => {\n if (value === undefined || value === null) return '';\n return new Intl.DateTimeFormat(localeString, options).format(toDate(value));\n };\n\n const formatNumber = (\n value: number | bigint,\n options?: Intl.NumberFormatOptions\n ): string => new Intl.NumberFormat(localeString, options).format(value);\n\n const formatPlural = (\n value: number,\n options?: Intl.PluralRulesOptions\n ): Intl.LDMLPluralRule =>\n new Intl.PluralRules(localeString, options).select(value);\n\n const formatList = (\n list: Iterable<unknown> | readonly unknown[],\n options?: Intl.ListFormatOptions\n ): string => {\n const strings = Array.from(list).filter(\n (item): item is string => typeof item === 'string'\n );\n return new Intl.ListFormat(localeString, options).format(strings);\n };\n\n const formatListToParts = (\n list: Iterable<unknown> | readonly unknown[],\n options?: Intl.ListFormatOptions\n ): ReturnType<Intl.ListFormat['formatToParts']> => {\n const strings = Array.from(list).filter(\n (item): item is string => typeof item === 'string'\n );\n return new Intl.ListFormat(localeString, options).formatToParts(strings);\n };\n\n const formatDisplayName = (\n value: string,\n options?: Intl.DisplayNamesOptions\n ): string | undefined =>\n new Intl.DisplayNames([localeString], options ?? { type: 'language' }).of(\n value\n );\n\n const formatRelativeTime = (\n value: number,\n unit?: Intl.RelativeTimeFormatUnit,\n options?: Intl.RelativeTimeFormatOptions\n ): string =>\n new Intl.RelativeTimeFormat(localeString, {\n numeric: 'auto',\n ...options,\n }).format(value, unit ?? 'second');\n\n const formatDateTimeRange = (\n from: Date | number,\n to: Date | number,\n options?: Intl.DateTimeFormatOptions\n ): string =>\n new Intl.DateTimeFormat(localeString, options).formatRange(\n toDate(from),\n toDate(to)\n );\n\n const formatDateToParts = (\n value: Parameters<Intl.DateTimeFormat['format']>[0] | string,\n options?: Intl.DateTimeFormatOptions\n ): Intl.DateTimeFormatPart[] =>\n new Intl.DateTimeFormat(localeString, options).formatToParts(\n typeof value === 'string' ? new Date(value) : value\n );\n\n const formatNumberToParts = (\n value: number | bigint,\n options?: Intl.NumberFormatOptions\n ): Intl.NumberFormatPart[] =>\n new Intl.NumberFormat(localeString, options).formatToParts(value);\n\n /** Alias of `formatMessage` — provided for `@formatjs/intl` v4 compatibility. */\n const $t = formatMessage as IntlShape['$t'];\n\n return {\n locale: localeString,\n defaultLocale: localeString,\n messages: {},\n formats: {},\n defaultFormats: {},\n timeZone: undefined,\n textComponent: Fragment,\n wrapRichTextChunksInFragment: false,\n fallbackOnEmptyString: true,\n onError: () => {},\n onWarn: () => {},\n formatters: {} as IntlShape['formatters'],\n formatMessage: formatMessage as IntlShape['formatMessage'],\n $t,\n formatDate,\n formatTime: formatDate,\n formatNumber,\n formatPlural,\n formatList: formatList as IntlShape['formatList'],\n formatListToParts: formatListToParts as IntlShape['formatListToParts'],\n formatDisplayName: formatDisplayName as IntlShape['formatDisplayName'],\n formatRelativeTime,\n formatDateTimeRange,\n formatDateToParts: formatDateToParts as IntlShape['formatDateToParts'],\n formatTimeToParts: formatDateToParts as IntlShape['formatTimeToParts'],\n formatNumberToParts:\n formatNumberToParts as IntlShape['formatNumberToParts'],\n } as unknown as IntlShape;\n};\n"],"mappings":";;;;;;;;;;;;;AAuBA,MAAM,iBAAiB,sBAAsB,sBAAsB;;AAKnE,MAAM,WAAW,OAAwD;CACvE,MAAM,WAAW,GAAG,QAAQ,GAAG;CAC/B,IAAI,aAAa,IAAI,OAAO;EAAE,eAAe;EAAI,MAAM;CAAG;CAC1D,OAAO;EACL,eAAe,GAAG,MAAM,GAAG,QAAQ;EACnC,MAAM,GAAG,MAAM,WAAW,CAAC;CAC7B;AACF;;AAGA,MAA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,OAAO,EAAE,CACX;CAEF,MAAM,qBACJ,OACA,YAEA,IAAI,KAAK,eAAe,cAAc,OAAO,CAAC,CAAC,cAC7C,OAAO,UAAU,WAAW,IAAI,KAAK,KAAK,IAAI,KAChD;CAEF,MAAM,uBACJ,OACA,YAEA,IAAI,KAAK,aAAa,cAAc,OAAO,CAAC,CAAC,cAAc,KAAK;CAKlE,OAAO;EACL,QAAQ;EACR,eAAe;EACf,UAAU,CAAC;EACX,SAAS,CAAC;EACV,gBAAgB,CAAC;EACjB,UAAU;EACV,eAAe;EACf,8BAA8B;EAC9B,uBAAuB;EACvB,eAAe,CAAC;EAChB,cAAc,CAAC;EACf,YAAY,CAAC;EACE;EACf;EACA;EACA,YAAY;EACZ;EACA;EACY;EACO;EACA;EACnB;EACA;EACmB;EACnB,mBAAmB;EAEjB;CACJ;AACF"}
1
+ {"version":3,"file":"createIntlObject.mjs","names":[],"sources":["../../src/createIntlObject.tsx"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n createMessageResolver,\n icuToIntlayerFormatter,\n type MessageValues,\n navigatePath,\n parseTaggedMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { Fragment, type ReactNode } from 'react';\nimport type { IntlShape, MessageDescriptor } from 'react-intl';\nimport { defaultErrorHandler, UnsupportedFormatterError } from './errors';\n\n/**\n * ICU-bound `resolveMessage`.\n *\n * Binding the converter here, instead of selecting it by dialect at runtime,\n * leaves the other message-format parsers unreferenced so they tree-shake out\n * of the app bundle.\n */\nconst resolveMessage = createMessageResolver(icuToIntlayerFormatter);\n\ntype RichRenderer = (chunks: ReactNode) => ReactNode;\n\n/** Splits a full dotted id into the dictionary key and remaining path. */\nconst splitId = (id: string): { dictionaryKey: string; path: string } => {\n const dotIndex = id.indexOf('.');\n if (dotIndex === -1) return { dictionaryKey: id, path: '' };\n return {\n dictionaryKey: id.slice(0, dotIndex),\n path: id.slice(dotIndex + 1),\n };\n};\n\n/** Looks up a message value by full dotted id; first segment = dictionary key. */\nconst lookupMessage = (id: string, locale: LocalesValues): unknown => {\n const { dictionaryKey, path } = splitId(id);\n if (!dictionaryKey) return undefined;\n try {\n const dictionary = getIntlayer(dictionaryKey as DictionaryKeys, locale);\n return navigatePath(dictionary, path);\n } catch {\n return undefined;\n }\n};\n\n/** Maps tagged tokens to React nodes using the provided renderer functions. */\nconst renderRichTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): ReactNode[] =>\n tokens.map((token, tokenIndex) => {\n if (typeof token === 'string') return token;\n const children = renderRichTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n if (typeof renderer === 'function') {\n return (\n <Fragment key={tokenIndex}>\n {(renderer as RichRenderer)(<>{children}</>)}\n </Fragment>\n );\n }\n return <Fragment key={tokenIndex}>{children}</Fragment>;\n });\n\n/** Partitions values into scalar interpolation params and tag renderers. */\nconst splitRichValues = (\n values: Record<string, unknown>\n): { scalarValues: MessageValues; renderers: Record<string, unknown> } => {\n const scalarValues: MessageValues = {};\n const renderers: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(values)) {\n if (typeof value === 'function') renderers[key] = value;\n else scalarValues[key] = value as MessageValues[string];\n }\n return { scalarValues, renderers };\n};\n\nconst isRichValues = (values: Record<string, unknown>): boolean =>\n Object.values(values).some((value) => typeof value === 'function');\n\n/** A duration, as `Intl.DurationFormat` takes it (`{ hours: 1, minutes: 30 }`). */\ntype DurationInput = Partial<\n Record<\n | 'years'\n | 'months'\n | 'weeks'\n | 'days'\n | 'hours'\n | 'minutes'\n | 'seconds'\n | 'milliseconds'\n | 'microseconds'\n | 'nanoseconds',\n number\n >\n>;\n\n/** `Intl.DurationFormat` options, plus react-intl's named `format`. */\ntype DurationFormatOptions = Record<string, unknown> & { format?: string };\n\ntype DurationFormatPart = { type: string; value: string; unit?: string };\n\n/** `Intl.DurationFormat`, not yet in every TypeScript `lib`. */\ntype DurationFormat = {\n format: (duration: DurationInput) => string;\n formatToParts: (duration: DurationInput) => DurationFormatPart[];\n};\n\ntype DurationFormatConstructor = new (\n locale: string,\n options?: Record<string, unknown>\n) => DurationFormat;\n\n/** Provider settings the intl object honours. */\nexport type IntlObjectOptions = {\n /** Tag renderers applied to every rich message, under the call's values. */\n defaultRichTextElements?: Record<string, unknown>;\n /** Receives formatting errors (default: logged outside production). */\n onError?: (error: Error) => void;\n};\n\n/**\n * Builds an intlayer-backed `IntlShape` object for the given locale.\n *\n * - Translation ids use the first dot-path segment as the dictionary key.\n * - Full ICU MessageFormat syntax is supported via `@intlayer/core/messageFormat`.\n * - Rich text tags (`<b>chunks</b>`) are resolved through render functions in `values`.\n *\n * @param locale - The locale messages are resolved for.\n * @param lookupOverride - Optional message lookup replacing the registry-based\n * id resolution; used by the dictionary-bound `useDictionary` variant.\n */\nexport const createIntlObject = (\n locale: LocalesValues,\n lookupOverride?: (id: string) => unknown,\n {\n defaultRichTextElements,\n onError = defaultErrorHandler,\n }: IntlObjectOptions = {}\n): IntlShape => {\n const localeString = locale as string;\n\n const formatMessage = (\n descriptor: MessageDescriptor,\n values?: Record<string, unknown>\n ): string | ReactNode[] => {\n const { id = '', defaultMessage } = descriptor;\n // Default tag renderers sit under the call's values, as upstream.\n const mergedValues = defaultRichTextElements\n ? { ...defaultRichTextElements, ...values }\n : values;\n const rawValue = lookupOverride\n ? lookupOverride(id)\n : lookupMessage(id, locale);\n const messageTemplate =\n rawValue !== undefined && rawValue !== null\n ? (rawValue as string)\n : typeof defaultMessage === 'string'\n ? defaultMessage\n : id;\n\n if (!mergedValues || !isRichValues(mergedValues)) {\n return (\n resolveMessage(\n messageTemplate,\n (mergedValues ?? {}) as MessageValues,\n locale\n ) ?? id\n );\n }\n\n const { scalarValues, renderers } = splitRichValues(mergedValues);\n const message = resolveMessage(messageTemplate, scalarValues, locale) ?? id;\n return renderRichTokens(parseTaggedMessage(message), renderers);\n };\n\n const toDate = (value: Date | number | string): Date =>\n value instanceof Date ? value : new Date(value);\n\n const formatDate = (\n value: string | number | Date | undefined,\n options?: Intl.DateTimeFormatOptions\n ): string => {\n if (value === undefined || value === null) return '';\n return new Intl.DateTimeFormat(localeString, options).format(toDate(value));\n };\n\n const formatNumber = (\n value: number | bigint,\n options?: Intl.NumberFormatOptions\n ): string => new Intl.NumberFormat(localeString, options).format(value);\n\n const formatPlural = (\n value: number,\n options?: Intl.PluralRulesOptions\n ): Intl.LDMLPluralRule =>\n new Intl.PluralRules(localeString, options).select(value);\n\n const formatList = (\n list: Iterable<unknown> | readonly unknown[],\n options?: Intl.ListFormatOptions\n ): string => {\n const strings = Array.from(list).filter(\n (item): item is string => typeof item === 'string'\n );\n return new Intl.ListFormat(localeString, options).format(strings);\n };\n\n const formatListToParts = (\n list: Iterable<unknown> | readonly unknown[],\n options?: Intl.ListFormatOptions\n ): ReturnType<Intl.ListFormat['formatToParts']> => {\n const strings = Array.from(list).filter(\n (item): item is string => typeof item === 'string'\n );\n return new Intl.ListFormat(localeString, options).formatToParts(strings);\n };\n\n const formatDisplayName = (\n value: string,\n options?: Intl.DisplayNamesOptions\n ): string | undefined =>\n new Intl.DisplayNames([localeString], options ?? { type: 'language' }).of(\n value\n );\n\n const formatRelativeTime = (\n value: number,\n unit?: Intl.RelativeTimeFormatUnit,\n options?: Intl.RelativeTimeFormatOptions\n ): string =>\n new Intl.RelativeTimeFormat(localeString, {\n numeric: 'auto',\n ...options,\n }).format(value, unit ?? 'second');\n\n const formatDateTimeRange = (\n from: Date | number,\n to: Date | number,\n options?: Intl.DateTimeFormatOptions\n ): string =>\n new Intl.DateTimeFormat(localeString, options).formatRange(\n toDate(from),\n toDate(to)\n );\n\n const formatDateToParts = (\n value: Parameters<Intl.DateTimeFormat['format']>[0] | string,\n options?: Intl.DateTimeFormatOptions\n ): Intl.DateTimeFormatPart[] =>\n new Intl.DateTimeFormat(localeString, options).formatToParts(\n typeof value === 'string' ? new Date(value) : value\n );\n\n const formatNumberToParts = (\n value: number | bigint,\n options?: Intl.NumberFormatOptions\n ): Intl.NumberFormatPart[] =>\n new Intl.NumberFormat(localeString, options).formatToParts(value);\n\n /** The `Intl.DurationFormat` for `options`, or `undefined` where it is missing. */\n const getDurationFormat = (\n options?: DurationFormatOptions\n ): DurationFormat | undefined => {\n const DurationFormatConstructor = (\n Intl as unknown as { DurationFormat?: DurationFormatConstructor }\n ).DurationFormat;\n\n if (!DurationFormatConstructor) {\n onError(\n new UnsupportedFormatterError(\n 'Intl.DurationFormat is not available in this environment.\\nTry polyfilling it using \"@formatjs/intl-durationformat\"'\n )\n );\n return undefined;\n }\n\n const { format: _namedFormat, ...durationOptions } = options ?? {};\n return new DurationFormatConstructor(localeString, durationOptions);\n };\n\n const formatDuration = (\n value: DurationInput,\n options?: DurationFormatOptions\n ): string => {\n try {\n return getDurationFormat(options)?.format(value) ?? '';\n } catch (error) {\n onError(error as Error);\n return '';\n }\n };\n\n const formatDurationToParts = (\n value: DurationInput,\n options?: DurationFormatOptions\n ): DurationFormatPart[] => {\n try {\n return getDurationFormat(options)?.formatToParts(value) ?? [];\n } catch (error) {\n onError(error as Error);\n return [];\n }\n };\n\n /** Alias of `formatMessage` — provided for `@formatjs/intl` v4 compatibility. */\n const $t = formatMessage as IntlShape['$t'];\n\n return {\n locale: localeString,\n defaultLocale: localeString,\n messages: {},\n formats: {},\n defaultFormats: {},\n timeZone: undefined,\n textComponent: Fragment,\n wrapRichTextChunksInFragment: false,\n fallbackOnEmptyString: true,\n defaultRichTextElements,\n onError,\n onWarn: () => {},\n formatters: {} as IntlShape['formatters'],\n formatMessage: formatMessage as IntlShape['formatMessage'],\n $t,\n formatDate,\n formatTime: formatDate,\n formatNumber,\n formatPlural,\n formatList: formatList as IntlShape['formatList'],\n formatListToParts: formatListToParts as IntlShape['formatListToParts'],\n formatDisplayName: formatDisplayName as IntlShape['formatDisplayName'],\n formatRelativeTime,\n formatDateTimeRange,\n formatDateToParts: formatDateToParts as IntlShape['formatDateToParts'],\n formatTimeToParts: formatDateToParts as IntlShape['formatTimeToParts'],\n formatNumberToParts:\n formatNumberToParts as IntlShape['formatNumberToParts'],\n formatDuration,\n formatDurationToParts,\n } as unknown as IntlShape;\n};\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAM,iBAAiB,sBAAsB,sBAAsB;;AAKnE,MAAM,WAAW,OAAwD;CACvE,MAAM,WAAW,GAAG,QAAQ,GAAG;CAC/B,IAAI,aAAa,IAAI,OAAO;EAAE,eAAe;EAAI,MAAM;CAAG;CAC1D,OAAO;EACL,eAAe,GAAG,MAAM,GAAG,QAAQ;EACnC,MAAM,GAAG,MAAM,WAAW,CAAC;CAC7B;AACF;;AAGA,MAAM,iBAAiB,IAAY,WAAmC;CACpE,MAAM,EAAE,eAAe,SAAS,QAAQ,EAAE;CAC1C,IAAI,CAAC,eAAe,OAAO;CAC3B,IAAI;EACF,MAAM,aAAa,YAAY,eAAiC,MAAM;EACtE,OAAO,aAAa,YAAY,IAAI;CACtC,QAAQ;EACN;CACF;AACF;;AAGA,MAAM,oBACJ,QACA,cAEA,OAAO,KAAK,OAAO,eAAe;CAChC,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,MAAM,WAAW,iBAAiB,MAAM,UAAU,SAAS;CAC3D,MAAM,WAAW,UAAU,MAAM;CACjC,IAAI,OAAO,aAAa,YACtB,OACE,oBAAC,UAAD,YACI,SAA0B,kCAAG,SAAW,EAAC,EACnC,GAFK,UAEL;CAGd,OAAO,oBAAC,UAAD,EAA4B,SAAmB,GAAhC,UAAgC;AACxD,CAAC;;AAGH,MAAM,mBACJ,WACwE;CACxE,MAAM,eAA8B,CAAC;CACrC,MAAM,YAAqC,CAAC;CAC5C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAC9C,IAAI,OAAO,UAAU,YAAY,UAAU,OAAO;MAC7C,aAAa,OAAO;CAE3B,OAAO;EAAE;EAAc;CAAU;AACnC;AAEA,MAAM,gBAAgB,WACpB,O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c,KAAK,KAAK,CAAC;EAC9D,SAAS,OAAO;GACd,QAAQ,KAAc;GACtB,OAAO,CAAC;EACV;CACF;CAKA,OAAO;EACL,QAAQ;EACR,eAAe;EACf,UAAU,CAAC;EACX,SAAS,CAAC;EACV,gBAAgB,CAAC;EACjB,UAAU;EACV,eAAe;EACf,8BAA8B;EAC9B,uBAAuB;EACvB;EACA;EACA,cAAc,CAAC;EACf,YAAY,CAAC;EACE;EACf;EACA;EACA,YAAY;EACZ;EACA;EACY;EACO;EACA;EACnB;EACA;EACmB;EACnB,mBAAmB;EAEjB;EACF;EACA;CACF;AACF"}
@@ -1,76 +1,82 @@
1
1
  // src/errors.ts
2
2
  /**
3
- * Error code enum matching react-intl's `ReactIntlErrorCode`.
4
- *
5
- * @deprecated These error codes are not raised by the intlayer compat adapter.
6
- * Exported for API compatibility only.
3
+ * Error codes of react-intl's errors (`IntlErrorCode` of `@formatjs/intl`),
4
+ * typed as the upstream enum so codes compare across both.
7
5
  */
8
- let ReactIntlErrorCode = /* @__PURE__ */ function(ReactIntlErrorCode) {
9
- ReactIntlErrorCode["FORMAT_ERROR"] = "FORMAT_ERROR";
10
- ReactIntlErrorCode["UNSUPPORTED_FORMATTER"] = "UNSUPPORTED_FORMATTER";
11
- ReactIntlErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
12
- ReactIntlErrorCode["MISSING_DATA"] = "MISSING_DATA";
13
- ReactIntlErrorCode["MISSING_TRANSLATION"] = "MISSING_TRANSLATION";
14
- return ReactIntlErrorCode;
15
- }({});
6
+ const ReactIntlErrorCode = {
7
+ FORMAT_ERROR: "FORMAT_ERROR",
8
+ UNSUPPORTED_FORMATTER: "UNSUPPORTED_FORMATTER",
9
+ INVALID_CONFIG: "INVALID_CONFIG",
10
+ MISSING_DATA: "MISSING_DATA",
11
+ MISSING_TRANSLATION: "MISSING_TRANSLATION"
12
+ };
13
+ /** The cause appended to an error message, as an `Error`. */
14
+ const toError = (exception) => {
15
+ if (!exception) return void 0;
16
+ return exception instanceof Error ? exception : new Error(String(exception));
17
+ };
16
18
  /**
17
- * Base error class matching react-intl's `ReactIntlError` shape.
18
- *
19
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
19
+ * Base class of react-intl's errors: the message is prefixed with its code
20
+ * and followed by the cause's message and stack.
20
21
  */
21
- var ReactIntlError = class extends Error {
22
+ var ReactIntlError = class ReactIntlError extends Error {
22
23
  code;
23
- constructor(code, message) {
24
- super(message);
25
- this.name = "ReactIntlError";
24
+ constructor(code, message, exception) {
25
+ const cause = toError(exception);
26
+ super(`[@formatjs/intl Error ${code}] ${message}\n${cause ? `\n${cause.message}\n${cause.stack}` : ""}`);
26
27
  this.code = code;
28
+ if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(this, ReactIntlError);
27
29
  }
28
30
  };
29
- /**
30
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
31
- */
32
- var InvalidConfigError = class extends ReactIntlError {
33
- constructor(message) {
34
- super("INVALID_CONFIG", message);
35
- this.name = "InvalidConfigError";
31
+ /** A formatter is missing or not supported. */
32
+ var UnsupportedFormatterError = class extends ReactIntlError {
33
+ constructor(message, exception) {
34
+ super(ReactIntlErrorCode.UNSUPPORTED_FORMATTER, message, exception);
36
35
  }
37
36
  };
38
- /**
39
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
40
- */
41
- var MessageFormatError = class extends ReactIntlError {
42
- constructor(message) {
43
- super("FORMAT_ERROR", message);
44
- this.name = "MessageFormatError";
37
+ /** The intl configuration is invalid. */
38
+ var InvalidConfigError = class extends ReactIntlError {
39
+ constructor(message, exception) {
40
+ super(ReactIntlErrorCode.INVALID_CONFIG, message, exception);
45
41
  }
46
42
  };
47
- /**
48
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
49
- */
43
+ /** Locale data is missing. */
50
44
  var MissingDataError = class extends ReactIntlError {
51
- constructor(message) {
52
- super("MISSING_DATA", message);
53
- this.name = "MissingDataError";
45
+ constructor(message, exception) {
46
+ super(ReactIntlErrorCode.MISSING_DATA, message, exception);
54
47
  }
55
48
  };
56
- /**
57
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
58
- */
59
- var MissingTranslationError = class extends ReactIntlError {
60
- constructor(message) {
61
- super("MISSING_TRANSLATION", message);
62
- this.name = "MissingTranslationError";
49
+ /** A value could not be formatted for `locale`. */
50
+ var IntlFormatError = class extends ReactIntlError {
51
+ descriptor;
52
+ locale;
53
+ constructor(message, locale, exception) {
54
+ super(ReactIntlErrorCode.FORMAT_ERROR, `${message}\nLocale: ${locale}\n`, exception);
55
+ this.locale = locale;
63
56
  }
64
57
  };
65
- /**
66
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
67
- */
68
- var UnsupportedFormatterError = class extends ReactIntlError {
69
- constructor(message) {
70
- super("UNSUPPORTED_FORMATTER", message);
71
- this.name = "UnsupportedFormatterError";
58
+ /** A message could not be formatted. */
59
+ var MessageFormatError = class extends IntlFormatError {
60
+ constructor(message, locale, descriptor, exception) {
61
+ super(`${message}\nMessageID: ${descriptor?.id}\nDefault Message: ${descriptor?.defaultMessage}\nDescription: ${descriptor?.description}\n`, locale, exception);
62
+ this.descriptor = descriptor;
63
+ this.locale = locale;
72
64
  }
73
65
  };
66
+ /** The text of a default message, for the missing-translation warning. */
67
+ const describeDefaultMessage = (defaultMessage) => typeof defaultMessage === "string" ? defaultMessage : defaultMessage.map((element) => element.value ?? JSON.stringify(element)).join();
68
+ /** A message is missing for `locale`; its default message or id is used. */
69
+ var MissingTranslationError = class extends ReactIntlError {
70
+ descriptor;
71
+ constructor(descriptor, locale) {
72
+ super(ReactIntlErrorCode.MISSING_TRANSLATION, `Missing message: "${descriptor.id}" for locale "${locale}", using ${descriptor.defaultMessage ? `default message (${describeDefaultMessage(descriptor.defaultMessage)})` : "id"} as fallback.`);
73
+ this.descriptor = descriptor;
74
+ }
75
+ };
76
+ /** react-intl's default `onError`: logs outside production. */
77
+ const defaultErrorHandler = (error) => {
78
+ if (process.env.NODE_ENV !== "production") console.error(error);
79
+ };
74
80
 
75
- export { InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, ReactIntlError, ReactIntlErrorCode, UnsupportedFormatterError };
81
+ export { InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, ReactIntlError, ReactIntlErrorCode, UnsupportedFormatterError, defaultErrorHandler };
76
82
  //# sourceMappingURL=errors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","names":[],"sources":["../../src/errors.ts"],"sourcesContent":["/**\n * Error code enum matching react-intl's `ReactIntlErrorCode`.\n *\n * @deprecated These error codes are not raised by the intlayer compat adapter.\n * Exported for API compatibility only.\n */\nexport enum ReactIntlErrorCode {\n FORMAT_ERROR = 'FORMAT_ERROR',\n UNSUPPORTED_FORMATTER = 'UNSUPPORTED_FORMATTER',\n INVALID_CONFIG = 'INVALID_CONFIG',\n MISSING_DATA = 'MISSING_DATA',\n MISSING_TRANSLATION = 'MISSING_TRANSLATION',\n}\n\n/**\n * Base error class matching react-intl's `ReactIntlError` shape.\n *\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class ReactIntlError extends Error {\n public readonly code: ReactIntlErrorCode;\n\n constructor(code: ReactIntlErrorCode, message: string) {\n super(message);\n this.name = 'ReactIntlError';\n this.code = code;\n }\n}\n\n/**\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class InvalidConfigError extends ReactIntlError {\n constructor(message: string) {\n super(ReactIntlErrorCode.INVALID_CONFIG, message);\n this.name = 'InvalidConfigError';\n }\n}\n\n/**\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class MessageFormatError extends ReactIntlError {\n constructor(message: string) {\n super(ReactIntlErrorCode.FORMAT_ERROR, message);\n this.name = 'MessageFormatError';\n }\n}\n\n/**\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class MissingDataError extends ReactIntlError {\n constructor(message: string) {\n super(ReactIntlErrorCode.MISSING_DATA, message);\n this.name = 'MissingDataError';\n }\n}\n\n/**\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class MissingTranslationError extends ReactIntlError {\n constructor(message: string) {\n super(ReactIntlErrorCode.MISSING_TRANSLATION, message);\n this.name = 'MissingTranslationError';\n }\n}\n\n/**\n * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.\n */\nexport class UnsupportedFormatterError extends ReactIntlError {\n constructor(message: string) {\n super(ReactIntlErrorCode.UNSUPPORTED_FORMATTER, message);\n this.name = 'UnsupportedFormatterError';\n }\n}\n"],"mappings":";;;;;;;AAMA,IAAY,qBAAL;CACL;CACA;CACA;CACA;CACA;;AACF;;;;;;AAOA,IAAa,iBAAb,cAAoC,MAAM;CACxC,AAAgB;CAEhB,YAAY,MAA0B,SAAiB;EACrD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,qBAAb,cAAwC,eAAe;CACrD,YAAY,SAAiB;EAC3B,wBAAyC,OAAO;EAChD,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,qBAAb,cAAwC,eAAe;CACrD,YAAY,SAAiB;EAC3B,sBAAuC,OAAO;EAC9C,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,mBAAb,cAAsC,eAAe;CACnD,YAAY,SAAiB;EAC3B,sBAAuC,OAAO;EAC9C,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,0BAAb,cAA6C,eAAe;CAC1D,YAAY,SAAiB;EAC3B,6BAA8C,OAAO;EACrD,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,4BAAb,cAA+C,eAAe;CAC5D,YAAY,SAAiB;EAC3B,+BAAgD,OAAO;EACvD,KAAK,OAAO;CACd;AACF"}
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../src/errors.ts"],"sourcesContent":["import type {\n MessageDescriptor,\n ReactIntlErrorCode as UpstreamReactIntlErrorCode,\n} from 'react-intl';\n\n/**\n * Error codes of react-intl's errors (`IntlErrorCode` of `@formatjs/intl`),\n * typed as the upstream enum so codes compare across both.\n */\nexport const ReactIntlErrorCode = {\n FORMAT_ERROR: 'FORMAT_ERROR',\n UNSUPPORTED_FORMATTER: 'UNSUPPORTED_FORMATTER',\n INVALID_CONFIG: 'INVALID_CONFIG',\n MISSING_DATA: 'MISSING_DATA',\n MISSING_TRANSLATION: 'MISSING_TRANSLATION',\n} as unknown as typeof UpstreamReactIntlErrorCode;\n\nexport type ReactIntlErrorCode = UpstreamReactIntlErrorCode;\n\n/** The cause appended to an error message, as an `Error`. */\nconst toError = (exception: unknown): Error | undefined => {\n if (!exception) return undefined;\n return exception instanceof Error ? exception : new Error(String(exception));\n};\n\n/**\n * Base class of react-intl's errors: the message is prefixed with its code\n * and followed by the cause's message and stack.\n */\nexport class ReactIntlError<\n Code extends ReactIntlErrorCode = UpstreamReactIntlErrorCode.FORMAT_ERROR,\n> extends Error {\n public readonly code: Code;\n\n constructor(code: Code, message: string, exception?: Error | unknown) {\n const cause = toError(exception);\n super(\n `[@formatjs/intl Error ${code}] ${message}\\n${cause ? `\\n${cause.message}\\n${cause.stack}` : ''}`\n );\n this.code = code;\n if (typeof Error.captureStackTrace === 'function') {\n Error.captureStackTrace(this, ReactIntlError);\n }\n }\n}\n\n/** A formatter is missing or not supported. */\nexport class UnsupportedFormatterError extends ReactIntlError<UpstreamReactIntlErrorCode.UNSUPPORTED_FORMATTER> {\n constructor(message: string, exception?: Error | unknown) {\n super(ReactIntlErrorCode.UNSUPPORTED_FORMATTER, message, exception);\n }\n}\n\n/** The intl configuration is invalid. */\nexport class InvalidConfigError extends ReactIntlError<UpstreamReactIntlErrorCode.INVALID_CONFIG> {\n constructor(message: string, exception?: Error | unknown) {\n super(ReactIntlErrorCode.INVALID_CONFIG, message, exception);\n }\n}\n\n/** Locale data is missing. */\nexport class MissingDataError extends ReactIntlError<UpstreamReactIntlErrorCode.MISSING_DATA> {\n constructor(message: string, exception?: Error | unknown) {\n super(ReactIntlErrorCode.MISSING_DATA, message, exception);\n }\n}\n\n/** A value could not be formatted for `locale`. */\nclass IntlFormatError extends ReactIntlError<UpstreamReactIntlErrorCode.FORMAT_ERROR> {\n public readonly descriptor?: MessageDescriptor;\n public readonly locale: string;\n\n constructor(message: string, locale: string, exception?: Error | unknown) {\n super(\n ReactIntlErrorCode.FORMAT_ERROR,\n `${message}\\nLocale: ${locale}\\n`,\n exception\n );\n this.locale = locale;\n }\n}\n\n/** A message could not be formatted. */\nexport class MessageFormatError extends IntlFormatError {\n declare public readonly descriptor?: MessageDescriptor;\n declare public readonly locale: string;\n\n constructor(\n message: string,\n locale: string,\n descriptor?: MessageDescriptor,\n exception?: Error | unknown\n ) {\n super(\n `${message}\\nMessageID: ${descriptor?.id}\\nDefault Message: ${descriptor?.defaultMessage}\\nDescription: ${descriptor?.description}\\n`,\n locale,\n exception\n );\n this.descriptor = descriptor;\n this.locale = locale;\n }\n}\n\n/** The text of a default message, for the missing-translation warning. */\nconst describeDefaultMessage = (\n defaultMessage: MessageDescriptor['defaultMessage']\n): string =>\n typeof defaultMessage === 'string'\n ? defaultMessage\n : (defaultMessage as { value?: string }[])\n .map((element) => element.value ?? JSON.stringify(element))\n .join();\n\n/** A message is missing for `locale`; its default message or id is used. */\nexport class MissingTranslationError extends ReactIntlError<UpstreamReactIntlErrorCode.MISSING_TRANSLATION> {\n public readonly descriptor?: MessageDescriptor;\n\n constructor(descriptor: MessageDescriptor, locale: string) {\n super(\n ReactIntlErrorCode.MISSING_TRANSLATION,\n `Missing message: \"${descriptor.id}\" for locale \"${locale}\", using ${\n descriptor.defaultMessage\n ? `default message (${describeDefaultMessage(descriptor.defaultMessage)})`\n : 'id'\n } as fallback.`\n );\n this.descriptor = descriptor;\n }\n}\n\n/** react-intl's default `onError`: logs outside production. */\nexport const defaultErrorHandler = (error: Error): void => {\n if (process.env.NODE_ENV !== 'production') console.error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AClI,QACA,SACF;EACA,KAAK,aAAa;EAClB,KAAK,SAAS;CAChB;AACF;;AAGA,MAAM,0BACJ,mBAEA,OAAO,mBAAmB,WACtB,iBACC,eACE,KAAK,YAAY,QAAQ,SAAS,KAAK,UAAU,OAAO,CAAC,CAAC,CAC1D,KAAK;;AAGd,IAAa,0BAAb,cAA6C,eAA+D;CAC1G,AAAgB;CAEhB,YAAY,YAA+B,QAAgB;EACzD,MACE,mBAAmB,qBACnB,qBAAqB,WAAW,GAAG,gBAAgB,OAAO,WACxD,WAAW,iBACP,oBAAoB,uBAAuB,WAAW,cAAc,EAAE,KACtE,KACL,cACH;EACA,KAAK,aAAa;CACpB;AACF;;AAGA,MAAa,uBAAuB,UAAuB;CACzD,6BAA6B,cAAc,QAAQ,MAAM,KAAK;AAChE"}
@@ -4,11 +4,11 @@ import { IntlContext, RawIntlProvider } from "./context.mjs";
4
4
  import { createIntl, createIntlCache } from "./createIntl.mjs";
5
5
  import { defineMessage, defineMessages } from "./defineMessages.mjs";
6
6
  import { InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, ReactIntlError, ReactIntlErrorCode, UnsupportedFormatterError } from "./errors.mjs";
7
- import { FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedList, FormattedListParts, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts } from "./FormattedComponents.mjs";
7
+ import { FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedDuration, FormattedDurationParts, FormattedList, FormattedListParts, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts } from "./FormattedComponents.mjs";
8
8
  import { FormattedMessage } from "./FormattedMessage.mjs";
9
9
  import { IntlProvider } from "./IntlProvider.mjs";
10
10
  import { useDictionary } from "./useDictionary.mjs";
11
11
  import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
12
12
  import { useIntl } from "./useIntl.mjs";
13
13
 
14
- export { FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedList, FormattedListParts, FormattedMessage, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, IntlContext, IntlProvider, InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, RawIntlProvider, ReactIntlError, ReactIntlErrorCode, UnsupportedFormatterError, createIntl, createIntlCache, defineMessage, defineMessages, useDictionary, useDictionaryDynamic, useIntl };
14
+ export { FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedDuration, FormattedDurationParts, FormattedList, FormattedListParts, FormattedMessage, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, IntlContext, IntlProvider, InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, RawIntlProvider, ReactIntlError, ReactIntlErrorCode, UnsupportedFormatterError, createIntl, createIntlCache, defineMessage, defineMessages, useDictionary, useDictionaryDynamic, useIntl };
@@ -0,0 +1,4 @@
1
+ import { createIntl, createIntlCache } from "./createIntl.mjs";
2
+ import { defineMessage, defineMessages } from "./defineMessages.mjs";
3
+
4
+ export { createIntl, createIntlCache, defineMessage, defineMessages };
@@ -1,4 +1,4 @@
1
- import { FormattedDate as FormattedDate$1, FormattedDateParts as FormattedDateParts$1, FormattedDateTimeRange as FormattedDateTimeRange$1, FormattedDisplayName as FormattedDisplayName$1, FormattedList as FormattedList$1, FormattedListParts as FormattedListParts$1, FormattedNumber as FormattedNumber$1, FormattedNumberParts as FormattedNumberParts$1, FormattedPlural as FormattedPlural$1, FormattedRelativeTime as FormattedRelativeTime$1, FormattedTime as FormattedTime$1, FormattedTimeParts as FormattedTimeParts$1 } from "react-intl";
1
+ import { FormattedDate as FormattedDate$1, FormattedDateParts as FormattedDateParts$1, FormattedDateTimeRange as FormattedDateTimeRange$1, FormattedDisplayName as FormattedDisplayName$1, FormattedDuration as FormattedDuration$1, FormattedDurationParts as FormattedDurationParts$1, FormattedList as FormattedList$1, FormattedListParts as FormattedListParts$1, FormattedNumber as FormattedNumber$1, FormattedNumberParts as FormattedNumberParts$1, FormattedPlural as FormattedPlural$1, FormattedRelativeTime as FormattedRelativeTime$1, FormattedTime as FormattedTime$1, FormattedTimeParts as FormattedTimeParts$1 } from "react-intl";
2
2
  /**
3
3
  * Drop-in for react-intl's `<FormattedDate>`.
4
4
  * Renders a locale-aware date string using `Intl.DateTimeFormat`.
@@ -60,4 +60,14 @@ export declare const FormattedNumberParts: typeof FormattedNumberParts$1;
60
60
  * Renders list format parts via a `children` render-prop.
61
61
  */
62
62
  export declare const FormattedListParts: typeof FormattedListParts$1;
63
+ /**
64
+ * Drop-in for react-intl's `<FormattedDuration>`.
65
+ * Renders a locale-aware duration using `Intl.DurationFormat`.
66
+ */
67
+ export declare const FormattedDuration: typeof FormattedDuration$1;
68
+ /**
69
+ * Drop-in for react-intl's `<FormattedDurationParts>`.
70
+ * Renders duration format parts via a `children` render-prop.
71
+ */
72
+ export declare const FormattedDurationParts: typeof FormattedDurationParts$1;
63
73
  //# sourceMappingURL=FormattedComponents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormattedComponents.d.ts","names":["_FormattedDate","_FormattedTime","_FormattedNumber","_FormattedList","_FormattedDisplayName","_FormattedRelativeTime","_FormattedPlural","_FormattedDateTimeRange","_FormattedDateParts","_FormattedTimeParts","_FormattedNumberParts","_FormattedListParts"],"sources":["../../src/FormattedComponents.tsx"],"mappings":";;;;;qBA8Ba,sBAAsBA;;;;;qBAkBtB,sBAAsBC;;;;;qBAkBtB,wBAAwBC;;;;;qBAkBxB,sBAAsBC;;;;;qBAatB,6BAA6BC;;;;;;qBAiB7B,8BAA8BC;;;;;qBAmB9B,wBAAwBC;;;;;qBAmCxB,+BAA+BC;;;;;qBAkB/B,2BAA2BC;;;;;qBAkB3B,2BAA2BC;;;;;qBAkB3B,6BAA6BC;;;;;qBAe7B,2BAA2BC"}
1
+ {"version":3,"file":"FormattedComponents.d.ts","names":["_FormattedDate","_FormattedTime","_FormattedNumber","_FormattedList","_FormattedDisplayName","_FormattedRelativeTime","_FormattedPlural","_FormattedDateTimeRange","_FormattedDateParts","_FormattedTimeParts","_FormattedNumberParts","_FormattedListParts","_FormattedDuration","_FormattedDurationParts"],"sources":["../../src/FormattedComponents.tsx"],"mappings":";;;;;qBAgCa,sBAAsBA;;;;;qBAkBtB,sBAAsBC;;;;;qBAkBtB,wBAAwBC;;;;;qBAkBxB,sBAAsBC;;;;;qBAatB,6BAA6BC;;;;;;qBAiB7B,8BAA8BC;;;;;qBAmB9B,wBAAwBC;;;;;qBAmCxB,+BAA+BC;;;;;qBAkB/B,2BAA2BC;;;;;qBAkB3B,2BAA2BC;;;;;qBAkB3B,6BAA6BC;;;;;qBAe7B,2BAA2BC;;;;;qBAuB3B,0BAYWC;;;;;qBAMX,+BAUWC"}
@@ -1,24 +1,3 @@
1
1
  import { FormattedMessage as FormattedMessage$1 } from "react-intl";
2
- /**
3
- * Drop-in for react-intl's `<FormattedMessage>`.
4
- *
5
- * Translates the message identified by `id` using the active intl context.
6
- * Full ICU MessageFormat syntax is supported.
7
- *
8
- * When `values` contains render functions, rich text tags
9
- * (`<b>chunks</b>`) are mapped through them. When a `tagName` is provided,
10
- * the output is wrapped in that element; otherwise a fragment is used.
11
- * A `children` render-prop receives the resolved nodes.
12
- *
13
- * @example
14
- * ```tsx
15
- * <FormattedMessage id="home.title" />
16
- * <FormattedMessage id="home.greeting" values={{ name: 'Alice' }} />
17
- * <FormattedMessage
18
- * id="terms.agreement"
19
- * values={{ b: (chunks) => <strong>{chunks}</strong> }}
20
- * />
21
- * ```
22
- */
23
2
  export declare const FormattedMessage: typeof FormattedMessage$1;
24
3
  //# sourceMappingURL=FormattedMessage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormattedMessage.d.ts","names":["_FormattedMessage"],"sources":["../../src/FormattedMessage.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;qBAgCa,yBAAyBA"}
1
+ {"version":3,"file":"FormattedMessage.d.ts","names":["_FormattedMessage"],"sources":["../../src/FormattedMessage.tsx"],"mappings":";qBAoGa,yBACmCA"}
@@ -2,9 +2,9 @@ import { IntlProvider as IntlProvider$1 } from "react-intl";
2
2
  /**
3
3
  * Drop-in for react-intl's `IntlProvider`.
4
4
  *
5
- * `messages`, `formats`, `timeZone`, `now`, `defaultRichTextElements`,
6
- * and `onError`/`onWarn` are accepted for API compatibility but have no
7
- * effect — Intlayer uses its own compiled dictionaries.
5
+ * `defaultRichTextElements` and `onError` apply to every message. `messages`,
6
+ * `formats`, `timeZone`, `now` and `onWarn` are accepted for API
7
+ * compatibility only — Intlayer uses its own compiled dictionaries.
8
8
  *
9
9
  * The `locale` prop is forwarded to `IntlayerClientProvider`.
10
10
  */
@@ -17,9 +17,9 @@ export declare const createIntlCache: typeof createIntlCache$1;
17
17
  * for the given `locale`. Use this in non-React contexts (e.g. server-side
18
18
  * route handlers).
19
19
  *
20
- * `messages`, `formats`, `timeZone`, `onError`, and `cache` are accepted for
21
- * API compatibility but have no effect — Intlayer uses its own compiled
22
- * dictionaries.
20
+ * `defaultRichTextElements` and `onError` apply to every message. `messages`,
21
+ * `formats`, `timeZone` and `cache` are accepted for API compatibility only —
22
+ * Intlayer uses its own compiled dictionaries.
23
23
  *
24
24
  * @example
25
25
  * ```ts
@@ -1,5 +1,12 @@
1
1
  import { LocalesValues } from "@intlayer/types/module_augmentation";
2
2
  import { IntlShape } from "react-intl";
3
+ /** Provider settings the intl object honours. */
4
+ export type IntlObjectOptions = {
5
+ /** Tag renderers applied to every rich message, under the call's values. */
6
+ defaultRichTextElements?: Record<string, unknown>;
7
+ /** Receives formatting errors (default: logged outside production). */
8
+ onError?: (error: Error) => void;
9
+ };
3
10
  /**
4
11
  * Builds an intlayer-backed `IntlShape` object for the given locale.
5
12
  *
@@ -11,5 +18,5 @@ import { IntlShape } from "react-intl";
11
18
  * @param lookupOverride - Optional message lookup replacing the registry-based
12
19
  * id resolution; used by the dictionary-bound `useDictionary` variant.
13
20
  */
14
- export declare const createIntlObject: (locale: LocalesValues, lookupOverride?: (id: string) => unknown) => IntlShape;
21
+ export declare const createIntlObject: (locale: LocalesValues, lookupOverride?: (id: string) => unknown, { defaultRichTextElements, onError }?: IntlObjectOptions) => IntlShape;
15
22
  //# sourceMappingURL=createIntlObject.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createIntlObject.d.ts","names":[],"sources":["../../src/createIntlObject.tsx"],"mappings":";;;;;;;;;;;;;qBA+Fa,mBAAgB,QACnB,eAAa,kBACH,2BACjB"}
1
+ {"version":3,"file":"createIntlObject.d.ts","names":[],"sources":["../../src/createIntlObject.tsx"],"mappings":";;;YAuHY;;EAEV,0BAA0B;;EAE1B,WAAW,OAAO;;;;;;;;;;;;;qBAcP,mBAAgB,QACnB,eAAa,kBACH,0BAAsB,yBAAA,YAIrC,sBACF"}
@@ -1,53 +1,48 @@
1
+ import { MessageDescriptor, ReactIntlErrorCode as ReactIntlErrorCode$1 } from "react-intl";
1
2
  /**
2
- * Error code enum matching react-intl's `ReactIntlErrorCode`.
3
- *
4
- * @deprecated These error codes are not raised by the intlayer compat adapter.
5
- * Exported for API compatibility only.
3
+ * Error codes of react-intl's errors (`IntlErrorCode` of `@formatjs/intl`),
4
+ * typed as the upstream enum so codes compare across both.
6
5
  */
7
- export declare enum ReactIntlErrorCode {
8
- FORMAT_ERROR = "FORMAT_ERROR",
9
- UNSUPPORTED_FORMATTER = "UNSUPPORTED_FORMATTER",
10
- INVALID_CONFIG = "INVALID_CONFIG",
11
- MISSING_DATA = "MISSING_DATA",
12
- MISSING_TRANSLATION = "MISSING_TRANSLATION"
13
- }
6
+ export declare const ReactIntlErrorCode: typeof ReactIntlErrorCode$1;
7
+ export type ReactIntlErrorCode = ReactIntlErrorCode$1;
14
8
  /**
15
- * Base error class matching react-intl's `ReactIntlError` shape.
16
- *
17
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
9
+ * Base class of react-intl's errors: the message is prefixed with its code
10
+ * and followed by the cause's message and stack.
18
11
  */
19
- export declare class ReactIntlError extends Error {
20
- readonly code: ReactIntlErrorCode;
21
- constructor(code: ReactIntlErrorCode, message: string);
12
+ export declare class ReactIntlError<Code extends ReactIntlErrorCode = ReactIntlErrorCode$1.FORMAT_ERROR> extends Error {
13
+ readonly code: Code;
14
+ constructor(code: Code, message: string, exception?: Error | unknown);
22
15
  }
23
- /**
24
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
25
- */
26
- export declare class InvalidConfigError extends ReactIntlError {
27
- constructor(message: string);
16
+ /** A formatter is missing or not supported. */
17
+ export declare class UnsupportedFormatterError extends ReactIntlError<ReactIntlErrorCode$1.UNSUPPORTED_FORMATTER> {
18
+ constructor(message: string, exception?: Error | unknown);
28
19
  }
29
- /**
30
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
31
- */
32
- export declare class MessageFormatError extends ReactIntlError {
33
- constructor(message: string);
20
+ /** The intl configuration is invalid. */
21
+ export declare class InvalidConfigError extends ReactIntlError<ReactIntlErrorCode$1.INVALID_CONFIG> {
22
+ constructor(message: string, exception?: Error | unknown);
34
23
  }
35
- /**
36
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
37
- */
38
- export declare class MissingDataError extends ReactIntlError {
39
- constructor(message: string);
24
+ /** Locale data is missing. */
25
+ export declare class MissingDataError extends ReactIntlError<ReactIntlErrorCode$1.MISSING_DATA> {
26
+ constructor(message: string, exception?: Error | unknown);
40
27
  }
41
- /**
42
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
43
- */
44
- export declare class MissingTranslationError extends ReactIntlError {
45
- constructor(message: string);
28
+ /** A value could not be formatted for `locale`. */
29
+ declare class IntlFormatError extends ReactIntlError<ReactIntlErrorCode$1.FORMAT_ERROR> {
30
+ readonly descriptor?: MessageDescriptor;
31
+ readonly locale: string;
32
+ constructor(message: string, locale: string, exception?: Error | unknown);
46
33
  }
47
- /**
48
- * @deprecated Not raised by the intlayer compat adapter. Exported for API compatibility only.
49
- */
50
- export declare class UnsupportedFormatterError extends ReactIntlError {
51
- constructor(message: string);
34
+ /** A message could not be formatted. */
35
+ export declare class MessageFormatError extends IntlFormatError {
36
+ readonly descriptor?: MessageDescriptor;
37
+ readonly locale: string;
38
+ constructor(message: string, locale: string, descriptor?: MessageDescriptor, exception?: Error | unknown);
39
+ }
40
+ /** A message is missing for `locale`; its default message or id is used. */
41
+ export declare class MissingTranslationError extends ReactIntlError<ReactIntlErrorCode$1.MISSING_TRANSLATION> {
42
+ readonly descriptor?: MessageDescriptor;
43
+ constructor(descriptor: MessageDescriptor, locale: string);
52
44
  }
45
+ /** react-intl's default `onError`: logs outside production. */
46
+ export declare const defaultErrorHandler: (error: Error) => void;
47
+ export {};
53
48
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","names":[],"sources":["../../src/errors.ts"],"mappings":";;;;;;oBAMY;EACV;EACA;EACA;EACA;EACA;;;;;;;qBAQW,uBAAuB;WAClB,MAAM;EAEtB,YAAY,MAAM,oBAAoB;;;;;qBAU3B,2BAA2B;EACtC,YAAY;;;;;qBASD,2BAA2B;EACtC,YAAY;;;;;qBASD,yBAAyB;EACpC,YAAY;;;;;qBASD,gCAAgC;EAC3C,YAAY;;;;;qBASD,kCAAkC;EAC7C,YAAY"}
1
+ {"version":3,"file":"errors.d.ts","names":["UpstreamReactIntlErrorCode"],"sources":["../../src/errors.ts"],"mappings":";;;;;qBASa,2BAMUA;YAEX,qBAAqBA;;;;;qBAYpB,eACX,aAAa,qBAAqBA,qBAA2B,sBACrD;WACQ,MAAM;EAEtB,YAAY,MAAM,MAAM,iBAAiB,YAAY;;;qBAa1C,kCAAkC,eAAeA,qBAA2B;EACvF,YAAY,iBAAiB,YAAY;;;qBAM9B,2BAA2B,eAAeA,qBAA2B;EAChF,YAAY,iBAAiB,YAAY;;;qBAM9B,yBAAyB,eAAeA,qBAA2B;EAC9E,YAAY,iBAAiB,YAAY;;;cAMrC,wBAAwB,eAAeA,qBAA2B;WACtD,aAAa;WACb;EAEhB,YAAY,iBAAiB,gBAAgB,YAAY;;;qBAW9C,2BAA2B;WACd,aAAa;WACb;EAExB,YACE,iBACA,gBACA,aAAa,mBACb,YAAY;;;qBAuBH,gCAAgC,eAAeA,qBAA2B;WACrE,aAAa;EAE7B,YAAY,YAAY,mBAAmB;;;qBAchC,sBAAmB,OAAW"}
@@ -3,7 +3,7 @@ import { createIntl, createIntlCache } from "./createIntl.js";
3
3
  import { defineMessage, defineMessages } from "./defineMessages.js";
4
4
  import { DictionaryIntlShape, DictionaryMessageIds, MessageValueForId, TypedFormatMessage } from "./dictionaryIntlShape.js";
5
5
  import { InvalidConfigError, MessageFormatError, MissingDataError, MissingTranslationError, ReactIntlError, ReactIntlErrorCode, UnsupportedFormatterError } from "./errors.js";
6
- import { FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedList, FormattedListParts, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts } from "./FormattedComponents.js";
6
+ import { FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedDuration, FormattedDurationParts, FormattedList, FormattedListParts, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts } from "./FormattedComponents.js";
7
7
  import { FormattedMessage } from "./FormattedMessage.js";
8
8
  import { IntlProvider } from "./IntlProvider.js";
9
9
  import { RootMessageIds } from "./typedMessageIds.js";
@@ -11,4 +11,4 @@ import { useDictionary } from "./useDictionary.js";
11
11
  import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
12
12
  import { useIntl } from "./useIntl.js";
13
13
  import { CustomFormats, FormatDateOptions, FormatDisplayNameOptions, FormatListOptions, FormatNumberOptions, FormatPluralOptions, FormatRelativeTimeOptions, Formatters, IntlCache, IntlConfig, IntlFormatters, IntlShape, MessageDescriptor, MessageFormatElement, PrimitiveType, ResolvedIntlConfig } from "react-intl";
14
- export { type CustomFormats, type DictionaryIntlShape, type DictionaryMessageIds, type FormatDateOptions, type FormatDisplayNameOptions, type FormatListOptions, type FormatNumberOptions, type FormatPluralOptions, type FormatRelativeTimeOptions, FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedList, FormattedListParts, FormattedMessage, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, type Formatters, type IntlCache, type IntlConfig, IntlContext, type IntlFormatters, IntlProvider, type IntlShape, InvalidConfigError, type MessageDescriptor, type MessageFormatElement, MessageFormatError, type MessageValueForId, MissingDataError, MissingTranslationError, type PrimitiveType, RawIntlProvider, ReactIntlError, ReactIntlErrorCode, type ResolvedIntlConfig, type RootMessageIds, type TypedFormatMessage, UnsupportedFormatterError, createIntl, createIntlCache, defineMessage, defineMessages, useDictionary, useDictionaryDynamic, useIntl };
14
+ export { type CustomFormats, type DictionaryIntlShape, type DictionaryMessageIds, type FormatDateOptions, type FormatDisplayNameOptions, type FormatListOptions, type FormatNumberOptions, type FormatPluralOptions, type FormatRelativeTimeOptions, FormattedDate, FormattedDateParts, FormattedDateTimeRange, FormattedDisplayName, FormattedDuration, FormattedDurationParts, FormattedList, FormattedListParts, FormattedMessage, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, type Formatters, type IntlCache, type IntlConfig, IntlContext, type IntlFormatters, IntlProvider, type IntlShape, InvalidConfigError, type MessageDescriptor, type MessageFormatElement, MessageFormatError, type MessageValueForId, MissingDataError, MissingTranslationError, type PrimitiveType, RawIntlProvider, ReactIntlError, ReactIntlErrorCode, type ResolvedIntlConfig, type RootMessageIds, type TypedFormatMessage, UnsupportedFormatterError, createIntl, createIntlCache, defineMessage, defineMessages, useDictionary, useDictionaryDynamic, useIntl };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `react-intl/server`: the intl factory and message helpers, without client
3
+ * components, for React Server Components and server code.
4
+ */
5
+ import { createIntl, createIntlCache } from "./createIntl.js";
6
+ import { defineMessage, defineMessages } from "./defineMessages.js";
7
+ export { createIntl, createIntlCache, defineMessage, defineMessages };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/react-intl",
3
- "version": "9.9.3-canary.1",
3
+ "version": "9.9.4",
4
4
  "private": false,
5
5
  "description": "react-intl API adapter for intlayer — drop-in compatibility layer",
6
6
  "keywords": [
@@ -42,6 +42,9 @@
42
42
  "*": {
43
43
  "plugin": [
44
44
  "./dist/types/plugin/index.d.ts"
45
+ ],
46
+ "server": [
47
+ "./dist/types/server.d.ts"
45
48
  ]
46
49
  }
47
50
  },
@@ -50,6 +53,11 @@
50
53
  "types": "./dist/types/index.d.ts",
51
54
  "import": "./dist/esm/index.mjs"
52
55
  },
56
+ "./server": {
57
+ "types": "./dist/types/server.d.ts",
58
+ "require": "./dist/cjs/server.cjs",
59
+ "import": "./dist/esm/server.mjs"
60
+ },
53
61
  "./plugin": {
54
62
  "types": "./dist/types/plugin/index.d.ts",
55
63
  "import": "./dist/esm/plugin/index.mjs"
@@ -75,13 +83,13 @@
75
83
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
76
84
  },
77
85
  "dependencies": {
78
- "@intlayer/config": "9.9.3-canary.1",
79
- "@intlayer/core": "9.9.3-canary.1",
80
- "@intlayer/dictionaries-entry": "9.9.3-canary.1",
81
- "@intlayer/engine": "9.9.3-canary.1",
82
- "@intlayer/types": "9.9.3-canary.1",
83
- "react-intlayer": "9.9.3-canary.1",
84
- "vite-intlayer": "9.9.3-canary.1"
86
+ "@intlayer/config": "9.9.4",
87
+ "@intlayer/core": "9.9.4",
88
+ "@intlayer/dictionaries-entry": "9.9.4",
89
+ "@intlayer/engine": "9.9.4",
90
+ "@intlayer/types": "9.9.4",
91
+ "react-intlayer": "9.9.4",
92
+ "vite-intlayer": "9.9.4"
85
93
  },
86
94
  "devDependencies": {
87
95
  "@types/node": "^26",