react-intl 6.0.6 → 6.0.8
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.
- package/index.d.ts +43 -0
- package/index.d.ts.map +1 -0
- package/index.js +51 -0
- package/lib/index.d.ts +43 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +26 -0
- package/lib/src/components/createFormattedComponent.d.ts +29 -0
- package/lib/src/components/createFormattedComponent.d.ts.map +1 -0
- package/lib/src/components/createFormattedComponent.js +62 -0
- package/lib/src/components/dateTimeRange.d.ts +11 -0
- package/lib/src/components/dateTimeRange.d.ts.map +1 -0
- package/lib/src/components/dateTimeRange.js +15 -0
- package/lib/src/components/injectIntl.d.ts +22 -0
- package/lib/src/components/injectIntl.d.ts.map +1 -0
- package/lib/src/components/injectIntl.js +29 -0
- package/lib/src/components/message.d.ts +12 -0
- package/lib/src/components/message.d.ts.map +1 -0
- package/lib/src/components/message.js +35 -0
- package/lib/src/components/plural.d.ts +15 -0
- package/lib/src/components/plural.d.ts.map +1 -0
- package/lib/src/components/plural.js +26 -0
- package/lib/src/components/provider.d.ts +35 -0
- package/lib/src/components/provider.d.ts.map +1 -0
- package/lib/src/components/provider.js +112 -0
- package/lib/src/components/relative.d.ts +12 -0
- package/lib/src/components/relative.d.ts.map +1 -0
- package/lib/src/components/relative.js +129 -0
- package/lib/src/components/useIntl.d.ts +3 -0
- package/lib/src/components/useIntl.d.ts.map +1 -0
- package/lib/src/components/useIntl.js +8 -0
- package/lib/src/types.d.ts +12 -0
- package/lib/src/types.d.ts.map +1 -0
- package/lib/src/types.js +1 -0
- package/lib/src/utils.d.ts +14 -0
- package/lib/src/utils.d.ts.map +1 -0
- package/lib/src/utils.js +43 -0
- package/package.json +9 -9
- package/react-intl.iife.js +4688 -0
- package/src/components/createFormattedComponent.d.ts +29 -0
- package/src/components/createFormattedComponent.d.ts.map +1 -0
- package/src/components/createFormattedComponent.js +69 -0
- package/src/components/dateTimeRange.d.ts +11 -0
- package/src/components/dateTimeRange.d.ts.map +1 -0
- package/src/components/dateTimeRange.js +17 -0
- package/src/components/injectIntl.d.ts +22 -0
- package/src/components/injectIntl.d.ts.map +1 -0
- package/src/components/injectIntl.js +33 -0
- package/src/components/message.d.ts +12 -0
- package/src/components/message.d.ts.map +1 -0
- package/src/components/message.js +37 -0
- package/src/components/plural.d.ts +15 -0
- package/src/components/plural.d.ts.map +1 -0
- package/src/components/plural.js +29 -0
- package/src/components/provider.d.ts +35 -0
- package/src/components/provider.d.ts.map +1 -0
- package/src/components/provider.js +116 -0
- package/src/components/relative.d.ts +12 -0
- package/src/components/relative.d.ts.map +1 -0
- package/src/components/relative.js +131 -0
- package/src/components/useIntl.d.ts +3 -0
- package/src/components/useIntl.d.ts.map +1 -0
- package/src/components/useIntl.js +12 -0
- package/src/types.d.ts +12 -0
- package/src/types.d.ts.map +1 -0
- package/src/types.js +2 -0
- package/src/utils.d.ts +14 -0
- package/src/utils.d.ts.map +1 -0
- package/src/utils.js +49 -0
- package/BUILD +0 -130
- package/CHANGELOG.md +0 -1384
- package/example-sandboxes/rescripts/.rescriptsrc.js +0 -28
- package/example-sandboxes/rescripts/package-lock.json +0 -18035
- package/example-sandboxes/rescripts/package.json +0 -35
- package/example-sandboxes/rescripts/public/index.html +0 -42
- package/example-sandboxes/rescripts/src/App.tsx +0 -16
- package/example-sandboxes/rescripts/src/index.tsx +0 -5
- package/example-sandboxes/rescripts/src/react-app-env.d.ts +0 -1
- package/example-sandboxes/rescripts/src/styles.css +0 -4
- package/example-sandboxes/rescripts/tsconfig.json +0 -20
- package/example-sandboxes/strict-locale-type/.env +0 -1
- package/example-sandboxes/strict-locale-type/package-lock.json +0 -14595
- package/example-sandboxes/strict-locale-type/package.json +0 -35
- package/example-sandboxes/strict-locale-type/src/App.tsx +0 -48
- package/example-sandboxes/strict-locale-type/src/index.html +0 -28
- package/example-sandboxes/strict-locale-type/src/index.tsx +0 -7
- package/example-sandboxes/strict-locale-type/src/styles.css +0 -4
- package/example-sandboxes/strict-locale-type/tsconfig.json +0 -7
- package/example-sandboxes/strict-message-types/.env +0 -1
- package/example-sandboxes/strict-message-types/package-lock.json +0 -14596
- package/example-sandboxes/strict-message-types/package.json +0 -35
- package/example-sandboxes/strict-message-types/src/App.tsx +0 -31
- package/example-sandboxes/strict-message-types/src/index.html +0 -28
- package/example-sandboxes/strict-message-types/src/index.tsx +0 -7
- package/example-sandboxes/strict-message-types/src/styles.css +0 -4
- package/example-sandboxes/strict-message-types/tsconfig.json +0 -7
- package/examples/BUILD +0 -70
- package/examples/Bug2727.tsx +0 -37
- package/examples/HandleChange.tsx +0 -48
- package/examples/Hooks.tsx +0 -126
- package/examples/Injected.tsx +0 -41
- package/examples/Messages.tsx +0 -82
- package/examples/StaticTypeSafetyAndCodeSplitting/StaticTypeSafetyAndCodeSplitting.tsx +0 -44
- package/examples/StaticTypeSafetyAndCodeSplitting/en.json +0 -3
- package/examples/StaticTypeSafetyAndCodeSplitting/intlHelpers.tsx +0 -39
- package/examples/StaticTypeSafetyAndCodeSplitting/it.json +0 -3
- package/examples/TimeZone.tsx +0 -44
- package/examples/advanced/Advanced.tsx +0 -68
- package/examples/advanced/compiled-lang/en.json +0 -77
- package/examples/advanced/compiled-lang/fr.json +0 -77
- package/examples/index.html +0 -20
- package/examples/index.tsx +0 -44
- package/examples/package.json +0 -20
- package/index.ts +0 -127
- package/jest.config.js +0 -27
- package/src/components/createFormattedComponent.tsx +0 -123
- package/src/components/dateTimeRange.tsx +0 -26
- package/src/components/injectIntl.tsx +0 -111
- package/src/components/message.tsx +0 -73
- package/src/components/plural.tsx +0 -45
- package/src/components/provider.tsx +0 -196
- package/src/components/relative.tsx +0 -192
- package/src/components/useIntl.ts +0 -10
- package/src/types.ts +0 -29
- package/src/utils.ts +0 -77
- package/tests/functional/index.ts +0 -18
- package/tests/functional/support/build.ts +0 -16
- package/tests/functional/support/format.tsx +0 -112
- package/tests/perf/index.tsx +0 -196
- package/tests/setup.js +0 -10
- package/tests/unit/components/__snapshots__/displayName.tsx.snap +0 -19
- package/tests/unit/components/__snapshots__/message.tsx.snap +0 -41
- package/tests/unit/components/__snapshots__/relative.tsx.snap +0 -11
- package/tests/unit/components/__snapshots__/useIntl.tsx.snap +0 -25
- package/tests/unit/components/date.tsx +0 -233
- package/tests/unit/components/dateTimeRange.tsx +0 -103
- package/tests/unit/components/displayName.tsx +0 -57
- package/tests/unit/components/message.tsx +0 -509
- package/tests/unit/components/number.tsx +0 -198
- package/tests/unit/components/plural.tsx +0 -116
- package/tests/unit/components/provider.tsx +0 -215
- package/tests/unit/components/relative.tsx +0 -263
- package/tests/unit/components/time.tsx +0 -242
- package/tests/unit/components/useIntl.tsx +0 -64
- package/tests/unit/components/withIntl.tsx +0 -66
- package/tests/unit/react-intl.ts +0 -88
- package/tests/unit/testUtils.tsx +0 -42
- package/tsconfig.json +0 -5
|
@@ -0,0 +1,29 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFormattedComponent.d.ts","sourceRoot":"","sources":["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"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFormattedComponent = exports.createFormattedDateTimePartsComponent = exports.FormattedListParts = exports.FormattedNumberParts = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var React = tslib_1.__importStar(require("react"));
|
|
6
|
+
var useIntl_1 = tslib_1.__importDefault(require("./useIntl"));
|
|
7
|
+
var DisplayName;
|
|
8
|
+
(function (DisplayName) {
|
|
9
|
+
DisplayName["formatDate"] = "FormattedDate";
|
|
10
|
+
DisplayName["formatTime"] = "FormattedTime";
|
|
11
|
+
DisplayName["formatNumber"] = "FormattedNumber";
|
|
12
|
+
DisplayName["formatList"] = "FormattedList";
|
|
13
|
+
// Note that this DisplayName is the locale display name, not to be confused with
|
|
14
|
+
// the name of the enum, which is for React component display name in dev tools.
|
|
15
|
+
DisplayName["formatDisplayName"] = "FormattedDisplayName";
|
|
16
|
+
})(DisplayName || (DisplayName = {}));
|
|
17
|
+
var DisplayNameParts;
|
|
18
|
+
(function (DisplayNameParts) {
|
|
19
|
+
DisplayNameParts["formatDate"] = "FormattedDateParts";
|
|
20
|
+
DisplayNameParts["formatTime"] = "FormattedTimeParts";
|
|
21
|
+
DisplayNameParts["formatNumber"] = "FormattedNumberParts";
|
|
22
|
+
DisplayNameParts["formatList"] = "FormattedListParts";
|
|
23
|
+
})(DisplayNameParts || (DisplayNameParts = {}));
|
|
24
|
+
var FormattedNumberParts = function (props) {
|
|
25
|
+
var intl = (0, useIntl_1.default)();
|
|
26
|
+
var value = props.value, children = props.children, formatProps = tslib_1.__rest(props, ["value", "children"]);
|
|
27
|
+
return children(intl.formatNumberToParts(value, formatProps));
|
|
28
|
+
};
|
|
29
|
+
exports.FormattedNumberParts = FormattedNumberParts;
|
|
30
|
+
exports.FormattedNumberParts.displayName = 'FormattedNumberParts';
|
|
31
|
+
var FormattedListParts = function (props) {
|
|
32
|
+
var intl = (0, useIntl_1.default)();
|
|
33
|
+
var value = props.value, children = props.children, formatProps = tslib_1.__rest(props, ["value", "children"]);
|
|
34
|
+
return children(intl.formatListToParts(value, formatProps));
|
|
35
|
+
};
|
|
36
|
+
exports.FormattedListParts = FormattedListParts;
|
|
37
|
+
exports.FormattedNumberParts.displayName = 'FormattedNumberParts';
|
|
38
|
+
function createFormattedDateTimePartsComponent(name) {
|
|
39
|
+
var ComponentParts = function (props) {
|
|
40
|
+
var intl = (0, useIntl_1.default)();
|
|
41
|
+
var value = props.value, children = props.children, formatProps = tslib_1.__rest(props, ["value", "children"]);
|
|
42
|
+
var date = typeof value === 'string' ? new Date(value || 0) : value;
|
|
43
|
+
var formattedParts = name === 'formatDate'
|
|
44
|
+
? intl.formatDateToParts(date, formatProps)
|
|
45
|
+
: intl.formatTimeToParts(date, formatProps);
|
|
46
|
+
return children(formattedParts);
|
|
47
|
+
};
|
|
48
|
+
ComponentParts.displayName = DisplayNameParts[name];
|
|
49
|
+
return ComponentParts;
|
|
50
|
+
}
|
|
51
|
+
exports.createFormattedDateTimePartsComponent = createFormattedDateTimePartsComponent;
|
|
52
|
+
function createFormattedComponent(name) {
|
|
53
|
+
var Component = function (props) {
|
|
54
|
+
var intl = (0, useIntl_1.default)();
|
|
55
|
+
var value = props.value, children = props.children, formatProps = tslib_1.__rest(props
|
|
56
|
+
// TODO: fix TS type definition for localeMatcher upstream
|
|
57
|
+
, ["value", "children"]);
|
|
58
|
+
// TODO: fix TS type definition for localeMatcher upstream
|
|
59
|
+
var formattedValue = intl[name](value, formatProps);
|
|
60
|
+
if (typeof children === 'function') {
|
|
61
|
+
return children(formattedValue);
|
|
62
|
+
}
|
|
63
|
+
var Text = intl.textComponent || React.Fragment;
|
|
64
|
+
return React.createElement(Text, null, formattedValue);
|
|
65
|
+
};
|
|
66
|
+
Component.displayName = DisplayName[name];
|
|
67
|
+
return Component;
|
|
68
|
+
}
|
|
69
|
+
exports.createFormattedComponent = createFormattedComponent;
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateTimeRange.d.ts","sourceRoot":"","sources":["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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var React = tslib_1.__importStar(require("react"));
|
|
5
|
+
var useIntl_1 = tslib_1.__importDefault(require("./useIntl"));
|
|
6
|
+
var FormattedDateTimeRange = function (props) {
|
|
7
|
+
var intl = (0, useIntl_1.default)();
|
|
8
|
+
var from = props.from, to = props.to, children = props.children, formatProps = tslib_1.__rest(props, ["from", "to", "children"]);
|
|
9
|
+
var formattedValue = intl.formatDateTimeRange(from, to, formatProps);
|
|
10
|
+
if (typeof children === 'function') {
|
|
11
|
+
return children(formattedValue);
|
|
12
|
+
}
|
|
13
|
+
var Text = intl.textComponent || React.Fragment;
|
|
14
|
+
return React.createElement(Text, null, formattedValue);
|
|
15
|
+
};
|
|
16
|
+
FormattedDateTimeRange.displayName = 'FormattedDateTimeRange';
|
|
17
|
+
exports.default = FormattedDateTimeRange;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectIntl.d.ts","sourceRoot":"","sources":["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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Context = exports.Provider = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var React = tslib_1.__importStar(require("react"));
|
|
6
|
+
var hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics"));
|
|
7
|
+
var utils_1 = require("../utils");
|
|
8
|
+
function getDisplayName(Component) {
|
|
9
|
+
return Component.displayName || Component.name || 'Component';
|
|
10
|
+
}
|
|
11
|
+
// TODO: We should provide initial value here
|
|
12
|
+
var IntlContext = React.createContext(null);
|
|
13
|
+
var IntlConsumer = IntlContext.Consumer, IntlProvider = IntlContext.Provider;
|
|
14
|
+
exports.Provider = IntlProvider;
|
|
15
|
+
exports.Context = IntlContext;
|
|
16
|
+
function injectIntl(WrappedComponent, options) {
|
|
17
|
+
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;
|
|
18
|
+
var WithIntl = function (props) { return (React.createElement(IntlConsumer, null, function (intl) {
|
|
19
|
+
var _a;
|
|
20
|
+
if (enforceContext) {
|
|
21
|
+
(0, utils_1.invariantIntlContext)(intl);
|
|
22
|
+
}
|
|
23
|
+
var intlProp = (_a = {}, _a[intlPropName] = intl, _a);
|
|
24
|
+
return (React.createElement(WrappedComponent, tslib_1.__assign({}, props, intlProp, { ref: forwardRef ? props.forwardedRef : null })));
|
|
25
|
+
})); };
|
|
26
|
+
WithIntl.displayName = "injectIntl(".concat(getDisplayName(WrappedComponent), ")");
|
|
27
|
+
WithIntl.WrappedComponent = WrappedComponent;
|
|
28
|
+
if (forwardRef) {
|
|
29
|
+
return (0, hoist_non_react_statics_1.default)(React.forwardRef(function (props, ref) { return (React.createElement(WithIntl, tslib_1.__assign({}, props, { forwardedRef: ref }))); }), WrappedComponent);
|
|
30
|
+
}
|
|
31
|
+
return (0, hoist_non_react_statics_1.default)(WithIntl, WrappedComponent);
|
|
32
|
+
}
|
|
33
|
+
exports.default = injectIntl;
|
|
@@ -0,0 +1,12 @@
|
|
|
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 | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | React.ReactPortal | Date | FormatXMLElementFn<React.ReactNode, React.ReactNode> | null | undefined>>>;
|
|
11
|
+
export default MemoizedFormattedMessage;
|
|
12
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2015, Yahoo Inc.
|
|
4
|
+
* Copyrights licensed under the New BSD License.
|
|
5
|
+
* See the accompanying LICENSE file for terms.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
var tslib_1 = require("tslib");
|
|
9
|
+
var React = tslib_1.__importStar(require("react"));
|
|
10
|
+
var useIntl_1 = tslib_1.__importDefault(require("./useIntl"));
|
|
11
|
+
var utils_1 = require("../utils");
|
|
12
|
+
function areEqual(prevProps, nextProps) {
|
|
13
|
+
var values = prevProps.values, otherProps = tslib_1.__rest(prevProps, ["values"]);
|
|
14
|
+
var nextValues = nextProps.values, nextOtherProps = tslib_1.__rest(nextProps, ["values"]);
|
|
15
|
+
return ((0, utils_1.shallowEqual)(nextValues, values) &&
|
|
16
|
+
(0, utils_1.shallowEqual)(otherProps, nextOtherProps));
|
|
17
|
+
}
|
|
18
|
+
function FormattedMessage(props) {
|
|
19
|
+
var intl = (0, useIntl_1.default)();
|
|
20
|
+
var formatMessage = intl.formatMessage, _a = intl.textComponent, Text = _a === void 0 ? React.Fragment : _a;
|
|
21
|
+
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;
|
|
22
|
+
var descriptor = { id: id, description: description, defaultMessage: defaultMessage };
|
|
23
|
+
var nodes = formatMessage(descriptor, values, {
|
|
24
|
+
ignoreTag: ignoreTag,
|
|
25
|
+
});
|
|
26
|
+
if (typeof children === 'function') {
|
|
27
|
+
return children(Array.isArray(nodes) ? nodes : [nodes]);
|
|
28
|
+
}
|
|
29
|
+
if (Component) {
|
|
30
|
+
return React.createElement(Component, null, React.Children.toArray(nodes));
|
|
31
|
+
}
|
|
32
|
+
return React.createElement(React.Fragment, null, nodes);
|
|
33
|
+
}
|
|
34
|
+
FormattedMessage.displayName = 'FormattedMessage';
|
|
35
|
+
var MemoizedFormattedMessage = React.memo(FormattedMessage, areEqual);
|
|
36
|
+
MemoizedFormattedMessage.displayName = 'MemoizedFormattedMessage';
|
|
37
|
+
exports.default = MemoizedFormattedMessage;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2015, Yahoo Inc.
|
|
4
|
+
* Copyrights licensed under the New BSD License.
|
|
5
|
+
* See the accompanying LICENSE file for terms.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
var tslib_1 = require("tslib");
|
|
9
|
+
var React = tslib_1.__importStar(require("react"));
|
|
10
|
+
var useIntl_1 = tslib_1.__importDefault(require("./useIntl"));
|
|
11
|
+
var FormattedPlural = function (props) {
|
|
12
|
+
var _a = (0, useIntl_1.default)(), formatPlural = _a.formatPlural, Text = _a.textComponent;
|
|
13
|
+
var value = props.value, other = props.other, children = props.children;
|
|
14
|
+
var pluralCategory = formatPlural(value, props);
|
|
15
|
+
var formattedPlural = props[pluralCategory] || other;
|
|
16
|
+
if (typeof children === 'function') {
|
|
17
|
+
return children(formattedPlural);
|
|
18
|
+
}
|
|
19
|
+
if (Text) {
|
|
20
|
+
return React.createElement(Text, null, formattedPlural);
|
|
21
|
+
}
|
|
22
|
+
// Work around @types/react where React.FC cannot return string
|
|
23
|
+
return formattedPlural;
|
|
24
|
+
};
|
|
25
|
+
FormattedPlural.defaultProps = {
|
|
26
|
+
type: 'cardinal',
|
|
27
|
+
};
|
|
28
|
+
FormattedPlural.displayName = 'FormattedPlural';
|
|
29
|
+
exports.default = FormattedPlural;
|
|
@@ -0,0 +1,35 @@
|
|
|
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, "onError" | "timeZone" | "fallbackOnEmptyString" | "formats" | "messages" | "defaultLocale" | "defaultFormats" | "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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["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,CAwCV,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"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2015, Yahoo Inc.
|
|
4
|
+
* Copyrights licensed under the New BSD License.
|
|
5
|
+
* See the accompanying LICENSE file for terms.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.createIntl = void 0;
|
|
9
|
+
var tslib_1 = require("tslib");
|
|
10
|
+
var React = tslib_1.__importStar(require("react"));
|
|
11
|
+
var injectIntl_1 = require("./injectIntl");
|
|
12
|
+
var utils_1 = require("../utils");
|
|
13
|
+
var intl_1 = require("@formatjs/intl");
|
|
14
|
+
var intl_messageformat_1 = require("intl-messageformat");
|
|
15
|
+
function processIntlConfig(config) {
|
|
16
|
+
return {
|
|
17
|
+
locale: config.locale,
|
|
18
|
+
timeZone: config.timeZone,
|
|
19
|
+
fallbackOnEmptyString: config.fallbackOnEmptyString,
|
|
20
|
+
formats: config.formats,
|
|
21
|
+
textComponent: config.textComponent,
|
|
22
|
+
messages: config.messages,
|
|
23
|
+
defaultLocale: config.defaultLocale,
|
|
24
|
+
defaultFormats: config.defaultFormats,
|
|
25
|
+
onError: config.onError,
|
|
26
|
+
onWarn: config.onWarn,
|
|
27
|
+
wrapRichTextChunksInFragment: config.wrapRichTextChunksInFragment,
|
|
28
|
+
defaultRichTextElements: config.defaultRichTextElements,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function assignUniqueKeysToFormatXMLElementFnArgument(values) {
|
|
32
|
+
if (!values) {
|
|
33
|
+
return values;
|
|
34
|
+
}
|
|
35
|
+
return Object.keys(values).reduce(function (acc, k) {
|
|
36
|
+
var v = values[k];
|
|
37
|
+
acc[k] = (0, intl_messageformat_1.isFormatXMLElementFn)(v)
|
|
38
|
+
? (0, utils_1.assignUniqueKeysToParts)(v)
|
|
39
|
+
: v;
|
|
40
|
+
return acc;
|
|
41
|
+
}, {});
|
|
42
|
+
}
|
|
43
|
+
var formatMessage = function (config, formatters, descriptor, rawValues) {
|
|
44
|
+
var rest = [];
|
|
45
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
|
46
|
+
rest[_i - 4] = arguments[_i];
|
|
47
|
+
}
|
|
48
|
+
var values = assignUniqueKeysToFormatXMLElementFnArgument(rawValues);
|
|
49
|
+
var chunks = intl_1.formatMessage.apply(void 0, tslib_1.__spreadArray([config,
|
|
50
|
+
formatters,
|
|
51
|
+
descriptor,
|
|
52
|
+
values], rest, false));
|
|
53
|
+
if (Array.isArray(chunks)) {
|
|
54
|
+
return React.Children.toArray(chunks);
|
|
55
|
+
}
|
|
56
|
+
return chunks;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Create intl object
|
|
60
|
+
* @param config intl config
|
|
61
|
+
* @param cache cache for formatter instances to prevent memory leak
|
|
62
|
+
*/
|
|
63
|
+
var createIntl = function (_a, cache) {
|
|
64
|
+
var rawDefaultRichTextElements = _a.defaultRichTextElements, config = tslib_1.__rest(_a, ["defaultRichTextElements"]);
|
|
65
|
+
var defaultRichTextElements = assignUniqueKeysToFormatXMLElementFnArgument(rawDefaultRichTextElements);
|
|
66
|
+
var coreIntl = (0, intl_1.createIntl)(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, utils_1.DEFAULT_INTL_CONFIG), config), { defaultRichTextElements: defaultRichTextElements }), cache);
|
|
67
|
+
var resolvedConfig = {
|
|
68
|
+
locale: coreIntl.locale,
|
|
69
|
+
timeZone: coreIntl.timeZone,
|
|
70
|
+
fallbackOnEmptyString: coreIntl.fallbackOnEmptyString,
|
|
71
|
+
formats: coreIntl.formats,
|
|
72
|
+
defaultLocale: coreIntl.defaultLocale,
|
|
73
|
+
defaultFormats: coreIntl.defaultFormats,
|
|
74
|
+
messages: coreIntl.messages,
|
|
75
|
+
onError: coreIntl.onError,
|
|
76
|
+
defaultRichTextElements: defaultRichTextElements,
|
|
77
|
+
};
|
|
78
|
+
return tslib_1.__assign(tslib_1.__assign({}, coreIntl), {
|
|
79
|
+
// @ts-expect-error fix this
|
|
80
|
+
formatMessage: formatMessage.bind(null, resolvedConfig, coreIntl.formatters),
|
|
81
|
+
// @ts-expect-error fix this
|
|
82
|
+
$t: formatMessage.bind(null, resolvedConfig, coreIntl.formatters) });
|
|
83
|
+
};
|
|
84
|
+
exports.createIntl = createIntl;
|
|
85
|
+
var IntlProvider = /** @class */ (function (_super) {
|
|
86
|
+
tslib_1.__extends(IntlProvider, _super);
|
|
87
|
+
function IntlProvider() {
|
|
88
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
89
|
+
_this.cache = (0, intl_1.createIntlCache)();
|
|
90
|
+
_this.state = {
|
|
91
|
+
cache: _this.cache,
|
|
92
|
+
intl: (0, exports.createIntl)(processIntlConfig(_this.props), _this.cache),
|
|
93
|
+
prevConfig: processIntlConfig(_this.props),
|
|
94
|
+
};
|
|
95
|
+
return _this;
|
|
96
|
+
}
|
|
97
|
+
IntlProvider.getDerivedStateFromProps = function (props, _a) {
|
|
98
|
+
var prevConfig = _a.prevConfig, cache = _a.cache;
|
|
99
|
+
var config = processIntlConfig(props);
|
|
100
|
+
if (!(0, utils_1.shallowEqual)(prevConfig, config)) {
|
|
101
|
+
return {
|
|
102
|
+
intl: (0, exports.createIntl)(config, cache),
|
|
103
|
+
prevConfig: config,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
};
|
|
108
|
+
IntlProvider.prototype.render = function () {
|
|
109
|
+
(0, utils_1.invariantIntlContext)(this.state.intl);
|
|
110
|
+
return React.createElement(injectIntl_1.Provider, { value: this.state.intl }, this.props.children);
|
|
111
|
+
};
|
|
112
|
+
IntlProvider.displayName = 'IntlProvider';
|
|
113
|
+
IntlProvider.defaultProps = utils_1.DEFAULT_INTL_CONFIG;
|
|
114
|
+
return IntlProvider;
|
|
115
|
+
}(React.PureComponent));
|
|
116
|
+
exports.default = IntlProvider;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relative.d.ts","sourceRoot":"","sources":["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"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2015, Yahoo Inc.
|
|
6
|
+
* Copyrights licensed under the New BSD License.
|
|
7
|
+
* See the accompanying LICENSE file for terms.
|
|
8
|
+
*/
|
|
9
|
+
var React = tslib_1.__importStar(require("react"));
|
|
10
|
+
var ecma402_abstract_1 = require("@formatjs/ecma402-abstract");
|
|
11
|
+
var useIntl_1 = tslib_1.__importDefault(require("./useIntl"));
|
|
12
|
+
var MINUTE = 60;
|
|
13
|
+
var HOUR = 60 * 60;
|
|
14
|
+
var DAY = 60 * 60 * 24;
|
|
15
|
+
function selectUnit(seconds) {
|
|
16
|
+
var absValue = Math.abs(seconds);
|
|
17
|
+
if (absValue < MINUTE) {
|
|
18
|
+
return 'second';
|
|
19
|
+
}
|
|
20
|
+
if (absValue < HOUR) {
|
|
21
|
+
return 'minute';
|
|
22
|
+
}
|
|
23
|
+
if (absValue < DAY) {
|
|
24
|
+
return 'hour';
|
|
25
|
+
}
|
|
26
|
+
return 'day';
|
|
27
|
+
}
|
|
28
|
+
function getDurationInSeconds(unit) {
|
|
29
|
+
switch (unit) {
|
|
30
|
+
case 'second':
|
|
31
|
+
return 1;
|
|
32
|
+
case 'minute':
|
|
33
|
+
return MINUTE;
|
|
34
|
+
case 'hour':
|
|
35
|
+
return HOUR;
|
|
36
|
+
default:
|
|
37
|
+
return DAY;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function valueToSeconds(value, unit) {
|
|
41
|
+
if (!value) {
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
switch (unit) {
|
|
45
|
+
case 'second':
|
|
46
|
+
return value;
|
|
47
|
+
case 'minute':
|
|
48
|
+
return value * MINUTE;
|
|
49
|
+
default:
|
|
50
|
+
return value * HOUR;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var INCREMENTABLE_UNITS = [
|
|
54
|
+
'second',
|
|
55
|
+
'minute',
|
|
56
|
+
'hour',
|
|
57
|
+
];
|
|
58
|
+
function canIncrement(unit) {
|
|
59
|
+
if (unit === void 0) { unit = 'second'; }
|
|
60
|
+
return INCREMENTABLE_UNITS.indexOf(unit) > -1;
|
|
61
|
+
}
|
|
62
|
+
var SimpleFormattedRelativeTime = function (props) {
|
|
63
|
+
var _a = (0, useIntl_1.default)(), formatRelativeTime = _a.formatRelativeTime, Text = _a.textComponent;
|
|
64
|
+
var children = props.children, value = props.value, unit = props.unit, otherProps = tslib_1.__rest(props, ["children", "value", "unit"]);
|
|
65
|
+
var formattedRelativeTime = formatRelativeTime(value || 0, unit, otherProps);
|
|
66
|
+
if (typeof children === 'function') {
|
|
67
|
+
return children(formattedRelativeTime);
|
|
68
|
+
}
|
|
69
|
+
if (Text) {
|
|
70
|
+
return React.createElement(Text, null, formattedRelativeTime);
|
|
71
|
+
}
|
|
72
|
+
return React.createElement(React.Fragment, null, formattedRelativeTime);
|
|
73
|
+
};
|
|
74
|
+
var FormattedRelativeTime = function (_a) {
|
|
75
|
+
var value = _a.value, unit = _a.unit, updateIntervalInSeconds = _a.updateIntervalInSeconds, otherProps = tslib_1.__rest(_a, ["value", "unit", "updateIntervalInSeconds"]);
|
|
76
|
+
(0, ecma402_abstract_1.invariant)(!updateIntervalInSeconds ||
|
|
77
|
+
!!(updateIntervalInSeconds && canIncrement(unit)), 'Cannot schedule update with unit longer than hour');
|
|
78
|
+
var _b = React.useState(), prevUnit = _b[0], setPrevUnit = _b[1];
|
|
79
|
+
var _c = React.useState(0), prevValue = _c[0], setPrevValue = _c[1];
|
|
80
|
+
var _d = React.useState(0), currentValueInSeconds = _d[0], setCurrentValueInSeconds = _d[1];
|
|
81
|
+
var updateTimer;
|
|
82
|
+
if (unit !== prevUnit || value !== prevValue) {
|
|
83
|
+
setPrevValue(value || 0);
|
|
84
|
+
setPrevUnit(unit);
|
|
85
|
+
setCurrentValueInSeconds(canIncrement(unit) ? valueToSeconds(value, unit) : 0);
|
|
86
|
+
}
|
|
87
|
+
React.useEffect(function () {
|
|
88
|
+
function clearUpdateTimer() {
|
|
89
|
+
clearTimeout(updateTimer);
|
|
90
|
+
}
|
|
91
|
+
clearUpdateTimer();
|
|
92
|
+
// If there's no interval and we cannot increment this unit, do nothing
|
|
93
|
+
if (!updateIntervalInSeconds || !canIncrement(unit)) {
|
|
94
|
+
return clearUpdateTimer;
|
|
95
|
+
}
|
|
96
|
+
// Figure out the next interesting time
|
|
97
|
+
var nextValueInSeconds = currentValueInSeconds - updateIntervalInSeconds;
|
|
98
|
+
var nextUnit = selectUnit(nextValueInSeconds);
|
|
99
|
+
// We've reached the max auto incrementable unit, don't schedule another update
|
|
100
|
+
if (nextUnit === 'day') {
|
|
101
|
+
return clearUpdateTimer;
|
|
102
|
+
}
|
|
103
|
+
var unitDuration = getDurationInSeconds(nextUnit);
|
|
104
|
+
var remainder = nextValueInSeconds % unitDuration;
|
|
105
|
+
var prevInterestingValueInSeconds = nextValueInSeconds - remainder;
|
|
106
|
+
var nextInterestingValueInSeconds = prevInterestingValueInSeconds >= currentValueInSeconds
|
|
107
|
+
? prevInterestingValueInSeconds - unitDuration
|
|
108
|
+
: prevInterestingValueInSeconds;
|
|
109
|
+
var delayInSeconds = Math.abs(nextInterestingValueInSeconds - currentValueInSeconds);
|
|
110
|
+
if (currentValueInSeconds !== nextInterestingValueInSeconds) {
|
|
111
|
+
updateTimer = setTimeout(function () { return setCurrentValueInSeconds(nextInterestingValueInSeconds); }, delayInSeconds * 1e3);
|
|
112
|
+
}
|
|
113
|
+
return clearUpdateTimer;
|
|
114
|
+
}, [currentValueInSeconds, updateIntervalInSeconds, unit]);
|
|
115
|
+
var currentValue = value || 0;
|
|
116
|
+
var currentUnit = unit;
|
|
117
|
+
if (canIncrement(unit) &&
|
|
118
|
+
typeof currentValueInSeconds === 'number' &&
|
|
119
|
+
updateIntervalInSeconds) {
|
|
120
|
+
currentUnit = selectUnit(currentValueInSeconds);
|
|
121
|
+
var unitDuration = getDurationInSeconds(currentUnit);
|
|
122
|
+
currentValue = Math.round(currentValueInSeconds / unitDuration);
|
|
123
|
+
}
|
|
124
|
+
return (React.createElement(SimpleFormattedRelativeTime, tslib_1.__assign({ value: currentValue, unit: currentUnit }, otherProps)));
|
|
125
|
+
};
|
|
126
|
+
FormattedRelativeTime.displayName = 'FormattedRelativeTime';
|
|
127
|
+
FormattedRelativeTime.defaultProps = {
|
|
128
|
+
value: 0,
|
|
129
|
+
unit: 'second',
|
|
130
|
+
};
|
|
131
|
+
exports.default = FormattedRelativeTime;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntl.d.ts","sourceRoot":"","sources":["useIntl.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAElC,MAAM,CAAC,OAAO,UAAU,OAAO,IAAI,SAAS,CAI3C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var React = tslib_1.__importStar(require("react"));
|
|
5
|
+
var injectIntl_1 = require("./injectIntl");
|
|
6
|
+
var utils_1 = require("../utils");
|
|
7
|
+
function useIntl() {
|
|
8
|
+
var intl = React.useContext(injectIntl_1.Context);
|
|
9
|
+
(0, utils_1.invariantIntlContext)(intl);
|
|
10
|
+
return intl;
|
|
11
|
+
}
|
|
12
|
+
exports.default = useIntl;
|