@discord/intl 0.2.2 → 0.4.0
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/dist/formatters/ast.d.ts +3 -3
- package/dist/formatters/ast.js +3 -3
- package/dist/formatters/index.d.ts +1 -1
- package/dist/formatters/react.d.ts +2 -2
- package/dist/formatters/react.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/dist/intl-manager.js +0 -1
- package/package.json +1 -1
- package/src/formatters/ast.ts +3 -3
- package/src/formatters/index.ts +1 -0
- package/src/formatters/react.ts +5 -6
- package/src/index.ts +2 -1
- package/src/intl-manager.ts +0 -1
package/dist/formatters/ast.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ export type AstFunctionTypes = FunctionTypes<RichTextNode, object>;
|
|
|
8
8
|
export declare enum RichTextNodeType {
|
|
9
9
|
Text = "text",
|
|
10
10
|
Strong = "strong",
|
|
11
|
-
Emphasis = "
|
|
12
|
-
Strikethrough = "
|
|
13
|
-
Code = "
|
|
11
|
+
Emphasis = "em",
|
|
12
|
+
Strikethrough = "s",
|
|
13
|
+
Code = "inlineCode",
|
|
14
14
|
Link = "link",
|
|
15
15
|
Paragraph = "paragraph",
|
|
16
16
|
/**
|
package/dist/formatters/ast.js
CHANGED
|
@@ -50,9 +50,9 @@ var RichTextNodeType;
|
|
|
50
50
|
(function (RichTextNodeType) {
|
|
51
51
|
RichTextNodeType["Text"] = "text";
|
|
52
52
|
RichTextNodeType["Strong"] = "strong";
|
|
53
|
-
RichTextNodeType["Emphasis"] = "
|
|
54
|
-
RichTextNodeType["Strikethrough"] = "
|
|
55
|
-
RichTextNodeType["Code"] = "
|
|
53
|
+
RichTextNodeType["Emphasis"] = "em";
|
|
54
|
+
RichTextNodeType["Strikethrough"] = "s";
|
|
55
|
+
RichTextNodeType["Code"] = "inlineCode";
|
|
56
56
|
RichTextNodeType["Link"] = "link";
|
|
57
57
|
RichTextNodeType["Paragraph"] = "paragraph";
|
|
58
58
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { astFormatter, type AstFunctionTypes, type RichTextNode, RichTextNodeType } from './ast';
|
|
2
2
|
export { markdownFormatter, type MarkdownFunctionTypes } from './markdown';
|
|
3
|
-
export { reactFormatter, makeReactFormatter, DEFAULT_REACT_RICH_TEXT_ELEMENTS, type ReactFunctionTypes, } from './react';
|
|
3
|
+
export { reactFormatter, makeReactFormatter, DEFAULT_REACT_RICH_TEXT_ELEMENTS, type ReactFunctionTypes, ReactIntlMessage, } from './react';
|
|
4
4
|
export { stringFormatter, type StringFunctionTypes } from './string';
|
|
@@ -18,9 +18,9 @@ export type ReactFunctionTypes = FunctionTypes<React.ReactNode, ReactClickHandle
|
|
|
18
18
|
onContextMenu: ReactClickHandler;
|
|
19
19
|
}>;
|
|
20
20
|
export declare const DEFAULT_REACT_RICH_TEXT_ELEMENTS: RichTextFormattingMap<ReactFunctionTypes['hook']>;
|
|
21
|
-
export type ReactIntlMessage = React.ReactElement
|
|
21
|
+
export type ReactIntlMessage = Array<React.ReactElement | string> & {
|
|
22
22
|
__brand: 'discord-intl';
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
export declare function formatReact(this: IntlManager, message: AnyIntlMessage, values: object, Builder: FormatBuilderConstructor<React.ReactElement>): ReactIntlMessage;
|
|
25
25
|
/**
|
|
26
26
|
* Create a new React formatter with the given rich text elements replacing the defaults. Use this
|
package/dist/formatters/react.js
CHANGED
|
@@ -94,10 +94,10 @@ function createReactBuilder(richTextElements) {
|
|
|
94
94
|
}
|
|
95
95
|
function formatReact(message, values, Builder) {
|
|
96
96
|
if (typeof message === 'string') {
|
|
97
|
-
return
|
|
97
|
+
return [message];
|
|
98
98
|
}
|
|
99
99
|
var parts = this.bindFormatValues(Builder, message, values);
|
|
100
|
-
return
|
|
100
|
+
return parts;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Create a new React formatter with the given rich text elements replacing the defaults. Use this
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { RichTextNode } from './formatters';
|
|
3
3
|
export * from './formatters';
|
|
4
|
+
export { FormatBuilder, FormatBuilderConstructor, bindFormatValues } from './format';
|
|
4
5
|
export { runtimeHashMessageKey } from './hash';
|
|
5
6
|
export { IntlManager, DEFAULT_LOCALE, type FormatFunction } from './intl-manager';
|
|
6
7
|
export { createLoader, loadAllMessagesInLocale, waitForAllDefaultIntlMessagesLoaded, MessageLoader, } from './message-loader';
|
|
@@ -20,7 +21,7 @@ export type * from './types.d.ts';
|
|
|
20
21
|
* intl message, even if the actual value comes from elsewhere (like a
|
|
21
22
|
* user-generated string).
|
|
22
23
|
*/
|
|
23
|
-
export type ReactIntlMessage = string | React.ReactElement
|
|
24
|
+
export type ReactIntlMessage = string | React.ReactElement | Array<string | React.ReactElement>;
|
|
24
25
|
/**
|
|
25
26
|
* The return value of `formatToParts` from `@discord/intl`, this type
|
|
26
27
|
* represents any AST structure for a message rendered using this system.
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.MessageLoader = exports.waitForAllDefaultIntlMessagesLoaded = exports.loadAllMessagesInLocale = exports.createLoader = exports.DEFAULT_LOCALE = exports.IntlManager = exports.runtimeHashMessageKey = void 0;
|
|
17
|
+
exports.MessageLoader = exports.waitForAllDefaultIntlMessagesLoaded = exports.loadAllMessagesInLocale = exports.createLoader = exports.DEFAULT_LOCALE = exports.IntlManager = exports.runtimeHashMessageKey = exports.bindFormatValues = exports.FormatBuilder = void 0;
|
|
18
18
|
__exportStar(require("./formatters"), exports);
|
|
19
|
+
var format_1 = require("./format");
|
|
20
|
+
Object.defineProperty(exports, "FormatBuilder", { enumerable: true, get: function () { return format_1.FormatBuilder; } });
|
|
21
|
+
Object.defineProperty(exports, "bindFormatValues", { enumerable: true, get: function () { return format_1.bindFormatValues; } });
|
|
19
22
|
var hash_1 = require("./hash");
|
|
20
23
|
Object.defineProperty(exports, "runtimeHashMessageKey", { enumerable: true, get: function () { return hash_1.runtimeHashMessageKey; } });
|
|
21
24
|
var intl_manager_1 = require("./intl-manager");
|
package/dist/intl-manager.js
CHANGED
|
@@ -49,7 +49,6 @@ var IntlManager = /** @class */ (function () {
|
|
|
49
49
|
};
|
|
50
50
|
this.defaultLocale = defaultLocale;
|
|
51
51
|
this.currentLocale = defaultLocale;
|
|
52
|
-
console.log(intl_messageformat_1.IntlMessageFormat.formats);
|
|
53
52
|
this.intl = (0, intl_1.createIntl)({
|
|
54
53
|
formats: intl_messageformat_1.IntlMessageFormat.formats,
|
|
55
54
|
defaultLocale: defaultLocale,
|
package/package.json
CHANGED
package/src/formatters/ast.ts
CHANGED
|
@@ -20,9 +20,9 @@ export type AstFunctionTypes = FunctionTypes<RichTextNode, object>;
|
|
|
20
20
|
export enum RichTextNodeType {
|
|
21
21
|
Text = 'text',
|
|
22
22
|
Strong = 'strong',
|
|
23
|
-
Emphasis = '
|
|
24
|
-
Strikethrough = '
|
|
25
|
-
Code = '
|
|
23
|
+
Emphasis = 'em',
|
|
24
|
+
Strikethrough = 's',
|
|
25
|
+
Code = 'inlineCode',
|
|
26
26
|
Link = 'link',
|
|
27
27
|
Paragraph = 'paragraph',
|
|
28
28
|
/**
|
package/src/formatters/index.ts
CHANGED
package/src/formatters/react.ts
CHANGED
|
@@ -71,10 +71,9 @@ function createReactBuilder(richTextElements: RichTextFormattingMap<ReactFunctio
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
>;
|
|
74
|
+
// This is explicitly `ReactElement | string` and _not_ `ReactNode`, because nullish values and any
|
|
75
|
+
// other type that ReactNode accepts (boolean, number, etc.) are _not_ valid children of a message.
|
|
76
|
+
export type ReactIntlMessage = Array<React.ReactElement | string> & { __brand: 'discord-intl' };
|
|
78
77
|
|
|
79
78
|
export function formatReact(
|
|
80
79
|
this: IntlManager,
|
|
@@ -83,11 +82,11 @@ export function formatReact(
|
|
|
83
82
|
Builder: FormatBuilderConstructor<React.ReactElement>,
|
|
84
83
|
): ReactIntlMessage {
|
|
85
84
|
if (typeof message === 'string') {
|
|
86
|
-
return
|
|
85
|
+
return [message] as ReactIntlMessage;
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
const parts = this.bindFormatValues(Builder, message, values);
|
|
90
|
-
return
|
|
89
|
+
return parts as ReactIntlMessage;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
/**
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { RichTextNode } from './formatters';
|
|
3
3
|
|
|
4
4
|
export * from './formatters';
|
|
5
|
+
export { FormatBuilder, FormatBuilderConstructor, bindFormatValues } from './format';
|
|
5
6
|
export { runtimeHashMessageKey } from './hash';
|
|
6
7
|
export { IntlManager, DEFAULT_LOCALE, type FormatFunction } from './intl-manager';
|
|
7
8
|
export {
|
|
@@ -28,7 +29,7 @@ export type * from './types.d.ts';
|
|
|
28
29
|
* user-generated string).
|
|
29
30
|
*/
|
|
30
31
|
// TODO: Replace this with ReactIntlMessage from `formatters/react`.
|
|
31
|
-
export type ReactIntlMessage = string | React.ReactElement
|
|
32
|
+
export type ReactIntlMessage = string | React.ReactElement | Array<string | React.ReactElement>;
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* The return value of `formatToParts` from `@discord/intl`, this type
|
package/src/intl-manager.ts
CHANGED
|
@@ -47,7 +47,6 @@ export class IntlManager {
|
|
|
47
47
|
constructor(defaultLocale: string = DEFAULT_LOCALE) {
|
|
48
48
|
this.defaultLocale = defaultLocale;
|
|
49
49
|
this.currentLocale = defaultLocale;
|
|
50
|
-
console.log(IntlMessageFormat.formats);
|
|
51
50
|
this.intl = createIntl({
|
|
52
51
|
formats: IntlMessageFormat.formats,
|
|
53
52
|
defaultLocale,
|