@discord/intl 0.2.1-canary.3ae7479 → 0.2.1-rc.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.
@@ -65,6 +65,14 @@ var RichTextNodeType;
65
65
  */
66
66
  RichTextNodeType["Object"] = "object";
67
67
  })(RichTextNodeType || (exports.RichTextNodeType = RichTextNodeType = {}));
68
+ var RICH_TEXT_TAG_TYPES = {
69
+ $_: RichTextNodeType.Text,
70
+ $b: RichTextNodeType.Strong,
71
+ $i: RichTextNodeType.Emphasis,
72
+ $code: RichTextNodeType.Code,
73
+ $link: RichTextNodeType.Link,
74
+ $p: RichTextNodeType.Paragraph,
75
+ };
68
76
  var AST_RICH_TEXT_ELEMENTS = {
69
77
  $_: function () { return ({ type: RichTextNodeType.Text, content: '' }); },
70
78
  $b: function (content) { return ({ type: RichTextNodeType.Strong, content: content }); },
@@ -92,7 +100,7 @@ var AstBuilder = /** @class */ (function (_super) {
92
100
  if (!(tag in AST_RICH_TEXT_ELEMENTS)) {
93
101
  throw "".concat(tag, " is not a known rich text formatting tag");
94
102
  }
95
- var result = AST_RICH_TEXT_ELEMENTS[tag](children, 0);
103
+ var result = AST_RICH_TEXT_ELEMENTS[tag](children);
96
104
  if (Array.isArray(result)) {
97
105
  (_a = this.result).push.apply(_a, __spreadArray([], __read(result), false));
98
106
  }
@@ -62,7 +62,7 @@ var MarkdownBuilder = /** @class */ (function (_super) {
62
62
  return _this;
63
63
  }
64
64
  MarkdownBuilder.prototype.pushRichTextTag = function (tag, children) {
65
- this.result += MARKDOWN_RICH_TEXT_ELEMENTS[tag](children, 0);
65
+ this.result += MARKDOWN_RICH_TEXT_ELEMENTS[tag](children);
66
66
  };
67
67
  return MarkdownBuilder;
68
68
  }(string_1.StringBuilder));
@@ -48,15 +48,15 @@ var format_1 = require("../format");
48
48
  var h = React.createElement;
49
49
  exports.DEFAULT_REACT_RICH_TEXT_ELEMENTS = {
50
50
  $_: function () { return ''; },
51
- $b: function (content, key) { return h('strong', { key: key }, content); },
52
- $code: function (content, key) { return h('code', { key: key }, content); },
53
- $i: function (content, key) { return h('em', { key: key }, content); },
51
+ $b: function (content) { return h('strong', undefined, content); },
52
+ $code: function (content) { return h('code', undefined, content); },
53
+ $i: function (content) { return h('em', undefined, content); },
54
54
  // $link will always be [href, <empty>, ...content]
55
- $link: function (_a, key) {
55
+ $link: function (_a) {
56
56
  var _b = __read(_a), href = _b[0], content = _b.slice(1);
57
- return h('a', { href: href, key: key }, content);
57
+ return h('a', { href: href }, content);
58
58
  },
59
- $p: function (content, key) { return h('p', { key: key }, content); },
59
+ $p: function (content) { return h('p', undefined, content); },
60
60
  };
61
61
  /**
62
62
  * Creates a new `FormatBuilder` class that constructs a React element tree
@@ -70,12 +70,11 @@ function createReactBuilder(richTextElements) {
70
70
  __extends(class_1, _super);
71
71
  function class_1() {
72
72
  var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
73
- _this._nodeKey = 0;
74
73
  _this.result = [];
75
74
  return _this;
76
75
  }
77
76
  class_1.prototype.pushRichTextTag = function (tag, children) {
78
- this.result.push(richTextElements[tag](children, this._nodeKey++));
77
+ this.result.push(richTextElements[tag](children));
79
78
  };
80
79
  class_1.prototype.pushLiteralText = function (text) {
81
80
  this.result.push(text);
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { RichTextNode } from './formatters';
3
3
  export * from './formatters';
4
4
  export { IntlManager, DEFAULT_LOCALE, type FormatFunction } from './intl-manager';
5
- export { createLoader, loadAllMessagesInLocale, waitForAllDefaultIntlMessagesLoaded, MessageLoader, } from './message-loader';
5
+ export { createLoader, loadAllMessagesInLocale, waitForAllDefaultIntlMessagesLoaded, } from './message-loader';
6
6
  export type * from './types.d.ts';
7
7
  /**
8
8
  * A type representing any message that has been formatted using one of the
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ 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 = void 0;
17
+ exports.waitForAllDefaultIntlMessagesLoaded = exports.loadAllMessagesInLocale = exports.createLoader = exports.DEFAULT_LOCALE = exports.IntlManager = void 0;
18
18
  __exportStar(require("./formatters"), exports);
19
19
  var intl_manager_1 = require("./intl-manager");
20
20
  Object.defineProperty(exports, "IntlManager", { enumerable: true, get: function () { return intl_manager_1.IntlManager; } });
@@ -23,4 +23,3 @@ var message_loader_1 = require("./message-loader");
23
23
  Object.defineProperty(exports, "createLoader", { enumerable: true, get: function () { return message_loader_1.createLoader; } });
24
24
  Object.defineProperty(exports, "loadAllMessagesInLocale", { enumerable: true, get: function () { return message_loader_1.loadAllMessagesInLocale; } });
25
25
  Object.defineProperty(exports, "waitForAllDefaultIntlMessagesLoaded", { enumerable: true, get: function () { return message_loader_1.waitForAllDefaultIntlMessagesLoaded; } });
26
- Object.defineProperty(exports, "MessageLoader", { enumerable: true, get: function () { return message_loader_1.MessageLoader; } });
package/dist/types.d.ts CHANGED
@@ -198,8 +198,8 @@ export interface FunctionTypeMap {
198
198
  }
199
199
 
200
200
  export interface FunctionTypes<Result, HandlerType = (content: Result[]) => Result | Result[]> {
201
- link: undefined | ((content: Result[], key: number) => Result | Result[]);
202
- hook: undefined | ((content: Result[], key: number) => Result | Result[]);
201
+ link: undefined | ((content: Result[]) => Result | Result[]);
202
+ hook: undefined | ((content: Result[]) => Result | Result[]);
203
203
  handler: undefined | HandlerType;
204
204
  }
205
205
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl",
3
- "version": "0.2.1-canary.3ae7479",
3
+ "version": "0.2.1-rc.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",
@@ -36,6 +36,15 @@ export enum RichTextNodeType {
36
36
  Object = 'object',
37
37
  }
38
38
 
39
+ const RICH_TEXT_TAG_TYPES: Record<RichTextTagNames, RichTextNodeType> = {
40
+ $_: RichTextNodeType.Text,
41
+ $b: RichTextNodeType.Strong,
42
+ $i: RichTextNodeType.Emphasis,
43
+ $code: RichTextNodeType.Code,
44
+ $link: RichTextNodeType.Link,
45
+ $p: RichTextNodeType.Paragraph,
46
+ };
47
+
39
48
  interface RichTextNodeBase<ContentType> {
40
49
  type: RichTextNodeType;
41
50
  content: ContentType;
@@ -92,7 +101,7 @@ class AstBuilder extends FormatBuilder<RichTextNode> {
92
101
  if (!(tag in AST_RICH_TEXT_ELEMENTS)) {
93
102
  throw `${tag} is not a known rich text formatting tag`;
94
103
  }
95
- const result = AST_RICH_TEXT_ELEMENTS[tag](children, 0);
104
+ const result = AST_RICH_TEXT_ELEMENTS[tag](children);
96
105
  if (Array.isArray(result)) {
97
106
  this.result.push(...result);
98
107
  } else {
@@ -31,7 +31,7 @@ class MarkdownBuilder extends StringBuilder {
31
31
  result: string = '';
32
32
 
33
33
  pushRichTextTag(tag: RichTextTagNames, children: string[]) {
34
- this.result += MARKDOWN_RICH_TEXT_ELEMENTS[tag](children, 0);
34
+ this.result += MARKDOWN_RICH_TEXT_ELEMENTS[tag](children);
35
35
  }
36
36
  }
37
37
 
@@ -28,12 +28,12 @@ export type ReactFunctionTypes = FunctionTypes<
28
28
  const h = React.createElement;
29
29
  export const DEFAULT_REACT_RICH_TEXT_ELEMENTS: RichTextFormattingMap<ReactFunctionTypes['hook']> = {
30
30
  $_: () => '',
31
- $b: (content, key) => h('strong', { key }, content),
32
- $code: (content, key) => h('code', { key }, content),
33
- $i: (content, key) => h('em', { key }, content),
31
+ $b: (content) => h('strong', undefined, content),
32
+ $code: (content) => h('code', undefined, content),
33
+ $i: (content) => h('em', undefined, content),
34
34
  // $link will always be [href, <empty>, ...content]
35
- $link: ([href, ...content], key) => h('a', { href, key }, content),
36
- $p: (content, key) => h('p', { key }, content),
35
+ $link: ([href, ...content]) => h('a', { href }, content),
36
+ $p: (content) => h('p', undefined, content),
37
37
  };
38
38
 
39
39
  /**
@@ -47,11 +47,10 @@ function createReactBuilder(richTextElements: RichTextFormattingMap<ReactFunctio
47
47
  new (): FormatBuilder<React.ReactNode>;
48
48
  } {
49
49
  return class extends FormatBuilder<React.ReactNode> {
50
- _nodeKey: number = 0;
51
50
  result: React.ReactNode[] = [];
52
51
 
53
52
  pushRichTextTag(tag: RichTextTagNames, children: React.ReactNode[]) {
54
- this.result.push(richTextElements[tag](children, this._nodeKey++));
53
+ this.result.push(richTextElements[tag](children));
55
54
  }
56
55
 
57
56
  pushLiteralText(text: string) {
package/src/index.ts CHANGED
@@ -7,7 +7,6 @@ export {
7
7
  createLoader,
8
8
  loadAllMessagesInLocale,
9
9
  waitForAllDefaultIntlMessagesLoaded,
10
- MessageLoader,
11
10
  } from './message-loader';
12
11
  export type * from './types.d.ts';
13
12
 
package/src/types.d.ts CHANGED
@@ -198,8 +198,8 @@ export interface FunctionTypeMap {
198
198
  }
199
199
 
200
200
  export interface FunctionTypes<Result, HandlerType = (content: Result[]) => Result | Result[]> {
201
- link: undefined | ((content: Result[], key: number) => Result | Result[]);
202
- hook: undefined | ((content: Result[], key: number) => Result | Result[]);
201
+ link: undefined | ((content: Result[]) => Result | Result[]);
202
+ hook: undefined | ((content: Result[]) => Result | Result[]);
203
203
  handler: undefined | HandlerType;
204
204
  }
205
205