react-intl 6.0.3 → 6.0.6

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 (149) hide show
  1. package/BUILD +130 -0
  2. package/CHANGELOG.md +1384 -0
  3. package/LICENSE.md +0 -0
  4. package/README.md +0 -0
  5. package/example-sandboxes/rescripts/.rescriptsrc.js +28 -0
  6. package/example-sandboxes/rescripts/package-lock.json +18035 -0
  7. package/example-sandboxes/rescripts/package.json +35 -0
  8. package/example-sandboxes/rescripts/public/index.html +42 -0
  9. package/example-sandboxes/rescripts/src/App.tsx +16 -0
  10. package/example-sandboxes/rescripts/src/index.tsx +5 -0
  11. package/example-sandboxes/rescripts/src/react-app-env.d.ts +1 -0
  12. package/example-sandboxes/rescripts/src/styles.css +4 -0
  13. package/example-sandboxes/rescripts/tsconfig.json +20 -0
  14. package/example-sandboxes/strict-locale-type/.env +1 -0
  15. package/example-sandboxes/strict-locale-type/package-lock.json +14595 -0
  16. package/example-sandboxes/strict-locale-type/package.json +35 -0
  17. package/example-sandboxes/strict-locale-type/src/App.tsx +48 -0
  18. package/example-sandboxes/strict-locale-type/src/index.html +28 -0
  19. package/example-sandboxes/strict-locale-type/src/index.tsx +7 -0
  20. package/example-sandboxes/strict-locale-type/src/styles.css +4 -0
  21. package/example-sandboxes/strict-locale-type/tsconfig.json +7 -0
  22. package/example-sandboxes/strict-message-types/.env +1 -0
  23. package/example-sandboxes/strict-message-types/package-lock.json +14596 -0
  24. package/example-sandboxes/strict-message-types/package.json +35 -0
  25. package/example-sandboxes/strict-message-types/src/App.tsx +31 -0
  26. package/example-sandboxes/strict-message-types/src/index.html +28 -0
  27. package/example-sandboxes/strict-message-types/src/index.tsx +7 -0
  28. package/example-sandboxes/strict-message-types/src/styles.css +4 -0
  29. package/example-sandboxes/strict-message-types/tsconfig.json +7 -0
  30. package/examples/BUILD +70 -0
  31. package/examples/Bug2727.tsx +37 -0
  32. package/examples/HandleChange.tsx +48 -0
  33. package/examples/Hooks.tsx +126 -0
  34. package/examples/Injected.tsx +41 -0
  35. package/examples/Messages.tsx +82 -0
  36. package/examples/StaticTypeSafetyAndCodeSplitting/StaticTypeSafetyAndCodeSplitting.tsx +44 -0
  37. package/examples/StaticTypeSafetyAndCodeSplitting/en.json +3 -0
  38. package/examples/StaticTypeSafetyAndCodeSplitting/intlHelpers.tsx +39 -0
  39. package/examples/StaticTypeSafetyAndCodeSplitting/it.json +3 -0
  40. package/examples/TimeZone.tsx +44 -0
  41. package/examples/advanced/Advanced.tsx +68 -0
  42. package/examples/advanced/compiled-lang/en.json +77 -0
  43. package/examples/advanced/compiled-lang/fr.json +77 -0
  44. package/examples/index.html +20 -0
  45. package/examples/index.tsx +44 -0
  46. package/examples/package.json +20 -0
  47. package/index.ts +127 -0
  48. package/jest.config.js +27 -0
  49. package/package.json +12 -8
  50. package/src/components/createFormattedComponent.tsx +123 -0
  51. package/src/components/dateTimeRange.tsx +26 -0
  52. package/src/components/injectIntl.tsx +111 -0
  53. package/src/components/message.tsx +73 -0
  54. package/src/components/plural.tsx +45 -0
  55. package/src/components/provider.tsx +196 -0
  56. package/src/components/relative.tsx +192 -0
  57. package/src/components/useIntl.ts +10 -0
  58. package/src/types.ts +29 -0
  59. package/src/utils.ts +77 -0
  60. package/tests/functional/index.ts +18 -0
  61. package/tests/functional/support/build.ts +16 -0
  62. package/tests/functional/support/format.tsx +112 -0
  63. package/tests/perf/index.tsx +196 -0
  64. package/tests/setup.js +10 -0
  65. package/tests/unit/components/__snapshots__/displayName.tsx.snap +19 -0
  66. package/tests/unit/components/__snapshots__/message.tsx.snap +41 -0
  67. package/tests/unit/components/__snapshots__/relative.tsx.snap +11 -0
  68. package/tests/unit/components/__snapshots__/useIntl.tsx.snap +25 -0
  69. package/tests/unit/components/date.tsx +233 -0
  70. package/tests/unit/components/dateTimeRange.tsx +103 -0
  71. package/tests/unit/components/displayName.tsx +57 -0
  72. package/tests/unit/components/message.tsx +509 -0
  73. package/tests/unit/components/number.tsx +198 -0
  74. package/tests/unit/components/plural.tsx +116 -0
  75. package/tests/unit/components/provider.tsx +215 -0
  76. package/tests/unit/components/relative.tsx +263 -0
  77. package/tests/unit/components/time.tsx +242 -0
  78. package/tests/unit/components/useIntl.tsx +64 -0
  79. package/tests/unit/components/withIntl.tsx +66 -0
  80. package/tests/unit/react-intl.ts +88 -0
  81. package/tests/unit/testUtils.tsx +42 -0
  82. package/tsconfig.json +5 -0
  83. package/index.d.ts +0 -43
  84. package/index.d.ts.map +0 -1
  85. package/index.js +0 -51
  86. package/lib/index.d.ts +0 -43
  87. package/lib/index.d.ts.map +0 -1
  88. package/lib/index.js +0 -26
  89. package/lib/src/components/createFormattedComponent.d.ts +0 -29
  90. package/lib/src/components/createFormattedComponent.d.ts.map +0 -1
  91. package/lib/src/components/createFormattedComponent.js +0 -62
  92. package/lib/src/components/dateTimeRange.d.ts +0 -11
  93. package/lib/src/components/dateTimeRange.d.ts.map +0 -1
  94. package/lib/src/components/dateTimeRange.js +0 -15
  95. package/lib/src/components/injectIntl.d.ts +0 -22
  96. package/lib/src/components/injectIntl.d.ts.map +0 -1
  97. package/lib/src/components/injectIntl.js +0 -29
  98. package/lib/src/components/message.d.ts +0 -12
  99. package/lib/src/components/message.d.ts.map +0 -1
  100. package/lib/src/components/message.js +0 -35
  101. package/lib/src/components/plural.d.ts +0 -15
  102. package/lib/src/components/plural.d.ts.map +0 -1
  103. package/lib/src/components/plural.js +0 -26
  104. package/lib/src/components/provider.d.ts +0 -35
  105. package/lib/src/components/provider.d.ts.map +0 -1
  106. package/lib/src/components/provider.js +0 -108
  107. package/lib/src/components/relative.d.ts +0 -12
  108. package/lib/src/components/relative.d.ts.map +0 -1
  109. package/lib/src/components/relative.js +0 -129
  110. package/lib/src/components/useIntl.d.ts +0 -3
  111. package/lib/src/components/useIntl.d.ts.map +0 -1
  112. package/lib/src/components/useIntl.js +0 -8
  113. package/lib/src/types.d.ts +0 -12
  114. package/lib/src/types.d.ts.map +0 -1
  115. package/lib/src/types.js +0 -1
  116. package/lib/src/utils.d.ts +0 -14
  117. package/lib/src/utils.d.ts.map +0 -1
  118. package/lib/src/utils.js +0 -43
  119. package/react-intl.iife.js +0 -7485
  120. package/src/components/createFormattedComponent.d.ts +0 -29
  121. package/src/components/createFormattedComponent.d.ts.map +0 -1
  122. package/src/components/createFormattedComponent.js +0 -69
  123. package/src/components/dateTimeRange.d.ts +0 -11
  124. package/src/components/dateTimeRange.d.ts.map +0 -1
  125. package/src/components/dateTimeRange.js +0 -17
  126. package/src/components/injectIntl.d.ts +0 -22
  127. package/src/components/injectIntl.d.ts.map +0 -1
  128. package/src/components/injectIntl.js +0 -33
  129. package/src/components/message.d.ts +0 -12
  130. package/src/components/message.d.ts.map +0 -1
  131. package/src/components/message.js +0 -37
  132. package/src/components/plural.d.ts +0 -15
  133. package/src/components/plural.d.ts.map +0 -1
  134. package/src/components/plural.js +0 -29
  135. package/src/components/provider.d.ts +0 -35
  136. package/src/components/provider.d.ts.map +0 -1
  137. package/src/components/provider.js +0 -112
  138. package/src/components/relative.d.ts +0 -12
  139. package/src/components/relative.d.ts.map +0 -1
  140. package/src/components/relative.js +0 -131
  141. package/src/components/useIntl.d.ts +0 -3
  142. package/src/components/useIntl.d.ts.map +0 -1
  143. package/src/components/useIntl.js +0 -12
  144. package/src/types.d.ts +0 -12
  145. package/src/types.d.ts.map +0 -1
  146. package/src/types.js +0 -2
  147. package/src/utils.d.ts +0 -14
  148. package/src/utils.d.ts.map +0 -1
  149. package/src/utils.js +0 -49
