use-intl 2.20.0 → 3.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/core.d.ts +1 -0
  2. package/dist/_virtual/_rollupPluginBabelHelpers.esm.js +102 -0
  3. package/dist/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -0
  4. package/dist/core/IntlError.esm.js +33 -0
  5. package/dist/core/IntlError.esm.js.map +1 -0
  6. package/dist/core/TranslationValues.d.ts +1 -0
  7. package/dist/core/convertFormatsToIntlMessageFormat.esm.js +37 -0
  8. package/dist/core/convertFormatsToIntlMessageFormat.esm.js.map +1 -0
  9. package/dist/core/createBaseTranslator.d.ts +3 -8
  10. package/dist/core/createBaseTranslator.esm.js +210 -0
  11. package/dist/core/createBaseTranslator.esm.js.map +1 -0
  12. package/dist/core/createFormatter.esm.js +138 -0
  13. package/dist/core/createFormatter.esm.js.map +1 -0
  14. package/dist/core/createIntl.esm.js +14 -0
  15. package/dist/core/createIntl.esm.js.map +1 -0
  16. package/dist/core/createTranslator.d.ts +2 -3
  17. package/dist/core/createTranslator.esm.js +37 -0
  18. package/dist/core/createTranslator.esm.js.map +1 -0
  19. package/dist/core/createTranslatorImpl.d.ts +2 -3
  20. package/dist/core/createTranslatorImpl.esm.js +50 -0
  21. package/dist/core/createTranslatorImpl.esm.js.map +1 -0
  22. package/dist/core/defaults.esm.js +15 -0
  23. package/dist/core/defaults.esm.js.map +1 -0
  24. package/dist/core/index.d.ts +8 -1
  25. package/dist/core/initializeConfig.d.ts +13 -0
  26. package/dist/core/initializeConfig.esm.js +29 -0
  27. package/dist/core/initializeConfig.esm.js.map +1 -0
  28. package/dist/core/resolveNamespace.esm.js +10 -0
  29. package/dist/core/resolveNamespace.esm.js.map +1 -0
  30. package/dist/core/use-intl.esm10.js +23 -32
  31. package/dist/core/use-intl.esm10.js.map +1 -1
  32. package/dist/core/use-intl.esm11.js +10 -0
  33. package/dist/core/use-intl.esm11.js.map +1 -0
  34. package/dist/core/use-intl.esm2.js +204 -31
  35. package/dist/core/use-intl.esm2.js.map +1 -1
  36. package/dist/core/use-intl.esm3.js +31 -132
  37. package/dist/core/use-intl.esm3.js.map +1 -1
  38. package/dist/core/use-intl.esm4.js +1 -1
  39. package/dist/core/use-intl.esm5.js +19 -43
  40. package/dist/core/use-intl.esm5.js.map +1 -1
  41. package/dist/core/use-intl.esm6.js +134 -11
  42. package/dist/core/use-intl.esm6.js.map +1 -1
  43. package/dist/core/use-intl.esm7.js +29 -192
  44. package/dist/core/use-intl.esm7.js.map +1 -1
  45. package/dist/core/use-intl.esm8.js +10 -5
  46. package/dist/core/use-intl.esm8.js.map +1 -1
  47. package/dist/core/use-intl.esm9.js +44 -22
  48. package/dist/core/use-intl.esm9.js.map +1 -1
  49. package/dist/core/validateMessages.esm.js +28 -0
  50. package/dist/core/validateMessages.esm.js.map +1 -0
  51. package/dist/core.cjs.development.js +93 -0
  52. package/dist/core.cjs.development.js.map +1 -0
  53. package/dist/core.cjs.production.min.js +2 -0
  54. package/dist/core.cjs.production.min.js.map +1 -0
  55. package/dist/core.d.ts +1 -0
  56. package/dist/core.esm.js +7 -0
  57. package/dist/core.esm.js.map +1 -0
  58. package/dist/core.js +8 -0
  59. package/dist/createIntl-34d4281e.js +592 -0
  60. package/dist/createIntl-34d4281e.js.map +1 -0
  61. package/dist/createIntl-bc325740.js +2 -0
  62. package/dist/createIntl-bc325740.js.map +1 -0
  63. package/dist/react/IntlContext.esm.js +6 -0
  64. package/dist/react/IntlContext.esm.js.map +1 -0
  65. package/dist/react/IntlProvider.d.ts +1 -1
  66. package/dist/react/IntlProvider.esm.js +22 -0
  67. package/dist/react/IntlProvider.esm.js.map +1 -0
  68. package/dist/react/getInitializedConfig.d.ts +1 -13
  69. package/dist/react/use-intl.esm.js +22 -18
  70. package/dist/react/use-intl.esm.js.map +1 -1
  71. package/dist/react/use-intl.esm10.js +8 -24
  72. package/dist/react/use-intl.esm10.js.map +1 -1
  73. package/dist/react/use-intl.esm11.js +3 -10
  74. package/dist/react/use-intl.esm11.js.map +1 -1
  75. package/dist/react/use-intl.esm2.js +4 -22
  76. package/dist/react/use-intl.esm2.js.map +1 -1
  77. package/dist/react/use-intl.esm3.js +26 -4
  78. package/dist/react/use-intl.esm3.js.map +1 -1
  79. package/dist/react/use-intl.esm4.js +18 -41
  80. package/dist/react/use-intl.esm4.js.map +1 -1
  81. package/dist/react/use-intl.esm5.js +20 -4
  82. package/dist/react/use-intl.esm5.js.map +1 -1
  83. package/dist/react/use-intl.esm6.js +41 -4
  84. package/dist/react/use-intl.esm6.js.map +1 -1
  85. package/dist/react/use-intl.esm7.js +4 -20
  86. package/dist/react/use-intl.esm7.js.map +1 -1
  87. package/dist/react/use-intl.esm8.js +4 -26
  88. package/dist/react/use-intl.esm8.js.map +1 -1
  89. package/dist/react/use-intl.esm9.js +33 -3
  90. package/dist/react/use-intl.esm9.js.map +1 -1
  91. package/dist/react/useFormatter.esm.js +24 -0
  92. package/dist/react/useFormatter.esm.js.map +1 -0
  93. package/dist/react/useIntl.esm.js +30 -0
  94. package/dist/react/useIntl.esm.js.map +1 -0
  95. package/dist/react/useIntlContext.esm.js +13 -0
  96. package/dist/react/useIntlContext.esm.js.map +1 -0
  97. package/dist/react/useLocale.esm.js +8 -0
  98. package/dist/react/useLocale.esm.js.map +1 -0
  99. package/dist/react/useMessages.esm.js +8 -0
  100. package/dist/react/useMessages.esm.js.map +1 -0
  101. package/{src/react/useNow.tsx → dist/react/useNow.esm.js} +32 -36
  102. package/dist/react/useNow.esm.js.map +1 -0
  103. package/dist/react/useTimeZone.esm.js +8 -0
  104. package/dist/react/useTimeZone.esm.js.map +1 -0
  105. package/dist/react/useTranslations.esm.js +26 -0
  106. package/dist/react/useTranslations.esm.js.map +1 -0
  107. package/dist/react/{use-intl.esm12.js → useTranslationsImpl.esm.js} +6 -13
  108. package/dist/react/useTranslationsImpl.esm.js.map +1 -0
  109. package/dist/react.cjs.development.js +190 -0
  110. package/dist/react.cjs.development.js.map +1 -0
  111. package/dist/react.cjs.production.min.js +2 -0
  112. package/dist/react.cjs.production.min.js.map +1 -0
  113. package/dist/react.d.ts +1 -0
  114. package/dist/react.esm.js +9 -0
  115. package/dist/react.esm.js.map +1 -0
  116. package/dist/react.js +8 -0
  117. package/dist/test/setup.d.ts +1 -0
  118. package/dist/use-intl.cjs.development.js +32 -30
  119. package/dist/use-intl.cjs.development.js.map +1 -1
  120. package/dist/use-intl.cjs.production.min.js +1 -1
  121. package/dist/use-intl.cjs.production.min.js.map +1 -1
  122. package/dist/use-intl.esm.js +12 -10
  123. package/dist/use-intl.esm.js.map +1 -1
  124. package/package.json +17 -15
  125. package/react.d.ts +1 -0
  126. package/dist/react/use-intl.esm12.js.map +0 -1
  127. package/dist/src/core/AbstractIntlMessages.d.ts +0 -9
  128. package/dist/src/core/AbstractIntlMessages.js +0 -2
  129. package/dist/src/core/AbstractIntlMessages.js.map +0 -1
  130. package/dist/src/core/DateTimeFormatOptions.d.ts +0 -73
  131. package/dist/src/core/DateTimeFormatOptions.js +0 -3
  132. package/dist/src/core/DateTimeFormatOptions.js.map +0 -1
  133. package/dist/src/core/Formats.d.ts +0 -8
  134. package/dist/src/core/Formats.js +0 -2
  135. package/dist/src/core/Formats.js.map +0 -1
  136. package/dist/src/core/IntlConfig.d.ts +0 -54
  137. package/dist/src/core/IntlConfig.js +0 -2
  138. package/dist/src/core/IntlConfig.js.map +0 -1
  139. package/dist/src/core/IntlError.d.ts +0 -13
  140. package/dist/src/core/IntlError.js +0 -23
  141. package/dist/src/core/IntlError.js.map +0 -1
  142. package/dist/src/core/MessageFormatCache.d.ts +0 -5
  143. package/dist/src/core/MessageFormatCache.js +0 -2
  144. package/dist/src/core/MessageFormatCache.js.map +0 -1
  145. package/dist/src/core/NumberFormatOptions.d.ts +0 -2
  146. package/dist/src/core/NumberFormatOptions.js +0 -2
  147. package/dist/src/core/NumberFormatOptions.js.map +0 -1
  148. package/dist/src/core/TimeZone.d.ts +0 -2
  149. package/dist/src/core/TimeZone.js +0 -2
  150. package/dist/src/core/TimeZone.js.map +0 -1
  151. package/dist/src/core/TranslationValues.d.ts +0 -5
  152. package/dist/src/core/TranslationValues.js +0 -2
  153. package/dist/src/core/TranslationValues.js.map +0 -1
  154. package/dist/src/core/convertFormatsToIntlMessageFormat.d.ts +0 -11
  155. package/dist/src/core/convertFormatsToIntlMessageFormat.js +0 -47
  156. package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +0 -1
  157. package/dist/src/core/createBaseTranslator.d.ts +0 -26
  158. package/dist/src/core/createBaseTranslator.js +0 -218
  159. package/dist/src/core/createBaseTranslator.js.map +0 -1
  160. package/dist/src/core/createFormatter.d.ts +0 -19
  161. package/dist/src/core/createFormatter.js +0 -129
  162. package/dist/src/core/createFormatter.js.map +0 -1
  163. package/dist/src/core/createIntl.d.ts +0 -7
  164. package/dist/src/core/createIntl.js +0 -11
  165. package/dist/src/core/createIntl.js.map +0 -1
  166. package/dist/src/core/createTranslator.d.ts +0 -48
  167. package/dist/src/core/createTranslator.js +0 -24
  168. package/dist/src/core/createTranslator.js.map +0 -1
  169. package/dist/src/core/createTranslatorImpl.d.ts +0 -14
  170. package/dist/src/core/createTranslatorImpl.js +0 -43
  171. package/dist/src/core/createTranslatorImpl.js.map +0 -1
  172. package/dist/src/core/defaults.d.ts +0 -11
  173. package/dist/src/core/defaults.js +0 -11
  174. package/dist/src/core/defaults.js.map +0 -1
  175. package/dist/src/core/index.d.ts +0 -9
  176. package/dist/src/core/index.js +0 -6
  177. package/dist/src/core/index.js.map +0 -1
  178. package/dist/src/core/resolveNamespace.d.ts +0 -5
  179. package/dist/src/core/resolveNamespace.js +0 -10
  180. package/dist/src/core/resolveNamespace.js.map +0 -1
  181. package/dist/src/core/utils/MessageKeys.d.ts +0 -5
  182. package/dist/src/core/utils/MessageKeys.js +0 -2
  183. package/dist/src/core/utils/MessageKeys.js.map +0 -1
  184. package/dist/src/core/utils/NamespaceKeys.d.ts +0 -5
  185. package/dist/src/core/utils/NamespaceKeys.js +0 -2
  186. package/dist/src/core/utils/NamespaceKeys.js.map +0 -1
  187. package/dist/src/core/utils/NestedKeyOf.d.ts +0 -4
  188. package/dist/src/core/utils/NestedKeyOf.js +0 -2
  189. package/dist/src/core/utils/NestedKeyOf.js.map +0 -1
  190. package/dist/src/core/utils/NestedValueOf.d.ts +0 -2
  191. package/dist/src/core/utils/NestedValueOf.js +0 -2
  192. package/dist/src/core/utils/NestedValueOf.js.map +0 -1
  193. package/dist/src/core/validateMessages.d.ts +0 -3
  194. package/dist/src/core/validateMessages.js +0 -56
  195. package/dist/src/core/validateMessages.js.map +0 -1
  196. package/dist/src/index.d.ts +0 -2
  197. package/dist/src/index.js +0 -3
  198. package/dist/src/index.js.map +0 -1
  199. package/dist/src/react/IntlContext.d.ts +0 -13
  200. package/dist/src/react/IntlContext.js +0 -4
  201. package/dist/src/react/IntlContext.js.map +0 -1
  202. package/dist/src/react/IntlProvider.d.ts +0 -7
  203. package/dist/src/react/IntlProvider.js +0 -11
  204. package/dist/src/react/IntlProvider.js.map +0 -1
  205. package/dist/src/react/getInitializedConfig.d.ts +0 -13
  206. package/dist/src/react/getInitializedConfig.js +0 -21
  207. package/dist/src/react/getInitializedConfig.js.map +0 -1
  208. package/dist/src/react/index.d.ts +0 -8
  209. package/dist/src/react/index.js +0 -10
  210. package/dist/src/react/index.js.map +0 -1
  211. package/dist/src/react/useFormatter.d.ts +0 -6
  212. package/dist/src/react/useFormatter.js +0 -14
  213. package/dist/src/react/useFormatter.js.map +0 -1
  214. package/dist/src/react/useIntl.d.ts +0 -6
  215. package/dist/src/react/useIntl.js +0 -20
  216. package/dist/src/react/useIntl.js.map +0 -1
  217. package/dist/src/react/useIntlContext.d.ts +0 -10
  218. package/dist/src/react/useIntlContext.js +0 -12
  219. package/dist/src/react/useIntlContext.js.map +0 -1
  220. package/dist/src/react/useLocale.d.ts +0 -1
  221. package/dist/src/react/useLocale.js +0 -5
  222. package/dist/src/react/useLocale.js.map +0 -1
  223. package/dist/src/react/useMessages.d.ts +0 -1
  224. package/dist/src/react/useMessages.js +0 -5
  225. package/dist/src/react/useMessages.js.map +0 -1
  226. package/dist/src/react/useNow.d.ts +0 -23
  227. package/dist/src/react/useNow.js +0 -40
  228. package/dist/src/react/useNow.js.map +0 -1
  229. package/dist/src/react/useTimeZone.d.ts +0 -1
  230. package/dist/src/react/useTimeZone.js +0 -5
  231. package/dist/src/react/useTimeZone.js.map +0 -1
  232. package/dist/src/react/useTranslations.d.ts +0 -44
  233. package/dist/src/react/useTranslations.js +0 -21
  234. package/dist/src/react/useTranslations.js.map +0 -1
  235. package/dist/src/react/useTranslationsImpl.d.ts +0 -8
  236. package/dist/src/react/useTranslationsImpl.js +0 -35
  237. package/dist/src/react/useTranslationsImpl.js.map +0 -1
  238. package/src/core/AbstractIntlMessages.tsx +0 -10
  239. package/src/core/DateTimeFormatOptions.tsx +0 -130
  240. package/src/core/Formats.tsx +0 -10
  241. package/src/core/IntlConfig.tsx +0 -59
  242. package/src/core/IntlError.tsx +0 -26
  243. package/src/core/MessageFormatCache.tsx +0 -10
  244. package/src/core/NumberFormatOptions.tsx +0 -3
  245. package/src/core/TimeZone.tsx +0 -426
  246. package/src/core/TranslationValues.tsx +0 -22
  247. package/src/core/convertFormatsToIntlMessageFormat.tsx +0 -63
  248. package/src/core/createBaseTranslator.tsx +0 -352
  249. package/src/core/createFormatter.tsx +0 -191
  250. package/src/core/createIntl.tsx +0 -13
  251. package/src/core/createTranslator.tsx +0 -112
  252. package/src/core/createTranslatorImpl.tsx +0 -87
  253. package/src/core/defaults.tsx +0 -18
  254. package/src/core/index.tsx +0 -14
  255. package/src/core/resolveNamespace.tsx +0 -12
  256. package/src/core/utils/MessageKeys.tsx +0 -9
  257. package/src/core/utils/NamespaceKeys.tsx +0 -9
  258. package/src/core/utils/NestedKeyOf.tsx +0 -9
  259. package/src/core/utils/NestedValueOf.tsx +0 -12
  260. package/src/core/validateMessages.tsx +0 -77
  261. package/src/index.tsx +0 -2
  262. package/src/react/IntlContext.tsx +0 -12
  263. package/src/react/IntlProvider.tsx +0 -23
  264. package/src/react/getInitializedConfig.tsx +0 -29
  265. package/src/react/index.tsx +0 -10
  266. package/src/react/useFormatter.tsx +0 -19
  267. package/src/react/useIntl.tsx +0 -29
  268. package/src/react/useIntlContext.tsx +0 -16
  269. package/src/react/useLocale.tsx +0 -5
  270. package/src/react/useMessages.tsx +0 -5
  271. package/src/react/useTimeZone.tsx +0 -5
  272. package/src/react/useTranslations.tsx +0 -103
  273. package/src/react/useTranslationsImpl.tsx +0 -61
