use-intl 2.9.2-alpha.0 → 2.10.0-alpha.3

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 (161) hide show
  1. package/CHANGELOG.md +463 -0
  2. package/dist/core/use-intl.esm.js +140 -27
  3. package/dist/core/use-intl.esm.js.map +1 -1
  4. package/dist/core/use-intl.esm2.js +27 -140
  5. package/dist/core/use-intl.esm2.js.map +1 -1
  6. package/dist/core/use-intl.esm3.js +2 -2
  7. package/dist/core/use-intl.esm4.js +12 -56
  8. package/dist/core/use-intl.esm4.js.map +1 -1
  9. package/dist/core/use-intl.esm5.js +56 -12
  10. package/dist/core/use-intl.esm5.js.map +1 -1
  11. package/dist/core/use-intl.esm6.js +7 -29
  12. package/dist/core/use-intl.esm6.js.map +1 -1
  13. package/dist/core/use-intl.esm7.js +9 -9
  14. package/dist/core/use-intl.esm7.js.map +1 -1
  15. package/dist/core/use-intl.esm8.js +29 -7
  16. package/dist/core/use-intl.esm8.js.map +1 -1
  17. package/dist/react/IntlContext.d.ts +2 -19
  18. package/dist/react/IntlContextValue.d.ts +19 -0
  19. package/dist/react/IntlProvider.d.ts +2 -16
  20. package/dist/react/IntlProviderProps.d.ts +15 -0
  21. package/dist/react/getIntlContextValue.d.ts +18 -0
  22. package/dist/react/use-intl.esm.js +12 -21
  23. package/dist/react/use-intl.esm.js.map +1 -1
  24. package/dist/react/use-intl.esm10.js +44 -0
  25. package/dist/react/use-intl.esm10.js.map +1 -0
  26. package/dist/react/use-intl.esm2.js +2 -2
  27. package/dist/react/use-intl.esm3.js +20 -30
  28. package/dist/react/use-intl.esm3.js.map +1 -1
  29. package/dist/react/use-intl.esm4.js +46 -4
  30. package/dist/react/use-intl.esm4.js.map +1 -1
  31. package/dist/react/use-intl.esm5.js +1 -1
  32. package/dist/react/use-intl.esm6.js +4 -46
  33. package/dist/react/use-intl.esm6.js.map +1 -1
  34. package/dist/react/use-intl.esm7.js +3 -12
  35. package/dist/react/use-intl.esm7.js.map +1 -1
  36. package/dist/react/use-intl.esm8.js +30 -3
  37. package/dist/react/use-intl.esm8.js.map +1 -1
  38. package/dist/react/use-intl.esm9.js +9 -38
  39. package/dist/react/use-intl.esm9.js.map +1 -1
  40. package/dist/react/useIntlContext.d.ts +1 -1
  41. package/dist/src/core/AbstractIntlMessages.d.ts +9 -0
  42. package/dist/src/core/AbstractIntlMessages.js +2 -0
  43. package/dist/src/core/AbstractIntlMessages.js.map +1 -0
  44. package/dist/src/core/DateTimeFormatOptions.d.ts +72 -0
  45. package/dist/src/core/DateTimeFormatOptions.js +3 -0
  46. package/dist/src/core/DateTimeFormatOptions.js.map +1 -0
  47. package/dist/src/core/Formats.d.ts +7 -0
  48. package/dist/src/core/Formats.js +2 -0
  49. package/dist/src/core/Formats.js.map +1 -0
  50. package/dist/src/core/IntlConfiguration.d.ts +46 -0
  51. package/dist/src/core/IntlConfiguration.js +2 -0
  52. package/dist/src/core/IntlConfiguration.js.map +1 -0
  53. package/dist/src/core/IntlError.d.ts +13 -0
  54. package/dist/src/core/IntlError.js +23 -0
  55. package/dist/src/core/IntlError.js.map +1 -0
  56. package/dist/src/core/IntlMessages.d.ts +2 -0
  57. package/dist/src/core/IntlMessages.js +4 -0
  58. package/dist/src/core/IntlMessages.js.map +1 -0
  59. package/dist/src/core/NumberFormatOptions.d.ts +2 -0
  60. package/dist/src/core/NumberFormatOptions.js +2 -0
  61. package/dist/src/core/NumberFormatOptions.js.map +1 -0
  62. package/dist/src/core/TranslationValues.d.ts +5 -0
  63. package/dist/src/core/TranslationValues.js +2 -0
  64. package/dist/src/core/TranslationValues.js.map +1 -0
  65. package/dist/src/core/convertFormatsToIntlMessageFormat.d.ts +10 -0
  66. package/dist/src/core/convertFormatsToIntlMessageFormat.js +31 -0
  67. package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +1 -0
  68. package/dist/src/core/createBaseTranslator.d.ts +26 -0
  69. package/dist/src/core/createBaseTranslator.js +185 -0
  70. package/dist/src/core/createBaseTranslator.js.map +1 -0
  71. package/dist/src/core/createIntl.d.ts +17 -0
  72. package/dist/src/core/createIntl.js +126 -0
  73. package/dist/src/core/createIntl.js.map +1 -0
  74. package/dist/src/core/createTranslator.d.ts +48 -0
  75. package/dist/src/core/createTranslator.js +24 -0
  76. package/dist/src/core/createTranslator.js.map +1 -0
  77. package/dist/src/core/createTranslatorImpl.d.ts +14 -0
  78. package/dist/src/core/createTranslatorImpl.js +43 -0
  79. package/dist/src/core/createTranslatorImpl.js.map +1 -0
  80. package/dist/src/core/defaults.d.ts +11 -0
  81. package/dist/src/core/defaults.js +11 -0
  82. package/dist/src/core/defaults.js.map +1 -0
  83. package/dist/src/core/index.d.ts +8 -0
  84. package/dist/src/core/index.js +4 -0
  85. package/dist/src/core/index.js.map +1 -0
  86. package/dist/src/core/resolveNamespace.d.ts +5 -0
  87. package/dist/src/core/resolveNamespace.js +10 -0
  88. package/dist/src/core/resolveNamespace.js.map +1 -0
  89. package/dist/src/core/utils/MessageKeys.d.ts +5 -0
  90. package/dist/src/core/utils/MessageKeys.js +2 -0
  91. package/dist/src/core/utils/MessageKeys.js.map +1 -0
  92. package/dist/src/core/utils/NamespaceKeys.d.ts +5 -0
  93. package/dist/src/core/utils/NamespaceKeys.js +2 -0
  94. package/dist/src/core/utils/NamespaceKeys.js.map +1 -0
  95. package/dist/src/core/utils/NestedKeyOf.d.ts +4 -0
  96. package/dist/src/core/utils/NestedKeyOf.js +2 -0
  97. package/dist/src/core/utils/NestedKeyOf.js.map +1 -0
  98. package/dist/src/core/utils/NestedValueOf.d.ts +2 -0
  99. package/dist/src/core/utils/NestedValueOf.js +2 -0
  100. package/dist/src/core/utils/NestedValueOf.js.map +1 -0
  101. package/dist/src/core/validateMessages.d.ts +3 -0
  102. package/dist/src/core/validateMessages.js +22 -0
  103. package/dist/src/core/validateMessages.js.map +1 -0
  104. package/dist/src/index.d.ts +2 -0
  105. package/dist/src/index.js +3 -0
  106. package/dist/src/index.js.map +1 -0
  107. package/dist/src/react/IntlContext.d.ts +4 -0
  108. package/dist/src/react/IntlContext.js +4 -0
  109. package/dist/src/react/IntlContext.js.map +1 -0
  110. package/dist/src/react/IntlContextValue.d.ts +19 -0
  111. package/dist/src/react/IntlContextValue.js +2 -0
  112. package/dist/src/react/IntlContextValue.js.map +1 -0
  113. package/dist/src/react/IntlProvider.d.ts +2 -0
  114. package/dist/src/react/IntlProvider.js +7 -0
  115. package/dist/src/react/IntlProvider.js.map +1 -0
  116. package/dist/src/react/IntlProviderProps.d.ts +15 -0
  117. package/dist/src/react/IntlProviderProps.js +2 -0
  118. package/dist/src/react/IntlProviderProps.js.map +1 -0
  119. package/dist/src/react/getIntlContextValue.d.ts +18 -0
  120. package/dist/src/react/getIntlContextValue.js +21 -0
  121. package/dist/src/react/getIntlContextValue.js.map +1 -0
  122. package/dist/src/react/index.d.ts +6 -0
  123. package/dist/src/react/index.js +7 -0
  124. package/dist/src/react/index.js.map +1 -0
  125. package/dist/src/react/useIntl.d.ts +5 -0
  126. package/dist/src/react/useIntl.js +14 -0
  127. package/dist/src/react/useIntl.js.map +1 -0
  128. package/dist/src/react/useIntlContext.d.ts +1 -0
  129. package/dist/src/react/useIntlContext.js +12 -0
  130. package/dist/src/react/useIntlContext.js.map +1 -0
  131. package/dist/src/react/useLocale.d.ts +1 -0
  132. package/dist/src/react/useLocale.js +5 -0
  133. package/dist/src/react/useLocale.js.map +1 -0
  134. package/dist/src/react/useNow.d.ts +23 -0
  135. package/dist/src/react/useNow.js +40 -0
  136. package/dist/src/react/useNow.js.map +1 -0
  137. package/dist/src/react/useTimeZone.d.ts +1 -0
  138. package/dist/src/react/useTimeZone.js +5 -0
  139. package/dist/src/react/useTimeZone.js.map +1 -0
  140. package/dist/src/react/useTranslations.d.ts +44 -0
  141. package/dist/src/react/useTranslations.js +21 -0
  142. package/dist/src/react/useTranslations.js.map +1 -0
  143. package/dist/src/react/useTranslationsImpl.d.ts +8 -0
  144. package/dist/src/react/useTranslationsImpl.js +35 -0
  145. package/dist/src/react/useTranslationsImpl.js.map +1 -0
  146. package/dist/use-intl.cjs.development.js +37 -28
  147. package/dist/use-intl.cjs.development.js.map +1 -1
  148. package/dist/use-intl.cjs.production.min.js +1 -1
  149. package/dist/use-intl.cjs.production.min.js.map +1 -1
  150. package/dist/use-intl.esm.js +6 -6
  151. package/package.json +6 -5
  152. package/src/core/createBaseTranslator.tsx +11 -7
  153. package/src/core/createIntl.tsx +2 -2
  154. package/src/core/createTranslatorImpl.tsx +1 -1
  155. package/src/react/IntlContext.tsx +2 -20
  156. package/src/react/IntlContextValue.tsx +21 -0
  157. package/src/react/IntlProvider.tsx +5 -36
  158. package/src/react/IntlProviderProps.tsx +17 -0
  159. package/src/react/getIntlContextValue.tsx +30 -0
  160. package/src/react/useIntlContext.tsx +1 -1
  161. package/LICENSE +0 -21
