@discord/intl 0.2.2-canary.6898c23 → 0.2.2-canary.96b50b6

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.
@@ -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
@@ -21,7 +21,7 @@ export type * from './types.d.ts';
21
21
  * intl message, even if the actual value comes from elsewhere (like a
22
22
  * user-generated string).
23
23
  */
24
- export type ReactIntlMessage = string | React.ReactElement;
24
+ export type ReactIntlMessage = string | React.ReactElement | Array<string | React.ReactElement>;
25
25
  /**
26
26
  * The return value of `formatToParts` from `@discord/intl`, this type
27
27
  * represents any AST structure for a message rendered using this system.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl",
3
- "version": "0.2.2-canary.6898c23",
3
+ "version": "0.2.2-canary.96b50b6",
4
4
  "license": "MIT",
5
5
  "description": "Client runtime for managing messages and translations in a React project.",
6
6
  "main": "./dist/index.js",
@@ -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
@@ -29,7 +29,7 @@ export type * from './types.d.ts';
29
29
  * user-generated string).
30
30
  */
31
31
  // TODO: Replace this with ReactIntlMessage from `formatters/react`.
32
- export type ReactIntlMessage = string | React.ReactElement;
32
+ export type ReactIntlMessage = string | React.ReactElement | Array<string | React.ReactElement>;
33
33
 
34
34
  /**
35
35
  * The return value of `formatToParts` from `@discord/intl`, this type