package/lib/index.js DELETED
@@ -1,26 +0,0 @@
1
- import { createFormattedComponent, createFormattedDateTimePartsComponent, } from './src/components/createFormattedComponent';
2
- import injectIntl, { Provider as RawIntlProvider, Context as IntlContext, } from './src/components/injectIntl';
3
- import useIntl from './src/components/useIntl';
4
- import IntlProvider, { createIntl } from './src/components/provider';
5
- import FormattedRelativeTime from './src/components/relative';
6
- import FormattedPlural from './src/components/plural';
7
- import FormattedMessage from './src/components/message';
8
- import FormattedDateTimeRange from './src/components/dateTimeRange';
9
- export { FormattedDateTimeRange, FormattedMessage, FormattedPlural, FormattedRelativeTime, IntlContext, IntlProvider, RawIntlProvider, createIntl, injectIntl, useIntl, };
10
- export { createIntlCache, UnsupportedFormatterError, InvalidConfigError, MissingDataError, MessageFormatError, MissingTranslationError, IntlErrorCode as ReactIntlErrorCode, IntlError as ReactIntlError, } from '@formatjs/intl';
11
- export function defineMessages(msgs) {
12
- return msgs;
13
- }
14
- export function defineMessage(msg) {
15
- return msg;
16
- }
17
- // IMPORTANT: Explicit here to prevent api-extractor from outputing `import('./src/types').CustomFormatConfig`
18
- export var FormattedDate = createFormattedComponent('formatDate');
19
- export var FormattedTime = createFormattedComponent('formatTime');
20
- // @ts-ignore issue w/ TS Intl types
21
- export var FormattedNumber = createFormattedComponent('formatNumber');
22
- export var FormattedList = createFormattedComponent('formatList');
23
- export var FormattedDisplayName = createFormattedComponent('formatDisplayName');
24
- export var FormattedDateParts = createFormattedDateTimePartsComponent('formatDate');
25
- export var FormattedTimeParts = createFormattedDateTimePartsComponent('formatTime');
26
- export { FormattedNumberParts, FormattedListParts, } from './src/components/createFormattedComponent';
@@ -1,29 +0,0 @@
1
- import * as React from 'react';
2
- import { FormatDateOptions, FormatNumberOptions, FormatListOptions, FormatDisplayNameOptions } from '@formatjs/intl';
3
- import { IntlShape } from '../types';
4
- import { Part } from '@formatjs/intl-listformat';
5
- declare type Formatter = {
6
- formatDate: FormatDateOptions;
7
- formatTime: FormatDateOptions;
8
- formatNumber: FormatNumberOptions;
9
- formatList: FormatListOptions;
10
- formatDisplayName: FormatDisplayNameOptions;
11
- };
12
- export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] & {
13
- value: Parameters<IntlShape['formatNumber']>[0];
14
- children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
15
- }>;
16
- export declare const FormattedListParts: React.FC<Formatter['formatList'] & {
17
- value: Parameters<IntlShape['formatList']>[0];
18
- children(val: Part[]): React.ReactElement | null;
19
- }>;
20
- export declare function createFormattedDateTimePartsComponent<Name extends 'formatDate' | 'formatTime'>(name: Name): React.FC<Formatter[Name] & {
21
- value: Parameters<IntlShape[Name]>[0];
22
- children(val: Intl.DateTimeFormatPart[]): React.ReactElement | null;
23
- }>;
24
- export declare function createFormattedComponent<Name extends keyof Formatter>(name: Name): React.FC<Formatter[Name] & {
25
- value: Parameters<IntlShape[Name]>[0];
26
- children?(val: string): React.ReactElement | null;
27
- }>;
28
- export {};
29
- //# sourceMappingURL=createFormattedComponent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormattedComponent.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/react-intl/src/components/createFormattedComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAElC,OAAO,EAAC,IAAI,EAAC,MAAM,2BAA2B,CAAA;AAmB9C,aAAK,SAAS,GAAG;IACf,UAAU,EAAE,iBAAiB,CAAA;IAC7B,UAAU,EAAE,iBAAiB,CAAA;IAC7B,YAAY,EAAE,mBAAmB,CAAA;IACjC,UAAU,EAAE,iBAAiB,CAAA;IAC7B,iBAAiB,EAAE,wBAAwB,CAAA;CAC5C,CAAA;AAED,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,SAAS,CAAC,cAAc,CAAC,GAAG;IAC1B,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAE/C,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,gBAAgB,EAAE,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CAClE,CAKF,CAAA;AAGD,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CACvC,SAAS,CAAC,YAAY,CAAC,GAAG;IACxB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAE7C,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CACjD,CAKF,CAAA;AAGD,wBAAgB,qCAAqC,CACnD,IAAI,SAAS,YAAY,GAAG,YAAY,EAExC,IAAI,EAAE,IAAI,GACT,KAAK,CAAC,EAAE,CACT,SAAS,CAAC,IAAI,CAAC,GAAG;IAChB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACrC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,kBAAkB,EAAE,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CACpE,CACF,CAoBA;AAED,wBAAgB,wBAAwB,CAAC,IAAI,SAAS,MAAM,SAAS,EACnE,IAAI,EAAE,IAAI,GACT,KAAK,CAAC,EAAE,CACT,SAAS,CAAC,IAAI,CAAC,GAAG;IAChB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACrC,QAAQ,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CAClD,CACF,CAsBA"}
@@ -1,62 +0,0 @@
1
- import { __rest } from "tslib";
2
- import * as React from 'react';
3
- import useIntl from './useIntl';
4
- var DisplayName;
5
- (function (DisplayName) {
6
- DisplayName["formatDate"] = "FormattedDate";
7
- DisplayName["formatTime"] = "FormattedTime";
8
- DisplayName["formatNumber"] = "FormattedNumber";
9
- DisplayName["formatList"] = "FormattedList";
10
- // Note that this DisplayName is the locale display name, not to be confused with
11
- // the name of the enum, which is for React component display name in dev tools.
12
- DisplayName["formatDisplayName"] = "FormattedDisplayName";
13
- })(DisplayName || (DisplayName = {}));
14
- var DisplayNameParts;
15
- (function (DisplayNameParts) {
16
- DisplayNameParts["formatDate"] = "FormattedDateParts";
17
- DisplayNameParts["formatTime"] = "FormattedTimeParts";
18
- DisplayNameParts["formatNumber"] = "FormattedNumberParts";
19
- DisplayNameParts["formatList"] = "FormattedListParts";
20
- })(DisplayNameParts || (DisplayNameParts = {}));
21
- export var FormattedNumberParts = function (props) {
22
- var intl = useIntl();
23
- var value = props.value, children = props.children, formatProps = __rest(props, ["value", "children"]);
24
- return children(intl.formatNumberToParts(value, formatProps));
25
- };
26
- FormattedNumberParts.displayName = 'FormattedNumberParts';
27
- export var FormattedListParts = function (props) {
28
- var intl = useIntl();
29
- var value = props.value, children = props.children, formatProps = __rest(props, ["value", "children"]);
30
- return children(intl.formatListToParts(value, formatProps));
31
- };
32
- FormattedNumberParts.displayName = 'FormattedNumberParts';
33
- export function createFormattedDateTimePartsComponent(name) {
34
- var ComponentParts = function (props) {
35
- var intl = useIntl();
36
- var value = props.value, children = props.children, formatProps = __rest(props, ["value", "children"]);
37
- var date = typeof value === 'string' ? new Date(value || 0) : value;
38
- var formattedParts = name === 'formatDate'
39
- ? intl.formatDateToParts(date, formatProps)
40
- : intl.formatTimeToParts(date, formatProps);
41
- return children(formattedParts);
42
- };
43
- ComponentParts.displayName = DisplayNameParts[name];
44
- return ComponentParts;
45
- }
46
- export function createFormattedComponent(name) {
47
- var Component = function (props) {
48
- var intl = useIntl();
49
- var value = props.value, children = props.children, formatProps = __rest(props
50
- // TODO: fix TS type definition for localeMatcher upstream
51
- , ["value", "children"]);
52
- // TODO: fix TS type definition for localeMatcher upstream
53
- var formattedValue = intl[name](value, formatProps);
54
- if (typeof children === 'function') {
55
- return children(formattedValue);
56
- }
57
- var Text = intl.textComponent || React.Fragment;
58
- return React.createElement(Text, null, formattedValue);
59
- };
60
- Component.displayName = DisplayName[name];
61
- return Component;
62
- }
@@ -1,11 +0,0 @@
1
- import * as React from 'react';
2
- import { FormatDateOptions } from '@formatjs/intl';
3
- import { DateTimeFormat } from '@formatjs/ecma402-abstract';
4
- interface Props extends FormatDateOptions {
5
- from: Parameters<DateTimeFormat['formatRange']>[0];
6
- to: Parameters<DateTimeFormat['formatRange']>[1];
7
- children?(value: React.ReactNode): React.ReactElement | null;
8
- }
9
- declare const FormattedDateTimeRange: React.FC<Props>;
10
- export default FormattedDateTimeRange;
11
- //# sourceMappingURL=dateTimeRange.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dateTimeRange.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/react-intl/src/components/dateTimeRange.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAA;AAGzD,UAAU,KAAM,SAAQ,iBAAiB;IACvC,IAAI,EAAE,UAAU,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAClD,EAAE,EAAE,UAAU,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAChD,QAAQ,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CAC7D;AAED,QAAA,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAW3C,CAAA;AAGD,eAAe,sBAAsB,CAAA"}
@@ -1,15 +0,0 @@
1
- import { __rest } from "tslib";
2
- import * as React from 'react';
3
- import useIntl from './useIntl';
4
- var FormattedDateTimeRange = function (props) {
5
- var intl = useIntl();
6
- var from = props.from, to = props.to, children = props.children, formatProps = __rest(props, ["from", "to", "children"]);
7
- var formattedValue = intl.formatDateTimeRange(from, to, formatProps);
8
- if (typeof children === 'function') {
9
- return children(formattedValue);
10
- }
11
- var Text = intl.textComponent || React.Fragment;
12
- return React.createElement(Text, null, formattedValue);
13
- };
14
- FormattedDateTimeRange.displayName = 'FormattedDateTimeRange';
15
- export default FormattedDateTimeRange;
@@ -1,22 +0,0 @@
1
- import * as React from 'react';
2
- import { IntlShape } from '../types';
3
- export declare const Provider: React.Provider<IntlShape>;
4
- export declare const Context: React.Context<IntlShape>;
5
- export interface Opts<IntlPropName extends string = 'intl', ForwardRef extends boolean = false> {
6
- intlPropName?: IntlPropName;
7
- forwardRef?: ForwardRef;
8
- enforceContext?: boolean;
9
- }
10
- export declare type WrappedComponentProps<IntlPropName extends string = 'intl'> = {
11
- [k in IntlPropName]: IntlShape;
12
- };
13
- export declare type WithIntlProps<P> = Omit<P, keyof WrappedComponentProps> & {
14
- forwardedRef?: React.Ref<any>;
15
- };
16
- export default function injectIntl<IntlPropName extends string = 'intl', P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, false>): React.FC<WithIntlProps<P>> & {
17
- WrappedComponent: React.ComponentType<P>;
18
- };
19
- export default function injectIntl<IntlPropName extends string = 'intl', P extends WrappedComponentProps<IntlPropName> = WrappedComponentProps<any>, T extends React.ComponentType<P> = any>(WrappedComponent: React.ComponentType<P>, options?: Opts<IntlPropName, true>): React.ForwardRefExoticComponent<React.PropsWithoutRef<WithIntlProps<React.PropsWithChildren<P>>> & React.RefAttributes<T>> & {
20
- WrappedComponent: React.ComponentType<P>;
21
- };
22
- //# sourceMappingURL=injectIntl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"injectIntl.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/react-intl/src/components/injectIntl.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAUlC,eAAO,MAAM,QAAQ,2BAAe,CAAA;AACpC,eAAO,MAAM,OAAO,0BAAc,CAAA;AAElC,MAAM,WAAW,IAAI,CACnB,YAAY,SAAS,MAAM,GAAG,MAAM,EACpC,UAAU,SAAS,OAAO,GAAG,KAAK;IAElC,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,oBAAY,qBAAqB,CAAC,YAAY,SAAS,MAAM,GAAG,MAAM,IAAI;KACvE,CAAC,IAAI,YAAY,GAAG,SAAS;CAC/B,CAAA;AAED,oBAAY,aAAa,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,qBAAqB,CAAC,GAAG;IACpE,YAAY,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;CAC9B,CAAA;AAID,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,YAAY,SAAS,MAAM,GAAG,MAAM,EACpC,CAAC,SAAS,qBAAqB,CAAC,YAAY,CAAC,GAAG,qBAAqB,CAAC,GAAG,CAAC,EAE1E,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EACxC,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,GAClC,KAAK,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG;IAC9B,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;CACzC,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,YAAY,SAAS,MAAM,GAAG,MAAM,EACpC,CAAC,SAAS,qBAAqB,CAAC,YAAY,CAAC,GAAG,qBAAqB,CAAC,GAAG,CAAC,EAC1E,CAAC,SAAS,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,EAEtC,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EACxC,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,GACjC,KAAK,CAAC,yBAAyB,CAChC,KAAK,CAAC,eAAe,CAAC,aAAa,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,GAC9D,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CACzB,GAAG;IACF,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;CACzC,CAAA"}
@@ -1,29 +0,0 @@
1
- import { __assign } from "tslib";
2
- import * as React from 'react';
3
- import hoistNonReactStatics from 'hoist-non-react-statics';
4
- import { invariantIntlContext } from '../utils';
5
- function getDisplayName(Component) {
6
- return Component.displayName || Component.name || 'Component';
7
- }
8
- // TODO: We should provide initial value here
9
- var IntlContext = React.createContext(null);
10
- var IntlConsumer = IntlContext.Consumer, IntlProvider = IntlContext.Provider;
11
- export var Provider = IntlProvider;
12
- export var Context = IntlContext;
13
- export default function injectIntl(WrappedComponent, options) {
14
- var _a = options || {}, _b = _a.intlPropName, intlPropName = _b === void 0 ? 'intl' : _b, _c = _a.forwardRef, forwardRef = _c === void 0 ? false : _c, _d = _a.enforceContext, enforceContext = _d === void 0 ? true : _d;
15
- var WithIntl = function (props) { return (React.createElement(IntlConsumer, null, function (intl) {
16
- var _a;
17
- if (enforceContext) {
18
- invariantIntlContext(intl);
19
- }
20
- var intlProp = (_a = {}, _a[intlPropName] = intl, _a);
21
- return (React.createElement(WrappedComponent, __assign({}, props, intlProp, { ref: forwardRef ? props.forwardedRef : null })));
22
- })); };
23
- WithIntl.displayName = "injectIntl(".concat(getDisplayName(WrappedComponent), ")");
24
- WithIntl.WrappedComponent = WrappedComponent;
25
- if (forwardRef) {
26
- return hoistNonReactStatics(React.forwardRef(function (props, ref) { return (React.createElement(WithIntl, __assign({}, props, { forwardedRef: ref }))); }), WrappedComponent);
27
- }
28
- return hoistNonReactStatics(WithIntl, WrappedComponent);
29
- }
@@ -1,12 +0,0 @@
1
- import * as React from 'react';
2
- import type { FormatXMLElementFn, Options as IntlMessageFormatOptions, PrimitiveType } from 'intl-messageformat';
3
- import { MessageDescriptor } from '@formatjs/intl';
4
- export interface Props<V extends Record<string, any> = Record<string, React.ReactNode | PrimitiveType | FormatXMLElementFn<React.ReactNode, React.ReactNode>>> extends MessageDescriptor {
5
- values?: V;
6
- tagName?: React.ElementType<any>;
7
- children?(nodes: React.ReactNode[]): React.ReactElement | null;
8
- ignoreTag?: IntlMessageFormatOptions['ignoreTag'];
9
- }
10
- declare const MemoizedFormattedMessage: React.NamedExoticComponent<Props<Record<string, string | number | boolean | Date | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | React.ReactPortal | FormatXMLElementFn<React.ReactNode, React.ReactNode> | null | undefined>>>;
11
- export default MemoizedFormattedMessage;
12
- //# sourceMappingURL=message.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/react-intl/src/components/message.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EACV,kBAAkB,EAClB,OAAO,IAAI,wBAAwB,EACnC,aAAa,EACd,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAA;AAIhD,MAAM,WAAW,KAAK,CACpB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CACpC,MAAM,EACJ,KAAK,CAAC,SAAS,GACf,aAAa,GACb,kBAAkB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CACvD,CACD,SAAQ,iBAAiB;IACzB,MAAM,CAAC,EAAE,CAAC,CAAA;IACV,OAAO,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAChC,QAAQ,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;IAC9D,SAAS,CAAC,EAAE,wBAAwB,CAAC,WAAW,CAAC,CAAA;CAClD;AAwCD,QAAA,MAAM,wBAAwB,8QAAgD,CAAA;AAG9E,eAAe,wBAAwB,CAAA"}
@@ -1,35 +0,0 @@
1
- /*
2
- * Copyright 2015, Yahoo Inc.
3
- * Copyrights licensed under the New BSD License.
4
- * See the accompanying LICENSE file for terms.
5
- */
6
- import { __rest } from "tslib";
7
- import * as React from 'react';
8
- import useIntl from './useIntl';
9
- import { shallowEqual } from '../utils';
10
- function areEqual(prevProps, nextProps) {
11
- var values = prevProps.values, otherProps = __rest(prevProps, ["values"]);
12
- var nextValues = nextProps.values, nextOtherProps = __rest(nextProps, ["values"]);
13
- return (shallowEqual(nextValues, values) &&
14
- shallowEqual(otherProps, nextOtherProps));
15
- }
16
- function FormattedMessage(props) {
17
- var intl = useIntl();
18
- var formatMessage = intl.formatMessage, _a = intl.textComponent, Text = _a === void 0 ? React.Fragment : _a;
19
- var id = props.id, description = props.description, defaultMessage = props.defaultMessage, values = props.values, children = props.children, _b = props.tagName, Component = _b === void 0 ? Text : _b, ignoreTag = props.ignoreTag;
20
- var descriptor = { id: id, description: description, defaultMessage: defaultMessage };
21
- var nodes = formatMessage(descriptor, values, {
22
- ignoreTag: ignoreTag,
23
- });
24
- if (typeof children === 'function') {
25
- return children(Array.isArray(nodes) ? nodes : [nodes]);
26
- }
27
- if (Component) {
28
- return React.createElement(Component, null, React.Children.toArray(nodes));
29
- }
30
- return React.createElement(React.Fragment, null, nodes);
31
- }
32
- FormattedMessage.displayName = 'FormattedMessage';
33
- var MemoizedFormattedMessage = React.memo(FormattedMessage, areEqual);
34
- MemoizedFormattedMessage.displayName = 'MemoizedFormattedMessage';
35
- export default MemoizedFormattedMessage;
@@ -1,15 +0,0 @@
1
- import * as React from 'react';
2
- import { FormatPluralOptions } from '@formatjs/intl';
3
- interface Props extends FormatPluralOptions {
4
- value: number;
5
- other: React.ReactNode;
6
- zero?: React.ReactNode;
7
- one?: React.ReactNode;
8
- two?: React.ReactNode;
9
- few?: React.ReactNode;
10
- many?: React.ReactNode;
11
- children?(value: React.ReactNode): React.ReactElement | null;
12
- }
13
- declare const FormattedPlural: React.FC<Props>;
14
- export default FormattedPlural;
15
- //# sourceMappingURL=plural.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/react-intl/src/components/plural.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAC,mBAAmB,EAAC,MAAM,gBAAgB,CAAA;AAGlD,UAAU,KAAM,SAAQ,mBAAmB;IACzC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,KAAK,CAAC,SAAS,CAAA;IACtB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACtB,GAAG,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACrB,GAAG,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACrB,GAAG,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACrB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACtB,QAAQ,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CAC7D;AAED,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAepC,CAAA;AAQD,eAAe,eAAe,CAAA"}
@@ -1,26 +0,0 @@
1
- /*
2
- * Copyright 2015, Yahoo Inc.
3
- * Copyrights licensed under the New BSD License.
4
- * See the accompanying LICENSE file for terms.
5
- */
6
- import * as React from 'react';
7
- import useIntl from './useIntl';
8
- var FormattedPlural = function (props) {
9
- var _a = useIntl(), formatPlural = _a.formatPlural, Text = _a.textComponent;
10
- var value = props.value, other = props.other, children = props.children;
11
- var pluralCategory = formatPlural(value, props);
12
- var formattedPlural = props[pluralCategory] || other;
13
- if (typeof children === 'function') {
14
- return children(formattedPlural);
15
- }
16
- if (Text) {
17
- return React.createElement(Text, null, formattedPlural);
18
- }
19
- // Work around @types/react where React.FC cannot return string
20
- return formattedPlural;
21
- };
22
- FormattedPlural.defaultProps = {
23
- type: 'cardinal',
24
- };
25
- FormattedPlural.displayName = 'FormattedPlural';
26
- export default FormattedPlural;
@@ -1,35 +0,0 @@
1
- import * as React from 'react';
2
- import type { IntlConfig, IntlShape, ResolvedIntlConfig } from '../types';
3
- import { IntlCache, CreateIntlFn } from '@formatjs/intl';
4
- interface State {
5
- /**
6
- * Explicit intl cache to prevent memory leaks
7
- */
8
- cache: IntlCache;
9
- /**
10
- * Intl object we created
11
- */
12
- intl?: IntlShape;
13
- /**
14
- * list of memoized config we care about.
15
- * This is important since creating intl is
16
- * very expensive
17
- */
18
- prevConfig: IntlConfig;
19
- }
20
- /**
21
- * Create intl object
22
- * @param config intl config
23
- * @param cache cache for formatter instances to prevent memory leak
24
- */
25
- export declare const createIntl: CreateIntlFn<React.ReactNode, IntlConfig, IntlShape>;
26
- export default class IntlProvider extends React.PureComponent<React.PropsWithChildren<IntlConfig>, State> {
27
- static displayName: string;
28
- static defaultProps: Pick<ResolvedIntlConfig, "timeZone" | "fallbackOnEmptyString" | "formats" | "messages" | "defaultLocale" | "defaultFormats" | "onError" | "textComponent">;
29
- private cache;
30
- state: State;
31
- static getDerivedStateFromProps(props: Readonly<IntlConfig>, { prevConfig, cache }: State): Partial<State> | null;
32
- render(): JSX.Element;
33
- }
34
- export {};
35
- //# sourceMappingURL=provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/react-intl/src/components/provider.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAQ9B,OAAO,KAAK,EAAC,UAAU,EAAE,SAAS,EAAE,kBAAkB,EAAC,MAAM,UAAU,CAAA;AACvE,OAAO,EAEL,SAAS,EAET,YAAY,EAGb,MAAM,gBAAgB,CAAA;AAQvB,UAAU,KAAK;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,CAAA;IAChB;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB;;;;OAIG;IACH,UAAU,EAAE,UAAU,CAAA;CACvB;AAmED;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,YAAY,CACnC,KAAK,CAAC,SAAS,EACf,UAAU,EACV,SAAS,CAsCV,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,KAAK,CAAC,aAAa,CAG3D,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,EACnC,KAAK,CACN;IACC,MAAM,CAAC,WAAW,SAAiB;IACnC,MAAM,CAAC,YAAY,6JAAsB;IACzC,OAAO,CAAC,KAAK,CAA+B;IAC5C,KAAK,EAAE,KAAK,CAIX;IAED,MAAM,CAAC,wBAAwB,CAC7B,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,EAC3B,EAAC,UAAU,EAAE,KAAK,EAAC,EAAE,KAAK,GACzB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI;IAWxB,MAAM,IAAI,GAAG,CAAC,OAAO;CAItB"}
@@ -1,108 +0,0 @@
1
- /*
2
- * Copyright 2015, Yahoo Inc.
3
- * Copyrights licensed under the New BSD License.
4
- * See the accompanying LICENSE file for terms.
5
- */
6
- import { __assign, __extends, __rest, __spreadArray } from "tslib";
7
- import * as React from 'react';
8
- import { Provider } from './injectIntl';
9
- import { DEFAULT_INTL_CONFIG, invariantIntlContext, assignUniqueKeysToParts, shallowEqual, } from '../utils';
10
- import { formatMessage as coreFormatMessage, createIntl as coreCreateIntl, createIntlCache, } from '@formatjs/intl';
11
- import { isFormatXMLElementFn, } from 'intl-messageformat';
12
- function processIntlConfig(config) {
13
- return {
14
- locale: config.locale,
15
- timeZone: config.timeZone,
16
- fallbackOnEmptyString: config.fallbackOnEmptyString,
17
- formats: config.formats,
18
- textComponent: config.textComponent,
19
- messages: config.messages,
20
- defaultLocale: config.defaultLocale,
21
- defaultFormats: config.defaultFormats,
22
- onError: config.onError,
23
- onWarn: config.onWarn,
24
- wrapRichTextChunksInFragment: config.wrapRichTextChunksInFragment,
25
- defaultRichTextElements: config.defaultRichTextElements,
26
- };
27
- }
28
- function assignUniqueKeysToFormatXMLElementFnArgument(values) {
29
- if (!values) {
30
- return values;
31
- }
32
- return Object.keys(values).reduce(function (acc, k) {
33
- var v = values[k];
34
- acc[k] = isFormatXMLElementFn(v)
35
- ? assignUniqueKeysToParts(v)
36
- : v;
37
- return acc;
38
- }, {});
39
- }
40
- var formatMessage = function (config, formatters, descriptor, rawValues) {
41
- var rest = [];
42
- for (var _i = 4; _i < arguments.length; _i++) {
43
- rest[_i - 4] = arguments[_i];
44
- }
45
- var values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues);
46
- var chunks = coreFormatMessage.apply(void 0, __spreadArray([config,
47
- formatters,
48
- descriptor,
49
- values], rest, false));
50
- if (Array.isArray(chunks)) {
51
- return React.Children.toArray(chunks);
52
- }
53
- return chunks;
54
- };
55
- /**
56
- * Create intl object
57
- * @param config intl config
58
- * @param cache cache for formatter instances to prevent memory leak
59
- */
60
- export var createIntl = function (_a, cache) {
61
- var rawDefaultRichTextElements = _a.defaultRichTextElements, config = __rest(_a, ["defaultRichTextElements"]);
62
- var defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(rawDefaultRichTextElements);
63
- var coreIntl = coreCreateIntl(__assign(__assign(__assign({}, DEFAULT_INTL_CONFIG), config), { defaultRichTextElements: defaultRichTextElements }), cache);
64
- var resolvedConfig = {
65
- locale: coreIntl.locale,
66
- timeZone: coreIntl.timeZone,
67
- fallbackOnEmptyString: coreIntl.fallbackOnEmptyString,
68
- formats: coreIntl.formats,
69
- defaultLocale: coreIntl.defaultLocale,
70
- defaultFormats: coreIntl.defaultFormats,
71
- messages: coreIntl.messages,
72
- onError: coreIntl.onError,
73
- defaultRichTextElements: defaultRichTextElements,
74
- };
75
- return __assign(__assign({}, coreIntl), { formatMessage: formatMessage.bind(null, resolvedConfig, coreIntl.formatters), $t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters) });
76
- };
77
- var IntlProvider = /** @class */ (function (_super) {
78
- __extends(IntlProvider, _super);
79
- function IntlProvider() {
80
- var _this = _super !== null && _super.apply(this, arguments) || this;
81
- _this.cache = createIntlCache();
82
- _this.state = {
83
- cache: _this.cache,
84
- intl: createIntl(processIntlConfig(_this.props), _this.cache),
85
- prevConfig: processIntlConfig(_this.props),
86
- };
87
- return _this;
88
- }
89
- IntlProvider.getDerivedStateFromProps = function (props, _a) {
90
- var prevConfig = _a.prevConfig, cache = _a.cache;
91
- var config = processIntlConfig(props);
92
- if (!shallowEqual(prevConfig, config)) {
93
- return {
94
- intl: createIntl(config, cache),
95
- prevConfig: config,
96
- };
97
- }
98
- return null;
99
- };
100
- IntlProvider.prototype.render = function () {
101
- invariantIntlContext(this.state.intl);
102
- return React.createElement(Provider, { value: this.state.intl }, this.props.children);
103
- };
104
- IntlProvider.displayName = 'IntlProvider';
105
- IntlProvider.defaultProps = DEFAULT_INTL_CONFIG;
106
- return IntlProvider;
107
- }(React.PureComponent));
108
- export default IntlProvider;
@@ -1,12 +0,0 @@
1
- import * as React from 'react';
2
- import { RelativeTimeFormatSingularUnit } from '@formatjs/ecma402-abstract';
3
- import { FormatRelativeTimeOptions } from '@formatjs/intl';
4
- export interface Props extends FormatRelativeTimeOptions {
5
- value?: number;
6
- unit?: RelativeTimeFormatSingularUnit;
7
- updateIntervalInSeconds?: number;
8
- children?(value: string): React.ReactElement | null;
9
- }
10
- declare const FormattedRelativeTime: React.FC<Props>;
11
- export default FormattedRelativeTime;
12
- //# sourceMappingURL=relative.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"relative.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/react-intl/src/components/relative.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAEL,8BAA8B,EAC/B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAC,yBAAyB,EAAC,MAAM,gBAAgB,CAAA;AAuDxD,MAAM,WAAW,KAAM,SAAQ,yBAAyB;IACtD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,8BAA8B,CAAA;IACrC,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CACpD;AA8BD,QAAA,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAmF1C,CAAA;AAQD,eAAe,qBAAqB,CAAA"}
@@ -1,129 +0,0 @@
1
- import { __assign, __rest } from "tslib";
2
- /*
3
- * Copyright 2015, Yahoo Inc.
4
- * Copyrights licensed under the New BSD License.
5
- * See the accompanying LICENSE file for terms.
6
- */
7
- import * as React from 'react';
8
- import { invariant, } from '@formatjs/ecma402-abstract';
9
- import useIntl from './useIntl';
10
- var MINUTE = 60;
11
- var HOUR = 60 * 60;
12
- var DAY = 60 * 60 * 24;
13
- function selectUnit(seconds) {
14
- var absValue = Math.abs(seconds);
15
- if (absValue < MINUTE) {
16
- return 'second';
17
- }
18
- if (absValue < HOUR) {
19
- return 'minute';
20
- }
21
- if (absValue < DAY) {
22
- return 'hour';
23
- }
24
- return 'day';
25
- }
26
- function getDurationInSeconds(unit) {
27
- switch (unit) {
28
- case 'second':
29
- return 1;
30
- case 'minute':
31
- return MINUTE;
32
- case 'hour':
33
- return HOUR;
34
- default:
35
- return DAY;
36
- }
37
- }
38
- function valueToSeconds(value, unit) {
39
- if (!value) {
40
- return 0;
41
- }
42
- switch (unit) {
43
- case 'second':
44
- return value;
45
- case 'minute':
46
- return value * MINUTE;
47
- default:
48
- return value * HOUR;
49
- }
50
- }
51
- var INCREMENTABLE_UNITS = [
52
- 'second',
53
- 'minute',
54
- 'hour',
55
- ];
56
- function canIncrement(unit) {
57
- if (unit === void 0) { unit = 'second'; }
58
- return INCREMENTABLE_UNITS.indexOf(unit) > -1;
59
- }
60
- var SimpleFormattedRelativeTime = function (props) {
61
- var _a = useIntl(), formatRelativeTime = _a.formatRelativeTime, Text = _a.textComponent;
62
- var children = props.children, value = props.value, unit = props.unit, otherProps = __rest(props, ["children", "value", "unit"]);
63
- var formattedRelativeTime = formatRelativeTime(value || 0, unit, otherProps);
64
- if (typeof children === 'function') {
65
- return children(formattedRelativeTime);
66
- }
67
- if (Text) {
68
- return React.createElement(Text, null, formattedRelativeTime);
69
- }
70
- return React.createElement(React.Fragment, null, formattedRelativeTime);
71
- };
72
- var FormattedRelativeTime = function (_a) {
73
- var value = _a.value, unit = _a.unit, updateIntervalInSeconds = _a.updateIntervalInSeconds, otherProps = __rest(_a, ["value", "unit", "updateIntervalInSeconds"]);
74
- invariant(!updateIntervalInSeconds ||
75
- !!(updateIntervalInSeconds && canIncrement(unit)), 'Cannot schedule update with unit longer than hour');
76
- var _b = React.useState(), prevUnit = _b[0], setPrevUnit = _b[1];
77
- var _c = React.useState(0), prevValue = _c[0], setPrevValue = _c[1];
78
- var _d = React.useState(0), currentValueInSeconds = _d[0], setCurrentValueInSeconds = _d[1];
79
- var updateTimer;
80
- if (unit !== prevUnit || value !== prevValue) {
81
- setPrevValue(value || 0);
82
- setPrevUnit(unit);
83
- setCurrentValueInSeconds(canIncrement(unit) ? valueToSeconds(value, unit) : 0);
84
- }
85
- React.useEffect(function () {
86
- function clearUpdateTimer() {
87
- clearTimeout(updateTimer);
88
- }
89
- clearUpdateTimer();
90
- // If there's no interval and we cannot increment this unit, do nothing
91
- if (!updateIntervalInSeconds || !canIncrement(unit)) {
92
- return clearUpdateTimer;
93
- }
94
- // Figure out the next interesting time
95
- var nextValueInSeconds = currentValueInSeconds - updateIntervalInSeconds;
96
- var nextUnit = selectUnit(nextValueInSeconds);
97
- // We've reached the max auto incrementable unit, don't schedule another update
98
- if (nextUnit === 'day') {
99
- return clearUpdateTimer;
100
- }
101
- var unitDuration = getDurationInSeconds(nextUnit);
102
- var remainder = nextValueInSeconds % unitDuration;
103
- var prevInterestingValueInSeconds = nextValueInSeconds - remainder;
104
- var nextInterestingValueInSeconds = prevInterestingValueInSeconds >= currentValueInSeconds
105
- ? prevInterestingValueInSeconds - unitDuration
106
- : prevInterestingValueInSeconds;
107
- var delayInSeconds = Math.abs(nextInterestingValueInSeconds - currentValueInSeconds);
108
- if (currentValueInSeconds !== nextInterestingValueInSeconds) {
109
- updateTimer = setTimeout(function () { return setCurrentValueInSeconds(nextInterestingValueInSeconds); }, delayInSeconds * 1e3);
110
- }
111
- return clearUpdateTimer;
112
- }, [currentValueInSeconds, updateIntervalInSeconds, unit]);
113
- var currentValue = value || 0;
114
- var currentUnit = unit;
115
- if (canIncrement(unit) &&
116
- typeof currentValueInSeconds === 'number' &&
117
- updateIntervalInSeconds) {
118
- currentUnit = selectUnit(currentValueInSeconds);
119
- var unitDuration = getDurationInSeconds(currentUnit);
120
- currentValue = Math.round(currentValueInSeconds / unitDuration);
121
- }
122
- return (React.createElement(SimpleFormattedRelativeTime, __assign({ value: currentValue, unit: currentUnit }, otherProps)));
123
- };
124
- FormattedRelativeTime.displayName = 'FormattedRelativeTime';
125
- FormattedRelativeTime.defaultProps = {
126
- value: 0,
127
- unit: 'second',
128
- };
129
- export default FormattedRelativeTime;
@@ -1,3 +0,0 @@
1
- import { IntlShape } from '../types';
2
- export default function useIntl(): IntlShape;
3
- //# sourceMappingURL=useIntl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useIntl.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/react-intl/src/components/useIntl.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAElC,MAAM,CAAC,OAAO,UAAU,OAAO,IAAI,SAAS,CAI3C"}
@@ -1,8 +0,0 @@
1
- import * as React from 'react';
2
- import { Context } from './injectIntl';
3
- import { invariantIntlContext } from '../utils';
4
- export default function useIntl() {
5
- var intl = React.useContext(Context);
6
- invariantIntlContext(intl);
7
- return intl;
8
- }