@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.
@@ -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 = "emphasis",
12
- Strikethrough = "strikethrough",
13
- Code = "code",
11
+ Emphasis = "em",
12
+ Strikethrough = "s",
13
+ Code = "inlineCode",
14
14
  Link = "link",
15
15
  Paragraph = "paragraph",
16
16
  /**
@@ -50,9 +50,9 @@ var RichTextNodeType;
50
50
  (function (RichTextNodeType) {
51
51
  RichTextNodeType["Text"] = "text";
52
52
  RichTextNodeType["Strong"] = "strong";
53
- RichTextNodeType["Emphasis"] = "emphasis";
54
- RichTextNodeType["Strikethrough"] = "strikethrough";
55
- RichTextNodeType["Code"] = "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<{}, typeof React.Fragment & {
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
@@ -94,10 +94,10 @@ function createReactBuilder(richTextElements) {
94
94
  }
95
95
  function formatReact(message, values, Builder) {
96
96
  if (typeof message === 'string') {
97
- return React.createElement(React.Fragment, undefined, message);
97
+ return [message];
98
98
  }
99
99
  var parts = this.bindFormatValues(Builder, message, values);
100
- return React.createElement(React.Fragment, undefined, parts);
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");
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "license": "MIT",
5
5
  "description": "Client runtime for managing messages and translations in a React project.",
6
6
  "main": "./dist/index.js",
@@ -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 = 'emphasis',
24
- Strikethrough = 'strikethrough',
25
- Code = 'code',
23
+ Emphasis = 'em',
24
+ Strikethrough = 's',
25
+ Code = 'inlineCode',
26
26
  Link = 'link',
27
27
  Paragraph = 'paragraph',
28
28
  /**
@@ -5,5 +5,6 @@ export {
5
5
  makeReactFormatter,
6
6
  DEFAULT_REACT_RICH_TEXT_ELEMENTS,
7
7
  type ReactFunctionTypes,
8
+ ReactIntlMessage,
8
9
  } from './react';
9
10
  export { stringFormatter, type StringFunctionTypes } from './string';
@@ -71,10 +71,9 @@ function createReactBuilder(richTextElements: RichTextFormattingMap<ReactFunctio
71
71
  };
72
72
  }
73
73
 
74
- export type ReactIntlMessage = React.ReactElement<
75
- {},
76
- typeof React.Fragment & { __brand: 'discord-intl' }
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 React.createElement(React.Fragment, undefined, message) as ReactIntlMessage;
85
+ return [message] as ReactIntlMessage;
87
86
  }
88
87
 
89
88
  const parts = this.bindFormatValues(Builder, message, values);
90
- return React.createElement(React.Fragment, undefined, parts) as ReactIntlMessage;
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
@@ -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,