@@ -0,0 +1,190 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var createIntl = require('./createIntl-34d4281e.js');
6
+ var React = require('react');
7
+ require('intl-messageformat');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
+
13
+ var IntlContext = /*#__PURE__*/React.createContext(undefined);
14
+
15
+ var _excluded = ["children"];
16
+ function IntlProvider(_ref) {
17
+ var children = _ref.children,
18
+ config = createIntl._objectWithoutPropertiesLoose(_ref, _excluded);
19
+ var _useState = React.useState(function () {
20
+ return new Map();
21
+ }),
22
+ messageFormatCache = _useState[0];
23
+ return React__default["default"].createElement(IntlContext.Provider, {
24
+ value: createIntl._extends({}, createIntl.initializeConfig(config), {
25
+ messageFormatCache: messageFormatCache
26
+ })
27
+ }, children);
28
+ }
29
+
30
+ function useIntlContext() {
31
+ var context = React.useContext(IntlContext);
32
+ if (!context) {
33
+ throw new Error('No intl context found. Have you configured the provider?' );
34
+ }
35
+ return context;
36
+ }
37
+
38
+ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
39
+ var _useIntlContext = useIntlContext(),
40
+ defaultTranslationValues = _useIntlContext.defaultTranslationValues,
41
+ globalFormats = _useIntlContext.formats,
42
+ getMessageFallback = _useIntlContext.getMessageFallback,
43
+ locale = _useIntlContext.locale,
44
+ messageFormatCache = _useIntlContext.messageFormatCache,
45
+ onError = _useIntlContext.onError,
46
+ timeZone = _useIntlContext.timeZone;
47
+ // The `namespacePrefix` is part of the type system.
48
+ // See the comment in the hook invocation.
49
+ allMessages = allMessages[namespacePrefix];
50
+ namespace = createIntl.resolveNamespace(namespace, namespacePrefix);
51
+ var translate = React.useMemo(function () {
52
+ return createIntl.createBaseTranslator({
53
+ messageFormatCache: messageFormatCache,
54
+ getMessageFallback: getMessageFallback,
55
+ messages: allMessages,
56
+ defaultTranslationValues: defaultTranslationValues,
57
+ namespace: namespace,
58
+ onError: onError,
59
+ formats: globalFormats,
60
+ locale: locale,
61
+ timeZone: timeZone
62
+ });
63
+ }, [messageFormatCache, getMessageFallback, allMessages, namespace, onError, defaultTranslationValues, globalFormats, locale, timeZone]);
64
+ return translate;
65
+ }
66
+
67
+ /**
68
+ * Translates messages from the given namespace by using the ICU syntax.
69
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
70
+ *
71
+ * If no namespace is provided, all available messages are returned.
72
+ * The namespace can also indicate nesting by using a dot
73
+ * (e.g. `namespace.Component`).
74
+ */
75
+ function useTranslations(namespace) {
76
+ var context = useIntlContext();
77
+ var messages = context.messages;
78
+ // We have to wrap the actual hook so the type inference for the optional
79
+ // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
80
+ // The prefix ("!") is arbitrary.
81
+ return useTranslationsImpl({
82
+ '!': messages
83
+ },
84
+ // @ts-ignore
85
+ namespace ? "!." + namespace : '!', '!');
86
+ }
87
+
88
+ function useLocale() {
89
+ return useIntlContext().locale;
90
+ }
91
+
92
+ function getNow() {
93
+ return new Date();
94
+ }
95
+ /**
96
+ * Reading the current date via `new Date()` in components should be avoided, as
97
+ * it causes components to be impure and can lead to flaky tests. Instead, this
98
+ * hook can be used.
99
+ *
100
+ * By default, it returns the time when the component mounts. If `updateInterval`
101
+ * is specified, the value will be updated based on the interval.
102
+ *
103
+ * You can however also return a static value from this hook, if you
104
+ * configure the `now` parameter on the context provider. Note however,
105
+ * that if `updateInterval` is configured in this case, the component
106
+ * will initialize with the global value, but will afterwards update
107
+ * continuously based on the interval.
108
+ *
109
+ * For unit tests, this can be mocked to a constant value. For end-to-end
110
+ * testing, an environment parameter can be passed to the `now` parameter
111
+ * of the provider to mock this to a static value.
112
+ */
113
+ function useNow(options) {
114
+ var updateInterval = options == null ? void 0 : options.updateInterval;
115
+ var _useIntlContext = useIntlContext(),
116
+ globalNow = _useIntlContext.now;
117
+ var _useState = React.useState(globalNow || getNow()),
118
+ now = _useState[0],
119
+ setNow = _useState[1];
120
+ React.useEffect(function () {
121
+ if (!updateInterval) return;
122
+ var intervalId = setInterval(function () {
123
+ setNow(getNow());
124
+ }, updateInterval);
125
+ return function () {
126
+ clearInterval(intervalId);
127
+ };
128
+ }, [globalNow, updateInterval]);
129
+ return now;
130
+ }
131
+
132
+ function useTimeZone() {
133
+ return useIntlContext().timeZone;
134
+ }
135
+
136
+ function useMessages() {
137
+ return useIntlContext().messages;
138
+ }
139
+
140
+ function useFormatter() {
141
+ var _useIntlContext = useIntlContext(),
142
+ formats = _useIntlContext.formats,
143
+ locale = _useIntlContext.locale,
144
+ globalNow = _useIntlContext.now,
145
+ onError = _useIntlContext.onError,
146
+ timeZone = _useIntlContext.timeZone;
147
+ return React.useMemo(function () {
148
+ return createIntl.createFormatter({
149
+ formats: formats,
150
+ locale: locale,
151
+ now: globalNow,
152
+ onError: onError,
153
+ timeZone: timeZone
154
+ });
155
+ }, [formats, globalNow, locale, onError, timeZone]);
156
+ }
157
+
158
+ var hasWarned = false;
159
+ /** @deprecated Switch to `useFormatter` instead. */
160
+ function useIntl() {
161
+ var _useIntlContext = useIntlContext(),
162
+ formats = _useIntlContext.formats,
163
+ locale = _useIntlContext.locale,
164
+ globalNow = _useIntlContext.now,
165
+ onError = _useIntlContext.onError,
166
+ timeZone = _useIntlContext.timeZone;
167
+ if (!hasWarned) {
168
+ hasWarned = true;
169
+ console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
170
+ }
171
+ return React.useMemo(function () {
172
+ return createIntl.createIntl({
173
+ formats: formats,
174
+ locale: locale,
175
+ now: globalNow,
176
+ onError: onError,
177
+ timeZone: timeZone
178
+ });
179
+ }, [formats, globalNow, locale, onError, timeZone]);
180
+ }
181
+
182
+ exports.IntlProvider = IntlProvider;
183
+ exports.useFormatter = useFormatter;
184
+ exports.useIntl = useIntl;
185
+ exports.useLocale = useLocale;
186
+ exports.useMessages = useMessages;
187
+ exports.useNow = useNow;
188
+ exports.useTimeZone = useTimeZone;
189
+ exports.useTranslations = useTranslations;
190
+ //# sourceMappingURL=react.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.cjs.development.js","sources":["../src/react/IntlContext.tsx","../src/react/IntlProvider.tsx","../src/react/useIntlContext.tsx","../src/react/useTranslationsImpl.tsx","../src/react/useTranslations.tsx","../src/react/useLocale.tsx","../src/react/useNow.tsx","../src/react/useTimeZone.tsx","../src/react/useMessages.tsx","../src/react/useFormatter.tsx","../src/react/useIntl.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport {InitializedIntlConfig} from '../core/IntlConfig';\nimport MessageFormatCache from '../core/MessageFormatCache';\n\nconst IntlContext = createContext<\n | (InitializedIntlConfig & {\n messageFormatCache?: MessageFormatCache;\n })\n | undefined\n>(undefined);\n\nexport default IntlContext;\n","import React, {ReactNode, useState} from 'react';\nimport IntlConfig from '../core/IntlConfig';\nimport initializeConfig from '../core/initializeConfig';\nimport IntlContext from './IntlContext';\n\ntype Props = IntlConfig & {\n children: ReactNode;\n};\n\nexport default function IntlProvider({children, ...config}: Props) {\n const [messageFormatCache] = useState(() => new Map());\n\n return (\n <IntlContext.Provider\n value={{\n ...initializeConfig(config),\n messageFormatCache\n }}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n","import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n","import {useMemo} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n messageFormatCache,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n messageFormatCache,\n getMessageFallback,\n messages: allMessages,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n messageFormatCache,\n getMessageFallback,\n allMessages,\n namespace,\n onError,\n defaultTranslationValues,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n","import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from '../core/Formats';\nimport TranslationValues, {\n RichTranslationValues\n} from '../core/TranslationValues';\nimport MessageKeys from '../core/utils/MessageKeys';\nimport NamespaceKeys from '../core/utils/NamespaceKeys';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport NestedValueOf from '../core/utils/NestedValueOf';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function useTranslations<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>(\n namespace?: NestedKey\n): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n const messages = context.messages as IntlMessages;\n\n // We have to wrap the actual hook so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return useTranslationsImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n","import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useMessages() {\n return useIntlContext().messages;\n}\n","import {useMemo} from 'react';\nimport createFormatter from '../core/createFormatter';\nimport useIntlContext from './useIntlContext';\n\nexport default function useFormatter() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createFormatter({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n","import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nlet hasWarned = false;\n\n/** @deprecated Switch to `useFormatter` instead. */\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'\n );\n }\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["IntlContext","createContext","undefined","IntlProvider","_ref","children","config","_objectWithoutPropertiesLoose","_excluded","_useState","useState","Map","messageFormatCache","React","createElement","Provider","value","_extends","initializeConfig","useIntlContext","context","useContext","Error","useTranslationsImpl","allMessages","namespace","namespacePrefix","_useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","resolveNamespace","translate","useMemo","createBaseTranslator","messages","useTranslations","useLocale","getNow","Date","useNow","options","updateInterval","globalNow","now","setNow","useEffect","intervalId","setInterval","clearInterval","useTimeZone","useMessages","useFormatter","createFormatter","hasWarned","useIntl","console","warn","createIntl"],"mappings":";;;;;;;;;;;;AAIA,IAAMA,WAAW,gBAAGC,mBAAa,CAK/BC,SAAS,CAAC;;;ACAE,SAAUC,YAAYA,CAAAC,IAAA,EAA6B;AAAA,EAAA,IAA3BC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;AAAKC,IAAAA,MAAM,GAAAC,wCAAA,CAAAH,IAAA,EAAAI,SAAA,CAAA,CAAA;EACvD,IAAAC,SAAA,GAA6BC,cAAQ,CAAC,YAAA;MAAA,OAAM,IAAIC,GAAG,EAAE,CAAA;KAAC,CAAA;AAA/CC,IAAAA,kBAAkB,GAAAH,SAAA,CAAA,CAAA,CAAA,CAAA;AAEzB,EAAA,OACEI,yBAAC,CAAAC,aAAA,CAAAd,WAAW,CAACe,QAAQ,EAAA;AACnBC,IAAAA,KAAK,EAAAC,mBAAA,CAAA,EAAA,EACAC,2BAAgB,CAACZ,MAAM,CAAC,EAAA;AAC3BM,MAAAA,kBAAkB,EAAlBA,kBAAAA;AAAkB,KAAA,CAAA;GAGnB,EAAAP,QAAQ,CACY,CAAA;AAE3B;;ACnBc,SAAU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AAO,GAAAH,eAAA,CAAPG,OAAO;IAAEE,MAAM,GAAAL,eAAA,CAANK,MAAM;IAAOe,SAAS,GAAApB,eAAA,CAAdqB,GAAG;IAAaf,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;EAEzD,IAAI,CAACwB,SAAS,EAAE;AACdA,IAAAA,SAAS,GAAG,IAAI,CAAA;AAChBE,IAAAA,OAAO,CAACC,IAAI,CACV,6GAA6G,CAC9G,CAAA;AACF,GAAA;AAED,EAAA,OAAOxB,aAAO,CACZ,YAAA;AAAA,IAAA,OACEyB,qBAAU,CAAC;AACThC,MAAAA,OAAO,EAAPA,OAAO;AACPE,MAAAA,MAAM,EAANA,MAAM;AACNgB,MAAAA,GAAG,EAAED,SAAS;AACdd,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACJ,OAAO,EAAEiB,SAAS,EAAEf,MAAM,EAAEC,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createIntl-bc325740.js"),r=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("intl-messageformat");var n=t(r),o=r.createContext(void 0),a=["children"];function s(){var e=r.useContext(o);if(!e)throw new Error(void 0);return e}function u(){return new Date}var i=!1;exports.IntlProvider=function(t){var s=t.children,u=e._objectWithoutPropertiesLoose(t,a),i=r.useState((function(){return new Map}))[0];return n.default.createElement(o.Provider,{value:e._extends({},e.initializeConfig(u),{messageFormatCache:i})},s)},exports.useFormatter=function(){var t=s(),n=t.formats,o=t.locale,a=t.now,u=t.onError,i=t.timeZone;return r.useMemo((function(){return e.createFormatter({formats:n,locale:o,now:a,onError:u,timeZone:i})}),[n,a,o,u,i])},exports.useIntl=function(){var t=s(),n=t.formats,o=t.locale,a=t.now,u=t.onError,l=t.timeZone;return i||(i=!0,console.warn("`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.")),r.useMemo((function(){return e.createIntl({formats:n,locale:o,now:a,onError:u,timeZone:l})}),[n,a,o,u,l])},exports.useLocale=function(){return s().locale},exports.useMessages=function(){return s().messages},exports.useNow=function(e){var t=null==e?void 0:e.updateInterval,n=s().now,o=r.useState(n||u()),a=o[0],i=o[1];return r.useEffect((function(){if(t){var e=setInterval((function(){i(u())}),t);return function(){clearInterval(e)}}}),[n,t]),a},exports.useTimeZone=function(){return s().timeZone},exports.useTranslations=function(t){return function(t,n,o){var a=s(),u=a.defaultTranslationValues,i=a.formats,l=a.getMessageFallback,c=a.locale,f=a.messageFormatCache,m=a.onError,v=a.timeZone;return t=t["!"],n=e.resolveNamespace(n,"!"),r.useMemo((function(){return e.createBaseTranslator({messageFormatCache:f,getMessageFallback:l,messages:t,defaultTranslationValues:u,namespace:n,onError:m,formats:i,locale:c,timeZone:v})}),[f,l,t,n,m,u,i,c,v])}({"!":s().messages},t?"!."+t:"!")};
2
+ //# sourceMappingURL=react.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.cjs.production.min.js","sources":["../src/react/IntlContext.tsx","../src/react/useIntlContext.tsx","../src/react/useNow.tsx","../src/react/useIntl.tsx","../src/react/IntlProvider.tsx","../src/react/useFormatter.tsx","../src/react/useLocale.tsx","../src/react/useMessages.tsx","../src/react/useTimeZone.tsx","../src/react/useTranslations.tsx","../src/react/useTranslationsImpl.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport {InitializedIntlConfig} from '../core/IntlConfig';\nimport MessageFormatCache from '../core/MessageFormatCache';\n\nconst IntlContext = createContext<\n | (InitializedIntlConfig & {\n messageFormatCache?: MessageFormatCache;\n })\n | undefined\n>(undefined);\n\nexport default IntlContext;\n","import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n","import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n","import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nlet hasWarned = false;\n\n/** @deprecated Switch to `useFormatter` instead. */\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'\n );\n }\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n","import React, {ReactNode, useState} from 'react';\nimport IntlConfig from '../core/IntlConfig';\nimport initializeConfig from '../core/initializeConfig';\nimport IntlContext from './IntlContext';\n\ntype Props = IntlConfig & {\n children: ReactNode;\n};\n\nexport default function IntlProvider({children, ...config}: Props) {\n const [messageFormatCache] = useState(() => new Map());\n\n return (\n <IntlContext.Provider\n value={{\n ...initializeConfig(config),\n messageFormatCache\n }}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n","import {useMemo} from 'react';\nimport createFormatter from '../core/createFormatter';\nimport useIntlContext from './useIntlContext';\n\nexport default function useFormatter() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createFormatter({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useMessages() {\n return useIntlContext().messages;\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n","import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from '../core/Formats';\nimport TranslationValues, {\n RichTranslationValues\n} from '../core/TranslationValues';\nimport MessageKeys from '../core/utils/MessageKeys';\nimport NamespaceKeys from '../core/utils/NamespaceKeys';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport NestedValueOf from '../core/utils/NestedValueOf';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function useTranslations<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>(\n namespace?: NestedKey\n): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n const messages = context.messages as IntlMessages;\n\n // We have to wrap the actual hook so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return useTranslationsImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n","import {useMemo} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n messageFormatCache,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n messageFormatCache,\n getMessageFallback,\n messages: allMessages,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n messageFormatCache,\n getMessageFallback,\n allMessages,\n namespace,\n onError,\n defaultTranslationValues,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n"],"names":["IntlContext","createContext","undefined","useIntlContext","context","useContext","Error","getNow","Date","hasWarned","_ref","children","config","_objectWithoutPropertiesLoose","_excluded","messageFormatCache","useState","Map","React","createElement","Provider","value","_extends","initializeConfig","_useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createFormatter","console","warn","createIntl","messages","options","updateInterval","_useState","setNow","useEffect","intervalId","setInterval","clearInterval","namespace","allMessages","namespacePrefix","defaultTranslationValues","globalFormats","getMessageFallback","resolveNamespace","createBaseTranslator","useTranslationsImpl"],"mappings":"kPAIMA,EAAcC,EAAaA,mBAK/BC,kBCNY,SAAUC,IACtB,IAAMC,EAAUC,aAAWL,GAE3B,IAAKI,EACH,MAAM,IAAIE,WAGJJ,GAIR,OAAOE,CACT,CCRA,SAASG,IACP,OAAO,IAAIC,IACb,CCLA,IAAIC,GAAY,uBCKF,SAAsBC,GAA6B,IAA3BC,EAAQD,EAARC,SAAaC,EAAMC,EAAAA,8BAAAH,EAAAI,GAChDC,EAAsBC,EAAAA,UAAS,WAAA,OAAM,IAAIC,OAAvB,GAEzB,OACEC,UAACC,cAAAnB,EAAYoB,SAAQ,CACnBC,MAAKC,EAAAA,SAAA,CAAA,EACAC,EAAgBA,iBAACX,GAAO,CAC3BG,mBAAAA,KAGDJ,EAGP,uBClBc,WACZ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AlB0B,mBACAxB,EAAMF,EAANE,OACAX,EAAkBS,EAAlBT,mBACAc,EAAOL,EAAPK,QACAC,EAAQN,EAARM,SAkCF,OA7BAgB,EAAcA,ED6EZ,KC5EFD,EAAYM,EAAgBA,iBAACN,ED4E3B,KC1EgBd,EAAAA,SAChB,WAAA,OACEqB,uBAAqB,CACnBrC,mBAAAA,EACAmC,mBAAAA,EACAd,SAAUU,EACVE,yBAAAA,EACAH,UAAAA,EACAhB,QAAAA,EACAJ,QAASwB,EACTvB,OAAAA,EACAI,SAAAA,GACA,GACJ,CACEf,EACAmC,EACAJ,EACAD,EACAhB,EACAmB,EACAC,EACAvB,EACAI,GAKN,CDwCSuB,CAIL,CAAC,IAValD,IACSiC,UAWvBS,OAAiBA,EAAc,IAGnC"}
@@ -0,0 +1 @@
1
+ export * from './react/index';
@@ -0,0 +1,9 @@
1
+ export { default as IntlProvider } from './react/IntlProvider.esm.js';
2
+ export { default as useTranslations } from './react/useTranslations.esm.js';
3
+ export { default as useLocale } from './react/useLocale.esm.js';
4
+ export { default as useNow } from './react/useNow.esm.js';
5
+ export { default as useTimeZone } from './react/useTimeZone.esm.js';
6
+ export { default as useMessages } from './react/useMessages.esm.js';
7
+ export { default as useFormatter } from './react/useFormatter.esm.js';
8
+ export { default as useIntl } from './react/useIntl.esm.js';
9
+ //# sourceMappingURL=react.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
package/dist/react.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./react.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./react.cjs.development.js')
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -252,7 +252,17 @@ function getPlainMessage(candidate, values) {
252
252
  }