@@ -1,10 +1,32 @@
1
- /**
2
- * For the strictly typed messages to work we have to wrap the namespace into
3
- * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
4
- */
5
- function resolveNamespace(namespace, namespacePrefix) {
6
- return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
1
+ import IntlError, { IntlErrorCode } from './use-intl.esm2.js';
2
+
3
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
4
+ Object.entries(messages).forEach(function (_ref) {
5
+ var key = _ref[0],
6
+ messageOrMessages = _ref[1];
7
+
8
+ if (key.includes('.')) {
9
+ var keyLabel = key;
10
+ if (parentPath) keyLabel += " (at " + parentPath + ")";
11
+ invalidKeyLabels.push(keyLabel);
12
+ }
13
+
14
+ if (messageOrMessages != null && typeof messageOrMessages === 'object') {
15
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
16
+ return part != null;
17
+ }).join('.'));
18
+ }
19
+ });
20
+ }
21
+
22
+ function validateMessages(messages, onError) {
23
+ var invalidKeyLabels = [];
24
+ validateMessagesSegment(messages, invalidKeyLabels);
25
+
26
+ if (invalidKeyLabels.length > 0) {
27
+ onError(new IntlError(IntlErrorCode.INVALID_KEY, "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ')));
28
+ }
7
29
  }
8
30
 
9
- export { resolveNamespace as default };
31
+ export { validateMessages as default };
10
32
  //# sourceMappingURL=use-intl.esm8.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm8.js","sources":["../../src/core/resolveNamespace.tsx"],"sourcesContent":["/**\n * For the strictly typed messages to work we have to wrap the namespace into\n * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045\n */\nexport default function resolveNamespace(\n namespace: string,\n namespacePrefix: string\n) {\n return namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length);\n}\n"],"names":["resolveNamespace","namespace","namespacePrefix","undefined","slice","length"],"mappings":"AAAA;;;AAGG;AACW,SAAUA,gBAAV,CACZC,SADY,EAEZC,eAFY,EAEW;AAEvB,EAAA,OAAOD,SAAS,KAAKC,eAAd,GACHC,SADG,GAEHF,SAAS,CAACG,KAAV,CAAgB,CAACF,eAAe,GAAG,GAAnB,EAAwBG,MAAxC,CAFJ,CAAA;AAGD;;;;"}
1
+ {"version":3,"file":"use-intl.esm8.js","sources":["../../src/core/validateMessages.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n\n if (messageOrMessages != null && typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\\n\\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}`\n )\n );\n }\n}\n"],"names":["validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","IntlError","IntlErrorCode","INVALID_KEY"],"mappings":";;AAGA,SAASA,uBAAT,CACEC,QADF,EAEEC,gBAFF,EAGEC,UAHF,EAGqB;AAEnBC,EAAAA,MAAM,CAACC,OAAP,CAAeJ,QAAf,CAAyBK,CAAAA,OAAzB,CAAiC,UAA6B,IAAA,EAAA;AAAA,IAAA,IAA3BC,GAA2B,GAAA,IAAA,CAAA,CAAA,CAAA;AAAA,QAAtBC,iBAAsB,GAAA,IAAA,CAAA,CAAA,CAAA,CAAA;;AAC5D,IAAA,IAAID,GAAG,CAACE,QAAJ,CAAa,GAAb,CAAJ,EAAuB;AACrB,MAAIC,IAAAA,QAAQ,GAAGH,GAAf,CAAA;AACA,MAAA,IAAIJ,UAAJ,EAAgBO,QAAQ,IAAA,OAAA,GAAYP,UAAZ,GAAR,GAAA,CAAA;AAChBD,MAAAA,gBAAgB,CAACS,IAAjB,CAAsBD,QAAtB,CAAA,CAAA;AACD,KAAA;;AAED,IAAIF,IAAAA,iBAAiB,IAAI,IAArB,IAA6B,OAAOA,iBAAP,KAA6B,QAA9D,EAAwE;AACtER,MAAAA,uBAAuB,CACrBQ,iBADqB,EAErBN,gBAFqB,EAGrB,CAACC,UAAD,EAAaI,GAAb,CAAA,CAAkBK,MAAlB,CAAyB,UAACC,IAAD,EAAA;AAAA,QAAUA,OAAAA,IAAI,IAAI,IAAlB,CAAA;AAAA,OAAzB,CAAiDC,CAAAA,IAAjD,CAAsD,GAAtD,CAHqB,CAAvB,CAAA;AAKD,KAAA;AACF,GAdD,CAAA,CAAA;AAeD,CAAA;;AAEa,SAAUC,gBAAV,CACZd,QADY,EAEZe,OAFY,EAEuB;AAEnC,EAAMd,IAAAA,gBAAgB,GAAkB,EAAxC,CAAA;AACAF,EAAAA,uBAAuB,CAACC,QAAD,EAAWC,gBAAX,CAAvB,CAAA;;AAEA,EAAA,IAAIA,gBAAgB,CAACe,MAAjB,GAA0B,CAA9B,EAAiC;AAC/BD,IAAAA,OAAO,CACL,IAAIE,SAAJ,CACEC,aAAa,CAACC,WADhB,EAAA,2JAAA,IAGIlB,gBAAgB,CAACe,MAAjB,KAA4B,CAA5B,GAAgC,KAAhC,GAAwC,MAH5C,CAIOf,GAAAA,IAAAA,GAAAA,gBAAgB,CAACY,IAAjB,CAAsB,IAAtB,CAJP,CADK,CAAP,CAAA;AAQD,GAAA;AACF;;;;"}
@@ -1,21 +1,4 @@
1
1
  /// <reference types="react" />
2
- import AbstractIntlMessages from '../core/AbstractIntlMessages';
3
- import Formats from '../core/Formats';
4
- import IntlError from '../core/IntlError';
5
- import { RichTranslationValues } from '../core/TranslationValues';
6
- export declare type IntlContextShape = {
7
- messages?: AbstractIntlMessages;
8
- locale: string;
9
- formats?: Partial<Formats>;
10
- timeZone?: string;
11
- onError(error: IntlError): void;
12
- getMessageFallback(info: {
13
- error: IntlError;
14
- key: string;
15
- namespace?: string;
16
- }): string;
17
- now?: Date;
18
- defaultTranslationValues?: RichTranslationValues;
19
- };
20
- declare const IntlContext: import("react").Context<IntlContextShape | undefined>;
2
+ import IntlContextValue from './IntlContextValue';
3
+ declare const IntlContext: import("react").Context<IntlContextValue | undefined>;
21
4
  export default IntlContext;
@@ -0,0 +1,19 @@
1
+ import AbstractIntlMessages from '../core/AbstractIntlMessages';
2
+ import Formats from '../core/Formats';
3
+ import IntlError from '../core/IntlError';
4
+ import { RichTranslationValues } from '../core/TranslationValues';
5
+ declare type IntlContextValue = {
6
+ messages?: AbstractIntlMessages;
7
+ locale: string;
8
+ formats?: Partial<Formats>;
9
+ timeZone?: string;
10
+ onError(error: IntlError): void;
11
+ getMessageFallback(info: {
12
+ error: IntlError;
13
+ key: string;
14
+ namespace?: string;
15
+ }): string;
16
+ now?: Date;
17
+ defaultTranslationValues?: RichTranslationValues;
18
+ };
19
+ export default IntlContextValue;
@@ -1,16 +1,2 @@
1
- import { ReactNode } from 'react';
2
- import { AbstractIntlMessages } from '../core';
3
- import IntlConfiguration from '../core/IntlConfiguration';
4
- import { RichTranslationValues } from '../core/TranslationValues';
5
- declare type Props = IntlConfiguration & {
6
- /** All components that use the provided hooks should be within this tree. */
7
- children: ReactNode;
8
- /** Global default values for translation values and rich text elements.
9
- * Can be used for consistent usage or styling of rich text elements.
10
- * Defaults will be overidden by locally provided values. */
11
- defaultTranslationValues?: RichTranslationValues;
12
- /** All messages that will be available in your components. */
13
- messages?: AbstractIntlMessages;
14
- };
15
- export default function IntlProvider({ children, onError, getMessageFallback, messages, ...contextValues }: Props): JSX.Element;
16
- export {};
1
+ import IntlProviderProps from './IntlProviderProps';
2
+ export default function IntlProvider({ children, ...props }: IntlProviderProps): JSX.Element;
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from 'react';
2
+ import { AbstractIntlMessages } from '../core';
3
+ import IntlConfiguration from '../core/IntlConfiguration';
4
+ import { RichTranslationValues } from '../core/TranslationValues';
5
+ declare type IntlProviderProps = IntlConfiguration & {
6
+ /** All components that use the provided hooks should be within this tree. */
7
+ children: ReactNode;
8
+ /** Global default values for translation values and rich text elements.
9
+ * Can be used for consistent usage or styling of rich text elements.
10
+ * Defaults will be overidden by locally provided values. */
11
+ defaultTranslationValues?: RichTranslationValues;
12
+ /** All messages that will be available in your components. */
13
+ messages?: AbstractIntlMessages;
14
+ };
15
+ export default IntlProviderProps;
@@ -0,0 +1,18 @@
1
+ import IntlProviderProps from './IntlProviderProps';
2
+ /**
3
+ * Enhances the incoming props with defaults.
4
+ */
5
+ export default function getIntlContextValue({ getMessageFallback, messages, onError, ...rest }: Omit<IntlProviderProps, 'children'>): {
6
+ messages: import("../core/AbstractIntlMessages").default | undefined;
7
+ onError: (error: import("..").IntlError) => void;
8
+ getMessageFallback: (info: {
9
+ error: import("..").IntlError;
10
+ key: string;
11
+ namespace?: string | undefined;
12
+ }) => string;
13
+ locale: string;
14
+ formats?: Partial<import("../core/Formats").default> | undefined;
15
+ timeZone?: string | undefined;
16
+ now?: Date | undefined;
17
+ defaultTranslationValues?: import("..").RichTranslationValues | undefined;
18
+ };
@@ -1,26 +1,17 @@
1
- import useIntlContext from './use-intl.esm7.js';
2
- import useTranslationsImpl from './use-intl.esm9.js';
1
+ import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../_virtual/use-intl.esm.js';
2
+ import React from 'react';
3
+ import IntlContext from './use-intl.esm7.js';
4
+ import getIntlContextValue from './use-intl.esm8.js';
3
5
 
4
- /**
5
- * Translates messages from the given namespace by using the ICU syntax.
6
- * See https://formatjs.io/docs/core-concepts/icu-syntax.
7
- *
8
- * If no namespace is provided, all available messages are returned.
9
- * The namespace can also indicate nesting by using a dot
10
- * (e.g. `namespace.Component`).
11
- */
6
+ var _excluded = ["children"];
7
+ function IntlProvider(_ref) {
8
+ var children = _ref.children,
9
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
12
10
 
13
- function useTranslations(namespace) {
14
- var context = useIntlContext();
15
- var messages = context.messages; // We have to wrap the actual hook so the type inference for the optional
16
- // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
17
- // The prefix ("!") is arbitrary.
18
-
19
- return useTranslationsImpl({
20
- '!': messages
21
- }, // @ts-ignore
22
- namespace ? "!." + namespace : '!', '!');
11
+ return React.createElement(IntlContext.Provider, {
12
+ value: getIntlContextValue(props)
13
+ }, children);
23
14
  }
24
15
 
25
- export { useTranslations as default };
16
+ export { IntlProvider as default };
26
17
  //# sourceMappingURL=use-intl.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm.js","sources":["../../src/react/useTranslations.tsx"],"sourcesContent":["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"],"names":["useTranslations","namespace","context","useIntlContext","messages","useTranslationsImpl"],"mappings":";;;AAYA;;;;;;;AAOG;;AACqB,SAAAA,eAAA,CAMtBC,SANsB,EAMD;AA6DrB,EAAMC,IAAAA,OAAO,GAAGC,cAAc,EAA9B,CAAA;AACA,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAzB,CA9DqB;AAiErB;AACA;;AACA,EAAA,OAAOC,mBAAmB,CAIxB;AAAC,IAAKD,GAAAA,EAAAA,QAAAA;AAAN,GAJwB;AAMxBH,EAAAA,SAAS,GAAQA,IAAAA,GAAAA,SAAR,GAAsB,GANP,EAOxB,GAPwB,CAA1B,CAAA;AASD;;;;"}
1
+ {"version":3,"file":"use-intl.esm.js","sources":["../../src/react/IntlProvider.tsx"],"sourcesContent":["import React from 'react';\nimport IntlContext from './IntlContext';\nimport IntlProviderProps from './IntlProviderProps';\nimport getIntlContextValue from './getIntlContextValue';\n\nexport default function IntlProvider({children, ...props}: IntlProviderProps) {\n return (\n <IntlContext.Provider value={getIntlContextValue(props)}>\n {children}\n </IntlContext.Provider>\n );\n}\n"],"names":["IntlProvider","children","props","React","createElement","IntlContext","Provider","value","getIntlContextValue"],"mappings":";;;;;;AAKc,SAAUA,YAAV,CAA8D,IAAA,EAAA;AAAA,EAAtCC,IAAAA,QAAsC,QAAtCA,QAAsC;AAAA,MAAzBC,KAAyB,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AAC1E,EAAA,OACEC,KAAC,CAAAC,aAAD,CAACC,WAAW,CAACC,QAAb;AAAsBC,IAAAA,KAAK,EAAEC,mBAAmB,CAACN,KAAD,CAAA;GAAhD,EACGD,QADH,CADF,CAAA;AAKD;;;;"}
@@ -0,0 +1,44 @@
1
+ import { useRef, useMemo } from 'react';
2
+ import createBaseTranslator, { getMessagesOrError } from '../core/use-intl.esm7.js';
3
+ import resolveNamespace from '../core/use-intl.esm6.js';
4
+ import useIntlContext from './use-intl.esm9.js';
5
+
6
+ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
7
+ var _useIntlContext = useIntlContext(),
8
+ defaultTranslationValues = _useIntlContext.defaultTranslationValues,
9
+ globalFormats = _useIntlContext.formats,
10
+ getMessageFallback = _useIntlContext.getMessageFallback,
11
+ locale = _useIntlContext.locale,
12
+ onError = _useIntlContext.onError,
13
+ timeZone = _useIntlContext.timeZone; // The `namespacePrefix` is part of the type system.
14
+ // See the comment in the hook invocation.
15
+
16
+
17
+ allMessages = allMessages[namespacePrefix];
18
+ namespace = resolveNamespace(namespace, namespacePrefix);
19
+ var cachedFormatsByLocaleRef = useRef({});
20
+ var messagesOrError = useMemo(function () {
21
+ return getMessagesOrError({
22
+ messages: allMessages,
23
+ namespace: namespace,
24
+ onError: onError
25
+ });
26
+ }, [allMessages, namespace, onError]);
27
+ var translate = useMemo(function () {
28
+ return createBaseTranslator({
29
+ cachedFormatsByLocale: cachedFormatsByLocaleRef.current,
30
+ getMessageFallback: getMessageFallback,
31
+ messagesOrError: messagesOrError,
32
+ defaultTranslationValues: defaultTranslationValues,
33
+ namespace: namespace,
34
+ onError: onError,
35
+ formats: globalFormats,
36
+ locale: locale,
37
+ timeZone: timeZone
38
+ });
39
+ }, [getMessageFallback, messagesOrError, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
40
+ return translate;
41
+ }
42
+
43
+ export { useTranslationsImpl as default };
44
+ //# sourceMappingURL=use-intl.esm10.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm10.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["import {IntlMessageFormat} from 'intl-messageformat';\nimport {useMemo, useRef} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator, {\n getMessagesOrError\n} 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 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 cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(\n () => getMessagesOrError({messages: allMessages, namespace, onError}),\n [allMessages, namespace, onError]\n );\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n cachedFormatsByLocale: cachedFormatsByLocaleRef.current,\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n"],"names":["useTranslationsImpl","allMessages","namespace","namespacePrefix","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","resolveNamespace","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","getMessagesOrError","messages","translate","createBaseTranslator","cachedFormatsByLocale","current"],"mappings":";;;;;AAUwB,SAAAA,mBAAA,CAGtBC,WAHsB,EAGCC,SAHD,EAGuBC,eAHvB,EAG8C;AACpE,EAAA,IAAA,eAAA,GAOIC,cAAc,EAPlB;AAAA,MACEC,wBADF,mBACEA,wBADF;AAAA,MAEWC,aAFX,mBAEEC,OAFF;AAAA,MAGEC,kBAHF,mBAGEA,kBAHF;AAAA,MAIEC,MAJF,mBAIEA,MAJF;AAAA,MAKEC,OALF,mBAKEA,OALF;AAAA,MAMEC,QANF,GAAA,eAAA,CAMEA,QANF,CADoE;AAWpE;;;AACAV,EAAAA,WAAW,GAAGA,WAAW,CAACE,eAAD,CAAzB,CAAA;AACAD,EAAAA,SAAS,GAAGU,gBAAgB,CAACV,SAAD,EAAYC,eAAZ,CAA5B,CAAA;AAEA,EAAA,IAAMU,wBAAwB,GAAGC,MAAM,CAErC,EAFqC,CAAvC,CAAA;AAIA,EAAMC,IAAAA,eAAe,GAAGC,OAAO,CAC7B,YAAA;AAAA,IAAA,OAAMC,kBAAkB,CAAC;AAACC,MAAAA,QAAQ,EAAEjB,WAAX;AAAwBC,MAAAA,SAAS,EAATA,SAAxB;AAAmCQ,MAAAA,OAAO,EAAPA,OAAAA;AAAnC,KAAD,CAAxB,CAAA;AAAA,GAD6B,EAE7B,CAACT,WAAD,EAAcC,SAAd,EAAyBQ,OAAzB,CAF6B,CAA/B,CAAA;AAKA,EAAMS,IAAAA,SAAS,GAAGH,OAAO,CACvB,YAAA;AAAA,IAAA,OACEI,oBAAoB,CAAC;AACnBC,MAAAA,qBAAqB,EAAER,wBAAwB,CAACS,OAD7B;AAEnBd,MAAAA,kBAAkB,EAAlBA,kBAFmB;AAGnBO,MAAAA,eAAe,EAAfA,eAHmB;AAInBV,MAAAA,wBAAwB,EAAxBA,wBAJmB;AAKnBH,MAAAA,SAAS,EAATA,SALmB;AAMnBQ,MAAAA,OAAO,EAAPA,OANmB;AAOnBH,MAAAA,OAAO,EAAED,aAPU;AAQnBG,MAAAA,MAAM,EAANA,MARmB;AASnBE,MAAAA,QAAQ,EAARA,QAAAA;AATmB,KAAD,CADtB,CAAA;AAAA,GADuB,EAavB,CACEH,kBADF,EAEEO,eAFF,EAGEV,wBAHF,EAIEH,SAJF,EAKEQ,OALF,EAMEJ,aANF,EAOEG,MAPF,EAQEE,QARF,CAbuB,CAAzB,CAAA;AAyBA,EAAA,OAAOQ,SAAP,CAAA;AACD;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { useMemo } from 'react';
2
- import createIntl from '../core/use-intl.esm2.js';
3
- import useIntlContext from './use-intl.esm7.js';
2
+ import createIntl from '../core/use-intl.esm.js';
3
+ import useIntlContext from './use-intl.esm9.js';
4
4
 
5
5
  function useIntl() {
6
6
  var _useIntlContext = useIntlContext(),
@@ -1,36 +1,26 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import React, { useEffect } from 'react';
3
- import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm5.js';
4
- import validateMessages from '../core/use-intl.esm6.js';
5
- import IntlContext from './use-intl.esm8.js';
1
+ import useIntlContext from './use-intl.esm9.js';
2
+ import useTranslationsImpl from './use-intl.esm10.js';
6
3
 
7
- var _excluded = ["children", "onError", "getMessageFallback", "messages"];
8
- function IntlProvider(_ref) {
9
- var children = _ref.children,
10
- _ref$onError = _ref.onError,
11
- onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
12
- _ref$getMessageFallba = _ref.getMessageFallback,
13
- getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
14
- messages = _ref.messages,
15
- contextValues = _objectWithoutPropertiesLoose(_ref, _excluded);
4
+ /**
5
+ * Translates messages from the given namespace by using the ICU syntax.
6
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
7
+ *
8
+ * If no namespace is provided, all available messages are returned.
9
+ * The namespace can also indicate nesting by using a dot
10
+ * (e.g. `namespace.Component`).
11
+ */
16
12
 
17
- if (process.env.NODE_ENV !== "production") {
18
- // eslint-disable-next-line react-hooks/rules-of-hooks
19
- useEffect(function () {
20
- if (messages) {
21
- validateMessages(messages, onError);
22
- }
23
- }, [messages, onError]);
24
- }
13
+ function useTranslations(namespace) {
14
+ var context = useIntlContext();
15
+ var messages = context.messages; // We have to wrap the actual hook so the type inference for the optional
16
+ // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
17
+ // The prefix ("!") is arbitrary.
25
18
 
26
- return React.createElement(IntlContext.Provider, {
27
- value: _extends({}, contextValues, {
28
- messages: messages,
29
- onError: onError,
30
- getMessageFallback: getMessageFallback
31
- })
32
- }, children);
19
+ return useTranslationsImpl({
20
+ '!': messages
21
+ }, // @ts-ignore
22
+ namespace ? "!." + namespace : '!', '!');
33
23
  }
34
24
 
35
- export { IntlProvider as default };
25
+ export { useTranslations as default };
36
26
  //# sourceMappingURL=use-intl.esm3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm3.js","sources":["../../src/react/IntlProvider.tsx"],"sourcesContent":["import React, {ReactNode, useEffect} from 'react';\nimport {AbstractIntlMessages} from '../core';\nimport IntlConfiguration from '../core/IntlConfiguration';\nimport {RichTranslationValues} from '../core/TranslationValues';\nimport {defaultGetMessageFallback, defaultOnError} from '../core/defaults';\nimport validateMessages from '../core/validateMessages';\nimport IntlContext from './IntlContext';\n\ntype Props = IntlConfiguration & {\n /** All components that use the provided hooks should be within this tree. */\n children: ReactNode;\n /** Global default values for translation values and rich text elements.\n * Can be used for consistent usage or styling of rich text elements.\n * Defaults will be overidden by locally provided values. */\n defaultTranslationValues?: RichTranslationValues;\n /** All messages that will be available in your components. */\n messages?: AbstractIntlMessages;\n};\n\nexport default function IntlProvider({\n children,\n onError = defaultOnError,\n getMessageFallback = defaultGetMessageFallback,\n messages,\n ...contextValues\n}: Props) {\n if (__DEV__) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n if (messages) {\n validateMessages(messages, onError);\n }\n }, [messages, onError]);\n }\n\n return (\n <IntlContext.Provider\n value={{...contextValues, messages, onError, getMessageFallback}}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n"],"names":["IntlProvider","children","onError","defaultOnError","getMessageFallback","defaultGetMessageFallback","messages","contextValues","useEffect","validateMessages","React","IntlContext","Provider","value"],"mappings":";;;;;;;AAmBwB,SAAAA,YAAA,CAMhB,IAAA,EAAA;AAAA,EALNC,IAAAA,QAKM,QALNA,QAKM;AAAA,MAAA,YAAA,GAAA,IAAA,CAJNC,OAIM;AAAA,MAJNA,OAIM,6BAJIC,cAIJ,GAAA,YAAA;AAAA,MAAA,qBAAA,GAAA,IAAA,CAHNC,kBAGM;AAAA,MAHNA,kBAGM,sCAHeC,yBAGf,GAAA,qBAAA;AAAA,MAFNC,QAEM,QAFNA,QAEM;AAAA,MADHC,aACG,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACN,EAAa,IAAA,OAAA,CAAA,GAAA,CAAA,QAAA,KAAA,YAAA,EAAA;AACX;AACAC,IAAAA,SAAS,CAAC,YAAK;AACb,MAAA,IAAIF,QAAJ,EAAc;AACZG,QAAAA,gBAAgB,CAACH,QAAD,EAAWJ,OAAX,CAAhB,CAAA;AACD,OAAA;AACF,KAJQ,EAIN,CAACI,QAAD,EAAWJ,OAAX,CAJM,CAAT,CAAA;AAKD,GAAA;;AAED,EAAA,OACEQ,mBAAA,CAACC,WAAW,CAACC,QAAb,EACE;AAAAC,IAAAA,KAAK,eAAMN,aAAN,EAAA;AAAqBD,MAAAA,QAAQ,EAARA,QAArB;AAA+BJ,MAAAA,OAAO,EAAPA,OAA/B;AAAwCE,MAAAA,kBAAkB,EAAlBA,kBAAAA;AAAxC,KAAA,CAAA;AAAL,GADF,EAGGH,QAHH,CADF,CAAA;AAOD;;;;"}
1
+ {"version":3,"file":"use-intl.esm3.js","sources":["../../src/react/useTranslations.tsx"],"sourcesContent":["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"],"names":["useTranslations","namespace","context","useIntlContext","messages","useTranslationsImpl"],"mappings":";;;AAYA;;;;;;;AAOG;;AACqB,SAAAA,eAAA,CAMtBC,SANsB,EAMD;AA6DrB,EAAMC,IAAAA,OAAO,GAAGC,cAAc,EAA9B,CAAA;AACA,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAzB,CA9DqB;AAiErB;AACA;;AACA,EAAA,OAAOC,mBAAmB,CAIxB;AAAC,IAAKD,GAAAA,EAAAA,QAAAA;AAAN,GAJwB;AAMxBH,EAAAA,SAAS,GAAQA,IAAAA,GAAAA,SAAR,GAAsB,GANP,EAOxB,GAPwB,CAA1B,CAAA;AASD;;;;"}
@@ -1,8 +1,50 @@
1
- import useIntlContext from './use-intl.esm7.js';
1
+ import { useState, useEffect } from 'react';
2
+ import useIntlContext from './use-intl.esm9.js';
2
3
 
3
- function useTimeZone() {
4
- return useIntlContext().timeZone;
4
+ function getNow() {
5
+ return new Date();
5
6
  }
7
+ /**
8
+ * Reading the current date via `new Date()` in components should be avoided, as
9
+ * it causes components to be impure and can lead to flaky tests. Instead, this
10
+ * hook can be used.
11
+ *
12
+ * By default, it returns the time when the component mounts. If `updateInterval`
13
+ * is specified, the value will be updated based on the interval.
14
+ *
15
+ * You can however also return a static value from this hook, if you
16
+ * configure the `now` parameter on the context provider. Note however,
17
+ * that if `updateInterval` is configured in this case, the component
18
+ * will initialize with the global value, but will afterwards update
19
+ * continuously based on the interval.
20
+ *
21
+ * For unit tests, this can be mocked to a constant value. For end-to-end
22
+ * testing, an environment parameter can be passed to the `now` parameter
23
+ * of the provider to mock this to a static value.
24
+ */
6
25
 
7
- export { useTimeZone as default };
26
+
27
+ function useNow(options) {
28
+ var updateInterval = options == null ? void 0 : options.updateInterval;
29
+
30
+ var _useIntlContext = useIntlContext(),
31
+ globalNow = _useIntlContext.now;
32
+
33
+ var _useState = useState(globalNow || getNow()),
34
+ now = _useState[0],
35
+ setNow = _useState[1];
36
+
37
+ useEffect(function () {
38
+ if (!updateInterval) return;
39
+ var intervalId = setInterval(function () {
40
+ setNow(getNow());
41
+ }, updateInterval);
42
+ return function () {
43
+ clearInterval(intervalId);
44
+ };
45
+ }, [globalNow, updateInterval]);
46
+ return now;
47
+ }
48
+
49
+ export { useNow as default };
8
50
  //# sourceMappingURL=use-intl.esm4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAV,GAAqB;AACjC,EAAOC,OAAAA,cAAc,GAAGC,QAAxB,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/useNow.tsx"],"sourcesContent":["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"],"names":["getNow","Date","useNow","options","updateInterval","useIntlContext","globalNow","now","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAT,GAAe;AACb,EAAO,OAAA,IAAIC,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAC,MAAA,CAAOC,OAAP,EAAwB;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBC,cAAc,EAAvC;AAAA,MAAYC,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsBC,QAAQ,CAACF,SAAS,IAAIN,MAAM,EAApB,CAA9B;AAAA,MAAOO,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAYE,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACN,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMO,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACT,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BI,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVS,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAACL,SAAD,EAAYF,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOG,GAAP,CAAA;AACD;;;;"}
@@ -1,4 +1,4 @@
1
- import useIntlContext from './use-intl.esm7.js';
1
+ import useIntlContext from './use-intl.esm9.js';
2
2
 
3
3
  function useLocale() {
4
4
  return useIntlContext().locale;
@@ -1,50 +1,8 @@
1
- import { useState, useEffect } from 'react';
2
- import useIntlContext from './use-intl.esm7.js';
1
+ import useIntlContext from './use-intl.esm9.js';
3
2
 
4
- function getNow() {
5
- return new Date();
3
+ function useTimeZone() {
4
+ return useIntlContext().timeZone;
6
5
  }
7
- /**
8
- * Reading the current date via `new Date()` in components should be avoided, as
9
- * it causes components to be impure and can lead to flaky tests. Instead, this
10
- * hook can be used.
11
- *
12
- * By default, it returns the time when the component mounts. If `updateInterval`
13
- * is specified, the value will be updated based on the interval.
14
- *
15
- * You can however also return a static value from this hook, if you
16
- * configure the `now` parameter on the context provider. Note however,
17
- * that if `updateInterval` is configured in this case, the component
18
- * will initialize with the global value, but will afterwards update
19
- * continuously based on the interval.
20
- *
21
- * For unit tests, this can be mocked to a constant value. For end-to-end
22
- * testing, an environment parameter can be passed to the `now` parameter
23
- * of the provider to mock this to a static value.
24
- */
25
6
 
26
-
27
- function useNow(options) {
28
- var updateInterval = options == null ? void 0 : options.updateInterval;
29
-
30
- var _useIntlContext = useIntlContext(),
31
- globalNow = _useIntlContext.now;
32
-
33
- var _useState = useState(globalNow || getNow()),
34
- now = _useState[0],
35
- setNow = _useState[1];
36
-
37
- useEffect(function () {
38
- if (!updateInterval) return;
39
- var intervalId = setInterval(function () {
40
- setNow(getNow());
41
- }, updateInterval);
42
- return function () {
43
- clearInterval(intervalId);
44
- };
45
- }, [globalNow, updateInterval]);
46
- return now;
47
- }
48
-
49
- export { useNow as default };
7
+ export { useTimeZone as default };
50
8
  //# sourceMappingURL=use-intl.esm6.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm6.js","sources":["../../src/react/useNow.tsx"],"sourcesContent":["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"],"names":["getNow","Date","useNow","options","updateInterval","useIntlContext","globalNow","now","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAT,GAAe;AACb,EAAO,OAAA,IAAIC,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAC,MAAA,CAAOC,OAAP,EAAwB;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBC,cAAc,EAAvC;AAAA,MAAYC,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsBC,QAAQ,CAACF,SAAS,IAAIN,MAAM,EAApB,CAA9B;AAAA,MAAOO,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAYE,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACN,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMO,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACT,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BI,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVS,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAACL,SAAD,EAAYF,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOG,GAAP,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm6.js","sources":["../../src/react/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAV,GAAqB;AACjC,EAAOC,OAAAA,cAAc,GAAGC,QAAxB,CAAA;AACD;;;;"}
@@ -1,15 +1,6 @@
1
- import { useContext } from 'react';
2
- import IntlContext from './use-intl.esm8.js';
1
+ import { createContext } from 'react';
3
2
 
4
- function useIntlContext() {
5
- var context = useContext(IntlContext);
3
+ var IntlContext = /*#__PURE__*/createContext(undefined);
6
4
 
7
- if (!context) {
8
- throw new Error(process.env.NODE_ENV !== "production" ? 'No intl context found. Have you configured the provider?' : undefined);
9
- }
10
-
11
- return context;
12
- }
13
-
14
- export { useIntlContext as default };
5
+ export { IntlContext as default };
15
6
  //# sourceMappingURL=use-intl.esm7.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/useIntlContext.tsx"],"sourcesContent":["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 __DEV__\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","undefined"],"mappings":";;;AAGc,SAAUA,cAAV,GAAwB;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAD,CAA1B,CAAA;;AAEA,EAAI,IAAA,CAACF,OAAL,EAAc;AACZ,IAAA,MAAM,IAAIG,KAAJ,CACJ,wCACI,0DADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OAAOJ,OAAP,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport IntlContextValue from './IntlContextValue';\n\nconst IntlContext = createContext<IntlContextValue | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAGA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
@@ -1,6 +1,33 @@
1
- import { createContext } from 'react';
1
+ import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
+ import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm4.js';
3
+ import validateMessages from '../core/use-intl.esm8.js';
2
4
 
3
- var IntlContext = /*#__PURE__*/createContext(undefined);
5
+ var _excluded = ["getMessageFallback", "messages", "onError"];
6
+ /**
7
+ * Enhances the incoming props with defaults.
8
+ */
4
9
 
5
- export { IntlContext as default };
10
+ function getIntlContextValue(_ref) {
11
+ var getMessageFallback = _ref.getMessageFallback,
12
+ messages = _ref.messages,
13
+ onError = _ref.onError,
14
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
15
+
16
+ var finalOnError = onError || defaultOnError;
17
+ var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
18
+
19
+ if (process.env.NODE_ENV !== 'production') {
20
+ if (messages) {
21
+ validateMessages(messages, finalOnError);
22
+ }
23
+ }
24
+
25
+ return _extends({}, rest, {
26
+ messages: messages,
27
+ onError: finalOnError,
28
+ getMessageFallback: finalGetMessageFallback
29
+ });
30
+ }
31
+
32
+ export { getIntlContextValue as default };
6
33
  //# sourceMappingURL=use-intl.esm8.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport Formats from '../core/Formats';\nimport IntlError from '../core/IntlError';\nimport {RichTranslationValues} from '../core/TranslationValues';\n\nexport type IntlContextShape = {\n messages?: AbstractIntlMessages;\n locale: string;\n formats?: Partial<Formats>;\n timeZone?: string;\n onError(error: IntlError): void;\n getMessageFallback(info: {\n error: IntlError;\n key: string;\n namespace?: string;\n }): string;\n now?: Date;\n defaultTranslationValues?: RichTranslationValues;\n};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
1
+ {"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/getIntlContextValue.tsx"],"sourcesContent":["import {defaultGetMessageFallback, defaultOnError} from '../core/defaults';\nimport validateMessages from '../core/validateMessages';\nimport IntlProviderProps from './IntlProviderProps';\n\n/**\n * Enhances the incoming props with defaults.\n */\nexport default function getIntlContextValue({\n getMessageFallback,\n messages,\n onError,\n ...rest\n}: Omit<IntlProviderProps, 'children'>) {\n const finalOnError = onError || defaultOnError;\n const finalGetMessageFallback =\n getMessageFallback || defaultGetMessageFallback;\n\n if (process.env.NODE_ENV !== 'production') {\n if (messages) {\n validateMessages(messages, finalOnError);\n }\n }\n\n return {\n ...rest,\n messages,\n onError: finalOnError,\n getMessageFallback: finalGetMessageFallback\n };\n}\n"],"names":["getIntlContextValue","getMessageFallback","messages","onError","rest","finalOnError","defaultOnError","finalGetMessageFallback","defaultGetMessageFallback","process","env","NODE_ENV","validateMessages"],"mappings":";;;;;AAIA;;AAEG;;AACqB,SAAAA,mBAAA,CAKc,IAAA,EAAA;AAAA,EAJpCC,IAAAA,kBAIoC,QAJpCA,kBAIoC;AAAA,MAHpCC,QAGoC,QAHpCA,QAGoC;AAAA,MAFpCC,OAEoC,QAFpCA,OAEoC;AAAA,MADjCC,IACiC,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACpC,EAAA,IAAMC,YAAY,GAAGF,OAAO,IAAIG,cAAhC,CAAA;AACA,EAAA,IAAMC,uBAAuB,GAC3BN,kBAAkB,IAAIO,yBADxB,CAAA;;AAGA,EAAA,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,IAAA,IAAIT,QAAJ,EAAc;AACZU,MAAAA,gBAAgB,CAACV,QAAD,EAAWG,YAAX,CAAhB,CAAA;AACD,KAAA;AACF,GAAA;;AAED,EAAA,OAAA,QAAA,CAAA,EAAA,EACKD,IADL,EAAA;AAEEF,IAAAA,QAAQ,EAARA,QAFF;AAGEC,IAAAA,OAAO,EAAEE,YAHX;AAIEJ,IAAAA,kBAAkB,EAAEM,uBAAAA;AAJtB,GAAA,CAAA,CAAA;AAMD;;;;"}