@lingui/react 4.0.0-next.4 → 4.0.0-next.5

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/index.cjs CHANGED
@@ -133,12 +133,14 @@ function Trans(props) {
133
133
  if (render === null || component === null) {
134
134
  return translation;
135
135
  }
136
- const FallbackComponent = defaultComponent || React.Fragment;
136
+ const FallbackComponent = defaultComponent || RenderFragment;
137
137
  const i18nProps = {
138
138
  id,
139
139
  message,
140
140
  translation,
141
- isTranslated: id !== translation && message !== translation
141
+ isTranslated: id !== translation && message !== translation,
142
+ children: translation
143
+ // for type-compatibility with `component` prop
142
144
  };
143
145
  if (render && component) {
144
146
  console.error(
@@ -152,15 +154,18 @@ function Trans(props) {
152
154
  console.error(
153
155
  `Invalid value supplied to prop \`component\`. It must be a React component, provided ${component}`
154
156
  );
155
- return /* @__PURE__ */ React.createElement(FallbackComponent, { ...i18nProps }, translation);
157
+ return React.createElement(FallbackComponent, i18nProps, translation);
156
158
  }
157
159
  if (typeof render === "function") {
158
160
  return render(i18nProps);
159
161
  }
160
162
  const Component = component || FallbackComponent;
161
- const DefaultComponent = defaultComponent;
162
- return DefaultComponent && !component ? /* @__PURE__ */ React.createElement(DefaultComponent, { ...i18nProps }, translation) : /* @__PURE__ */ React.createElement(Component, null, translation);
163
+ const RenderedComponent = defaultComponent && !component ? defaultComponent : Component;
164
+ return React.createElement(RenderedComponent, i18nProps, translation);
163
165
  }
166
+ const RenderFragment = ({ children }) => {
167
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
168
+ };
164
169
 
165
170
  exports.I18nProvider = I18nProvider;
166
171
  exports.LinguiContext = LinguiContext;
package/dist/index.d.ts CHANGED
@@ -2,12 +2,15 @@ import React, { ComponentType, FunctionComponent } from 'react';
2
2
  import { I18n } from '@lingui/core';
3
3
 
4
4
  type TransRenderProps = {
5
- id?: string;
6
- translation?: React.ReactNode;
7
- children?: React.ReactNode;
5
+ id: string;
6
+ translation: React.ReactNode;
7
+ children: React.ReactNode;
8
8
  message?: string | null;
9
- isTranslated?: boolean;
9
+ isTranslated: boolean;
10
10
  };
11
+ type MaximumOneOf<T, K extends keyof T = keyof T> = K extends keyof T ? {
12
+ [P in K]?: T[K];
13
+ } & Partial<Record<Exclude<keyof T, K>, never>> : never;
11
14
  type TransProps = {
12
15
  id: string;
13
16
  message?: string;
@@ -17,9 +20,10 @@ type TransProps = {
17
20
  };
18
21
  formats?: Record<string, unknown>;
19
22
  children?: React.ReactNode;
23
+ } & MaximumOneOf<{
20
24
  component?: React.ComponentType<TransRenderProps>;
21
25
  render?: (props: TransRenderProps) => React.ReactElement<any, any> | null;
22
- };
26
+ }>;
23
27
  declare function Trans(props: TransProps): React.ReactElement<any, any> | null;
24
28
 
25
29
  type I18nContext = {
package/dist/index.mjs CHANGED
@@ -131,12 +131,14 @@ function Trans(props) {
131
131
  if (render === null || component === null) {
132
132
  return translation;
133
133
  }
134
- const FallbackComponent = defaultComponent || React.Fragment;
134
+ const FallbackComponent = defaultComponent || RenderFragment;
135
135
  const i18nProps = {
136
136
  id,
137
137
  message,
138
138
  translation,
139
- isTranslated: id !== translation && message !== translation
139
+ isTranslated: id !== translation && message !== translation,
140
+ children: translation
141
+ // for type-compatibility with `component` prop
140
142
  };
141
143
  if (render && component) {
142
144
  console.error(
@@ -150,14 +152,17 @@ function Trans(props) {
150
152
  console.error(
151
153
  `Invalid value supplied to prop \`component\`. It must be a React component, provided ${component}`
152
154
  );
153
- return /* @__PURE__ */ React.createElement(FallbackComponent, { ...i18nProps }, translation);
155
+ return React.createElement(FallbackComponent, i18nProps, translation);
154
156
  }
155
157
  if (typeof render === "function") {
156
158
  return render(i18nProps);
157
159
  }
158
160
  const Component = component || FallbackComponent;
159
- const DefaultComponent = defaultComponent;
160
- return DefaultComponent && !component ? /* @__PURE__ */ React.createElement(DefaultComponent, { ...i18nProps }, translation) : /* @__PURE__ */ React.createElement(Component, null, translation);
161
+ const RenderedComponent = defaultComponent && !component ? defaultComponent : Component;
162
+ return React.createElement(RenderedComponent, i18nProps, translation);
161
163
  }
164
+ const RenderFragment = ({ children }) => {
165
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
166
+ };
162
167
 
163
168
  export { I18nProvider, LinguiContext, Trans, useLingui };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/react",
3
- "version": "4.0.0-next.4",
3
+ "version": "4.0.0-next.5",
4
4
  "sideEffects": false,
5
5
  "description": "React components for translations",
6
6
  "main": "./dist/index.cjs",
@@ -58,11 +58,14 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@babel/runtime": "^7.20.13",
61
- "@lingui/core": "^4.0.0-next.4"
61
+ "@lingui/core": "^4.0.0-next.5"
62
62
  },
63
63
  "devDependencies": {
64
+ "@lingui/jest-mocks": "^3.0.3",
64
65
  "@testing-library/react": "^11.0.4",
66
+ "react": "^17.0.2",
67
+ "react-dom": "^17.0.2",
65
68
  "unbuild": "^1.1.2"
66
69
  },
67
- "gitHead": "3b999e35d26e67dec7cf0591f794be782e11022c"
70
+ "gitHead": "bdbd6cf310cbcf09e1fe288f20ef530c28de481d"
68
71
  }