253
253
  return undefined;
254
254
  }
255
- function createBaseTranslator(_ref2) {
255
+ function createBaseTranslator(config) {
256
+ var messagesOrError = getMessagesOrError({
257
+ messages: config.messages,
258
+ namespace: config.namespace,
259
+ onError: config.onError
260
+ });
261
+ return createBaseTranslatorImpl(_extends({}, config, {
262
+ messagesOrError: messagesOrError
263
+ }));
264
+ }
265
+ function createBaseTranslatorImpl(_ref2) {
256
266
  var defaultTranslationValues = _ref2.defaultTranslationValues,
257
267
  globalFormats = _ref2.formats,
258
268
  _ref2$getMessageFallb = _ref2.getMessageFallback,
@@ -397,11 +407,8 @@ function createTranslatorImpl(_ref, namespacePrefix) {
397
407
  var translator = createBaseTranslator(_extends({}, rest, {
398
408
  onError: onError,
399
409
  getMessageFallback: getMessageFallback,
400
- messagesOrError: getMessagesOrError({
401
- messages: messages,
402
- namespace: namespace,
403
- onError: onError
404
- })
410
+ messages: messages,
411
+ namespace: namespace
405
412
  }));
406
413
  var originalRich = translator.rich;
407
414
  function base() {
@@ -592,18 +599,6 @@ function createFormatter(_ref) {
592
599
  };
593
600
  }
594
601
 
595
- /** @deprecated Switch to `createFormatter` */
596
- function createIntl() {
597
- var formatter = createFormatter.apply(void 0, arguments);
598
- return {
599
- formatDateTime: formatter.dateTime,
600
- formatNumber: formatter.number,
601
- formatRelativeTime: formatter.relativeTime
602
- };
603
- }
604
-
605
- var IntlContext = /*#__PURE__*/React.createContext(undefined);
606
-
607
602
  function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
608
603
  Object.entries(messages).forEach(function (_ref) {
609
604
  var key = _ref[0],
@@ -632,7 +627,7 @@ var _excluded$1 = ["getMessageFallback", "messages", "onError"];
632
627
  /**
633
628
  * Enhances the incoming props with defaults.
634
629
  */
635
- function getInitializedConfig(_ref) {
630
+ function initializeConfig(_ref) {
636
631
  var getMessageFallback = _ref.getMessageFallback,
637
632
  messages = _ref.messages,
638
633
  onError = _ref.onError,
@@ -651,16 +646,28 @@ function getInitializedConfig(_ref) {
651
646
  });
652
647
  }
653
648
 
649
+ /** @deprecated Switch to `createFormatter` */
650
+ function createIntl() {
651
+ var formatter = createFormatter.apply(void 0, arguments);
652
+ return {
653
+ formatDateTime: formatter.dateTime,
654
+ formatNumber: formatter.number,
655
+ formatRelativeTime: formatter.relativeTime
656
+ };
657
+ }
658
+
659
+ var IntlContext = /*#__PURE__*/React.createContext(undefined);
660
+
654
661
  var _excluded = ["children"];
655
662
  function IntlProvider(_ref) {
656
663
  var children = _ref.children,
657
- props = _objectWithoutPropertiesLoose(_ref, _excluded);
664
+ config = _objectWithoutPropertiesLoose(_ref, _excluded);
658
665
  var _useState = React.useState(function () {
659
666
  return new Map();
660
667
  }),
661
668
  messageFormatCache = _useState[0];
662
669
  return React__default["default"].createElement(IntlContext.Provider, {
663
- value: _extends({}, getInitializedConfig(props), {
670
+ value: _extends({}, initializeConfig(config), {
664
671
  messageFormatCache: messageFormatCache
665
672
  })
666
673
  }, children);
@@ -687,18 +694,11 @@ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
687
694
  // See the comment in the hook invocation.
688
695
  allMessages = allMessages[namespacePrefix];
689
696
  namespace = resolveNamespace(namespace, namespacePrefix);
690
- var messagesOrError = React.useMemo(function () {
691
- return getMessagesOrError({
692
- messages: allMessages,
693
- namespace: namespace,
694
- onError: onError
695
- });
696
- }, [allMessages, namespace, onError]);
697
697
  var translate = React.useMemo(function () {
698
698
  return createBaseTranslator({
699
699
  messageFormatCache: messageFormatCache,
700
700
  getMessageFallback: getMessageFallback,
701
- messagesOrError: messagesOrError,
701
+ messages: allMessages,
702
702
  defaultTranslationValues: defaultTranslationValues,
703
703
  namespace: namespace,
704
704
  onError: onError,
@@ -706,7 +706,7 @@ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
706
706
  locale: locale,
707
707
  timeZone: timeZone
708
708
  });
709
- }, [messageFormatCache, getMessageFallback, messagesOrError, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
709
+ }, [messageFormatCache, getMessageFallback, allMessages, namespace, onError, defaultTranslationValues, globalFormats, locale, timeZone]);
710
710
  return translate;
711
711
  }
712
712
 
@@ -827,9 +827,11 @@ function useIntl() {
827
827
 
828
828
  exports.IntlError = IntlError;
829
829
  exports.IntlProvider = IntlProvider;
830
+ exports.createBaseTranslator = createBaseTranslator;
830
831
  exports.createFormatter = createFormatter;
831
832
  exports.createIntl = createIntl;
832
833
  exports.createTranslator = createTranslator;
834
+ exports.initializeConfig = initializeConfig;
833
835
  exports.useFormatter = useFormatter;
834
836
  exports.useIntl = useIntl;
835
837
  exports.useLocale = useLocale;