@celljs/react 4.5.0 → 4.6.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/README.md +33 -3
- package/esm/browser/app/app.d.ts +1 -1
- package/esm/browser/error/error-boundary.d.ts +32 -0
- package/esm/browser/error/error-boundary.js +38 -0
- package/esm/browser/error/error-boundary.js.map +1 -0
- package/esm/browser/error/index.d.ts +1 -0
- package/esm/browser/error/index.js +2 -0
- package/esm/browser/error/index.js.map +1 -0
- package/esm/browser/hooks/container-hooks.d.ts +1 -1
- package/esm/browser/hooks/container-hooks.js +5 -10
- package/esm/browser/hooks/container-hooks.js.map +1 -1
- package/esm/browser/hooks/index.d.ts +1 -0
- package/esm/browser/hooks/index.js +1 -0
- package/esm/browser/hooks/index.js.map +1 -1
- package/esm/browser/hooks/rpc-hooks.d.ts +6 -0
- package/esm/browser/hooks/rpc-hooks.js +19 -0
- package/esm/browser/hooks/rpc-hooks.js.map +1 -0
- package/esm/browser/icon/icon.d.ts +2 -1
- package/esm/browser/icon/icon.js +7 -6
- package/esm/browser/icon/icon.js.map +1 -1
- package/esm/browser/index.d.ts +1 -0
- package/esm/browser/index.js +1 -0
- package/esm/browser/index.js.map +1 -1
- package/esm/browser/intl/index.d.ts +1 -0
- package/esm/browser/intl/index.js +2 -0
- package/esm/browser/intl/index.js.map +1 -0
- package/esm/browser/intl/intl-context.d.ts +13 -0
- package/esm/browser/{locale/locale-context.js → intl/intl-context.js} +12 -12
- package/esm/browser/intl/intl-context.js.map +1 -0
- package/esm/browser/layout/layout.d.ts +1 -1
- package/esm/browser/locale/index.d.ts +1 -2
- package/esm/browser/locale/index.js +1 -2
- package/esm/browser/locale/index.js.map +1 -1
- package/esm/browser/locale/locale-hooks.d.ts +3 -0
- package/esm/browser/locale/locale-hooks.js +15 -0
- package/esm/browser/locale/locale-hooks.js.map +1 -0
- package/esm/browser/router/file-route-util.js +10 -0
- package/esm/browser/router/file-route-util.js.map +1 -1
- package/esm/browser/router/router-protocol.d.ts +10 -0
- package/esm/browser/router/router-protocol.js.map +1 -1
- package/esm/browser/router/router.d.ts +6 -0
- package/esm/browser/router/router.js +10 -5
- package/esm/browser/router/router.js.map +1 -1
- package/esm/browser/shell/shell.d.ts +6 -3
- package/esm/browser/shell/shell.js +12 -6
- package/esm/browser/shell/shell.js.map +1 -1
- package/esm/browser/slot/slot.d.ts +2 -1
- package/lib/browser/app/app.d.ts +1 -1
- package/lib/browser/app/app.d.ts.map +1 -1
- package/lib/browser/error/error-boundary.d.ts +33 -0
- package/lib/browser/error/error-boundary.d.ts.map +1 -0
- package/lib/browser/error/error-boundary.js +76 -0
- package/lib/browser/error/error-boundary.js.map +1 -0
- package/lib/browser/error/error-boundary.spec.d.ts +2 -0
- package/lib/browser/error/error-boundary.spec.d.ts.map +1 -0
- package/lib/browser/error/error-boundary.spec.js +82 -0
- package/lib/browser/error/error-boundary.spec.js.map +1 -0
- package/lib/browser/error/index.d.ts +2 -0
- package/lib/browser/error/index.d.ts.map +1 -0
- package/lib/browser/error/index.js +18 -0
- package/lib/browser/error/index.js.map +1 -0
- package/lib/browser/hooks/container-hooks.d.ts +1 -1
- package/lib/browser/hooks/container-hooks.d.ts.map +1 -1
- package/lib/browser/hooks/container-hooks.js +4 -9
- package/lib/browser/hooks/container-hooks.js.map +1 -1
- package/lib/browser/hooks/container-hooks.spec.d.ts.map +1 -1
- package/lib/browser/hooks/container-hooks.spec.js +65 -7
- package/lib/browser/hooks/container-hooks.spec.js.map +1 -1
- package/lib/browser/hooks/index.d.ts +1 -0
- package/lib/browser/hooks/index.d.ts.map +1 -1
- package/lib/browser/hooks/index.js +1 -0
- package/lib/browser/hooks/index.js.map +1 -1
- package/lib/browser/hooks/rpc-hooks.d.ts +7 -0
- package/lib/browser/hooks/rpc-hooks.d.ts.map +1 -0
- package/lib/browser/hooks/rpc-hooks.js +55 -0
- package/lib/browser/hooks/rpc-hooks.js.map +1 -0
- package/lib/browser/icon/icon.d.ts +2 -1
- package/lib/browser/icon/icon.d.ts.map +1 -1
- package/lib/browser/icon/icon.js +7 -6
- package/lib/browser/icon/icon.js.map +1 -1
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/intl/index.d.ts +2 -0
- package/lib/browser/intl/index.d.ts.map +1 -0
- package/lib/browser/intl/index.js +18 -0
- package/lib/browser/intl/index.js.map +1 -0
- package/lib/browser/intl/intl-context.d.ts +14 -0
- package/lib/browser/intl/intl-context.d.ts.map +1 -0
- package/lib/browser/{locale/locale-context.js → intl/intl-context.js} +14 -13
- package/lib/browser/intl/intl-context.js.map +1 -0
- package/lib/browser/layout/layout.d.ts +1 -1
- package/lib/browser/layout/layout.d.ts.map +1 -1
- package/lib/browser/locale/index.d.ts +1 -2
- package/lib/browser/locale/index.d.ts.map +1 -1
- package/lib/browser/locale/index.js +1 -2
- package/lib/browser/locale/index.js.map +1 -1
- package/lib/browser/locale/locale-hooks.d.ts +4 -0
- package/lib/browser/locale/locale-hooks.d.ts.map +1 -0
- package/lib/browser/locale/locale-hooks.js +51 -0
- package/lib/browser/locale/locale-hooks.js.map +1 -0
- package/lib/browser/router/file-route-util.d.ts.map +1 -1
- package/lib/browser/router/file-route-util.js +10 -0
- package/lib/browser/router/file-route-util.js.map +1 -1
- package/lib/browser/router/file-route-util.spec.js +18 -6
- package/lib/browser/router/file-route-util.spec.js.map +1 -1
- package/lib/browser/router/router-protocol.d.ts +10 -0
- package/lib/browser/router/router-protocol.d.ts.map +1 -1
- package/lib/browser/router/router-protocol.js.map +1 -1
- package/lib/browser/router/router.d.ts +6 -0
- package/lib/browser/router/router.d.ts.map +1 -1
- package/lib/browser/router/router.js +10 -4
- package/lib/browser/router/router.js.map +1 -1
- package/lib/browser/router/router.spec.d.ts +1 -1
- package/lib/browser/router/router.spec.d.ts.map +1 -1
- package/lib/browser/router/router.spec.js +8 -5
- package/lib/browser/router/router.spec.js.map +1 -1
- package/lib/browser/shell/shell.d.ts +6 -3
- package/lib/browser/shell/shell.d.ts.map +1 -1
- package/lib/browser/shell/shell.js +11 -5
- package/lib/browser/shell/shell.js.map +1 -1
- package/lib/browser/slot/slot.d.ts +2 -1
- package/lib/browser/slot/slot.d.ts.map +1 -1
- package/lib/package.spec.js +25 -2
- package/lib/package.spec.js.map +1 -1
- package/package.json +24 -8
- package/src/browser/error/error-boundary.spec.tsx +49 -0
- package/src/browser/error/error-boundary.tsx +62 -0
- package/src/browser/error/index.ts +1 -0
- package/src/browser/hooks/container-hooks.spec.tsx +65 -9
- package/src/browser/hooks/container-hooks.ts +5 -9
- package/src/browser/hooks/index.ts +1 -0
- package/src/browser/hooks/rpc-hooks.ts +21 -0
- package/src/browser/icon/icon.tsx +7 -6
- package/src/browser/index.ts +2 -1
- package/src/browser/intl/index.ts +1 -0
- package/src/browser/intl/intl-context.tsx +31 -0
- package/src/browser/locale/index.ts +1 -2
- package/src/browser/locale/locale-hooks.ts +15 -0
- package/src/browser/router/file-route-util.spec.tsx +15 -4
- package/src/browser/router/file-route-util.ts +12 -0
- package/src/browser/router/router-protocol.ts +6 -0
- package/src/browser/router/router.spec.tsx +10 -8
- package/src/browser/router/router.tsx +13 -6
- package/src/browser/shell/shell.tsx +16 -6
- package/src/package.spec.ts +22 -3
- package/esm/browser/locale/locale-context.d.ts +0 -8
- package/esm/browser/locale/locale-context.js.map +0 -1
- package/esm/browser/locale/locale-protocol.d.ts +0 -1
- package/esm/browser/locale/locale-protocol.js +0 -2
- package/esm/browser/locale/locale-protocol.js.map +0 -1
- package/lib/browser/locale/locale-context.d.ts +0 -9
- package/lib/browser/locale/locale-context.d.ts.map +0 -1
- package/lib/browser/locale/locale-context.js.map +0 -1
- package/lib/browser/locale/locale-protocol.d.ts +0 -2
- package/lib/browser/locale/locale-protocol.d.ts.map +0 -1
- package/lib/browser/locale/locale-protocol.js +0 -5
- package/lib/browser/locale/locale-protocol.js.map +0 -1
- package/src/browser/locale/locale-context.tsx +0 -31
- package/src/browser/locale/locale-protocol.ts +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
2
|
import { reactTestModule } from '../test/test-module';
|
|
3
|
-
import { autoBind,
|
|
3
|
+
import { autoBind, Container } from '@celljs/core';
|
|
4
4
|
import { ApplicationFactory } from '@celljs/core/lib/common/application/application-factory';
|
|
5
5
|
import { Widget, WidgetManager } from '@celljs/widget';
|
|
6
6
|
import * as React from 'react';
|
|
@@ -28,9 +28,11 @@ export class LogoWidget {}
|
|
|
28
28
|
|
|
29
29
|
// autoBind() takes what was registered since the previous call: the classes of this file.
|
|
30
30
|
const specModule = autoBind();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
let container: Container;
|
|
32
|
+
const boot = async (props: Record<string, unknown> = {}) => {
|
|
33
|
+
container = ApplicationFactory.createContainer({ react: { path: '/app' }, ...props }, reactTestModule, specModule);
|
|
34
|
+
};
|
|
35
|
+
const routes = () => container.get<RouteMetadataProvider>(RouteMetadataProvider).provide();
|
|
34
36
|
|
|
35
37
|
describe('@celljs/react routes', () => {
|
|
36
38
|
|
|
@@ -44,8 +46,8 @@ describe('@celljs/react routes', () => {
|
|
|
44
46
|
|
|
45
47
|
it('registers each route under its own id: the path, or <index>', async () => {
|
|
46
48
|
await boot();
|
|
47
|
-
expect(
|
|
48
|
-
expect(
|
|
49
|
+
expect(container.isBound('@Route:<index>')).toBe(true);
|
|
50
|
+
expect(container.isBound('@Route:/about')).toBe(true);
|
|
49
51
|
});
|
|
50
52
|
|
|
51
53
|
it('react.router.routes overrides the metadata of a route by its path', async () => {
|
|
@@ -60,7 +62,7 @@ describe('@celljs/react widgets', () => {
|
|
|
60
62
|
|
|
61
63
|
it('@Widget components render with the props of the configuration', async () => {
|
|
62
64
|
await boot({ widget: { widgets: { logo: { props: { text: 'Cell' } } } } });
|
|
63
|
-
const nodes = await
|
|
65
|
+
const nodes = await container.get<WidgetManager<React.ReactNode>>(WidgetManager).render('header');
|
|
64
66
|
expect(renderToStaticMarkup(<>{nodes}</>)).toBe('<b>Cell</b>');
|
|
65
67
|
});
|
|
66
|
-
});
|
|
68
|
+
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { RouteMetadata, RouteMetadataProvider } from './router-protocol';
|
|
3
|
-
import { useRoutes, BrowserRouter, HashRouter, RouteObject, MemoryRouter } from 'react-router';
|
|
3
|
+
import { useRoutes, useLocation, BrowserRouter, HashRouter, RouteObject, MemoryRouter } from 'react-router';
|
|
4
4
|
import { Router } from '../annotation';
|
|
5
|
+
import { ErrorBoundary, ErrorFallbackProps } from '../error';
|
|
5
6
|
import { useInject, useValue } from '../hooks';
|
|
6
7
|
|
|
7
8
|
const routerMap = {
|
|
@@ -21,15 +22,21 @@ function RouterComponent() {
|
|
|
21
22
|
return React.createElement(routerMap[routerType], {}, React.createElement(Routes, { routes }));
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
/** The boundary of a page, inside its layout: tries the page again when the user goes to another path. */
|
|
26
|
+
export function PageErrorBoundary({ fallback, children }: React.PropsWithChildren<{ fallback?: React.ComponentType<ErrorFallbackProps> }>) {
|
|
27
|
+
const { pathname } = useLocation();
|
|
28
|
+
return React.createElement(ErrorBoundary, { fallback, resetKey: pathname }, children);
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
function toRouteObject(metadata: RouteMetadata): RouteObject {
|
|
25
32
|
let element: React.ReactNode;
|
|
26
33
|
if (metadata.component) {
|
|
27
|
-
|
|
34
|
+
// Pages of src/browser/pages, their layouts and _error files are lazy components.
|
|
35
|
+
element = React.createElement(PageErrorBoundary, { fallback: metadata.errorFallback },
|
|
36
|
+
React.createElement(React.Suspense, { fallback: null }, React.createElement(metadata.component)));
|
|
28
37
|
if (metadata.layout) {
|
|
29
|
-
element = React.createElement(metadata.layout, {}, element);
|
|
38
|
+
element = React.createElement(React.Suspense, { fallback: null }, React.createElement(metadata.layout, {}, element));
|
|
30
39
|
}
|
|
31
|
-
// Pages of src/browser/pages and their layouts are lazy components.
|
|
32
|
-
element = React.createElement(React.Suspense, { fallback: null }, element);
|
|
33
40
|
}
|
|
34
41
|
return {
|
|
35
42
|
path: metadata.path,
|
|
@@ -40,4 +47,4 @@ function toRouteObject(metadata: RouteMetadata): RouteObject {
|
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
@Router(RouterComponent, false)
|
|
43
|
-
export default class {}
|
|
50
|
+
export default class {}
|
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Component, Autowired,
|
|
1
|
+
import { AbstractApplicationShell } from '@celljs/core/lib/browser';
|
|
2
|
+
import { ApplicationShell, Component, Autowired, Container } from '@celljs/core';
|
|
3
3
|
import { createRoot } from 'react-dom/client';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { APP } from '../app';
|
|
6
|
+
import { ErrorBoundary } from '../error';
|
|
6
7
|
import { ContainerContext } from '../hooks';
|
|
7
8
|
|
|
9
|
+
/** Renders the `@App` component with the container of the application, inside an error boundary. */
|
|
8
10
|
@Component({ id: ApplicationShell, rebind: true })
|
|
9
|
-
export class Shell
|
|
11
|
+
export class Shell extends AbstractApplicationShell {
|
|
10
12
|
|
|
11
13
|
@Autowired(APP)
|
|
12
14
|
protected readonly app: React.ComponentType;
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
@Autowired(Container)
|
|
17
|
+
protected readonly container: Container;
|
|
18
|
+
|
|
19
|
+
protected render(host: HTMLElement): void {
|
|
20
|
+
createRoot(host).render(
|
|
21
|
+
<ContainerContext.Provider value={this.container}>
|
|
22
|
+
<ErrorBoundary>
|
|
23
|
+
{React.createElement(this.app)}
|
|
24
|
+
</ErrorBoundary>
|
|
25
|
+
</ContainerContext.Provider>
|
|
26
|
+
);
|
|
17
27
|
}
|
|
18
28
|
}
|
package/src/package.spec.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
import { describe, it } from 'bun:test';
|
|
2
|
-
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { reactTestModule } from './browser/test/test-module';
|
|
3
|
+
import { currentThis } from '@celljs/core';
|
|
4
|
+
import { AssemblyTestUtil } from '@celljs/core/lib/common/test/assembly-test-util';
|
|
5
|
+
import commonStatic from '@celljs/core/lib/common/static-module';
|
|
6
|
+
import { APP } from './browser/app';
|
|
7
|
+
import { ROUTER, RouteMetadataProvider } from './browser/router';
|
|
3
8
|
|
|
4
|
-
|
|
9
|
+
currentThis.cellProps = { react: { path: '/' } };
|
|
10
|
+
(globalThis as any).localStorage ??= { getItem: () => null, setItem: () => undefined, removeItem: () => undefined };
|
|
11
|
+
// Node.js before 21 has no navigator; the LocaleManager reads its language.
|
|
12
|
+
(globalThis as any).navigator ??= { language: 'en-US' };
|
|
13
|
+
|
|
14
|
+
describe('@celljs/react', () => {
|
|
15
|
+
// The components of this package and of @celljs/widget, without the shell, which needs a DOM.
|
|
16
|
+
it('its components load after core and every binding resolves', () => {
|
|
17
|
+
const { container, changed, errors } = AssemblyTestUtil.check([commonStatic], reactTestModule);
|
|
18
|
+
expect(errors).toEqual([]);
|
|
19
|
+
expect(changed).toBeGreaterThan(0);
|
|
20
|
+
expect(container.isBound(APP)).toBe(true);
|
|
21
|
+
expect(container.isBound(ROUTER)).toBe(true);
|
|
22
|
+
expect(container.get<RouteMetadataProvider>(RouteMetadataProvider).provide()).toEqual([]);
|
|
23
|
+
});
|
|
5
24
|
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { LOCALE_REACT_CONTEXT_PRIORITY } from './locale-protocol.js';
|
|
3
|
-
export declare function LocaleContext({ children }: React.PropsWithChildren): JSX.Element;
|
|
4
|
-
export declare namespace LocaleContext {
|
|
5
|
-
export { LOCALE_REACT_CONTEXT_PRIORITY as priority };
|
|
6
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AAM,CAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE;YACzG,IAAI,GAAG,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;gBACrC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC;QACL,CAAC,IACI,QAAQ,CACE,CAAC,CAAC;AACzB,CAAC;AAED,aAAa,CAAC,QAAQ,GAAG,6BAA6B,CAAC;AAGxC,gBAAA;CAAQ,CAAA;AAAR;IADd,OAAO,CAAC,aAAa,CAAC;aACA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const LOCALE_REACT_CONTEXT_PRIORITY = 3000;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"locale-protocol.js","sourceRoot":"","sources":["../../../src/browser/locale/locale-protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { LOCALE_REACT_CONTEXT_PRIORITY } from './locale-protocol';
|
|
3
|
-
export declare function LocaleContext({ children }: React.PropsWithChildren): JSX.Element;
|
|
4
|
-
export declare namespace LocaleContext {
|
|
5
|
-
export { LOCALE_REACT_CONTEXT_PRIORITY as priority };
|
|
6
|
-
}
|
|
7
|
-
export default class {
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=locale-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"locale-context.d.ts","sourceRoot":"","sources":["../../../src/browser/locale/locale-context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAOlE,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,iBAAiB,eAiBlE;yBAjBe,aAAa;aAmBJ,6BAA6B;;AAG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Q,CACE,CAAC,CAAC;AACzB,CAAC;AAED,aAAa,CAAC,QAAQ,GAAG,+CAA6B,CAAC;AAGxC,gBAAA;CAAQ,CAAA;AAAR;IADd,IAAA,oBAAO,EAAC,aAAa,CAAC;aACA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"locale-protocol.d.ts","sourceRoot":"","sources":["../../../src/browser/locale/locale-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,OAAO,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"locale-protocol.js","sourceRoot":"","sources":["../../../src/browser/locale/locale-protocol.ts"],"names":[],"mappings":";;;AAAa,QAAA,6BAA6B,GAAG,IAAI,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { LOCALE_REACT_CONTEXT_PRIORITY } from './locale-protocol';
|
|
3
|
-
import { IntlProvider } from 'react-intl';
|
|
4
|
-
import { Logger } from '@celljs/core';
|
|
5
|
-
import { LocaleManager } from '@celljs/widget';
|
|
6
|
-
import { Context } from '../annotation';
|
|
7
|
-
import { useInject } from '../hooks';
|
|
8
|
-
|
|
9
|
-
export function LocaleContext({ children }: React.PropsWithChildren) {
|
|
10
|
-
const localeManager = useInject<LocaleManager>(LocaleManager);
|
|
11
|
-
const logger = useInject<Logger>(Logger);
|
|
12
|
-
const [locale, setLocale] = React.useState(localeManager.currentSubject.value);
|
|
13
|
-
React.useEffect(() => {
|
|
14
|
-
const subscription = localeManager.currentSubject.subscribe(l => setLocale(l));
|
|
15
|
-
return () => subscription.unsubscribe();
|
|
16
|
-
}, [localeManager]);
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<IntlProvider locale={locale?.lang || navigator.language || 'en'} messages={locale?.messages} onError={err => {
|
|
20
|
-
if (err.code !== 'MISSING_TRANSLATION') {
|
|
21
|
-
logger.warn(err);
|
|
22
|
-
}
|
|
23
|
-
}}>
|
|
24
|
-
{children}
|
|
25
|
-
</IntlProvider>);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
LocaleContext.priority = LOCALE_REACT_CONTEXT_PRIORITY;
|
|
29
|
-
|
|
30
|
-
@Context(LocaleContext)
|
|
31
|
-
export default class {}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const LOCALE_REACT_CONTEXT_PRIORITY = 3000;
|