@celljs/react 4.5.1 → 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.
Files changed (161) hide show
  1. package/README.md +33 -3
  2. package/esm/browser/app/app.d.ts +1 -1
  3. package/esm/browser/error/error-boundary.d.ts +32 -0
  4. package/esm/browser/error/error-boundary.js +38 -0
  5. package/esm/browser/error/error-boundary.js.map +1 -0
  6. package/esm/browser/error/index.d.ts +1 -0
  7. package/esm/browser/error/index.js +2 -0
  8. package/esm/browser/error/index.js.map +1 -0
  9. package/esm/browser/hooks/container-hooks.d.ts +1 -1
  10. package/esm/browser/hooks/container-hooks.js +5 -10
  11. package/esm/browser/hooks/container-hooks.js.map +1 -1
  12. package/esm/browser/hooks/index.d.ts +1 -0
  13. package/esm/browser/hooks/index.js +1 -0
  14. package/esm/browser/hooks/index.js.map +1 -1
  15. package/esm/browser/hooks/rpc-hooks.d.ts +6 -0
  16. package/esm/browser/hooks/rpc-hooks.js +19 -0
  17. package/esm/browser/hooks/rpc-hooks.js.map +1 -0
  18. package/esm/browser/icon/icon.d.ts +2 -1
  19. package/esm/browser/icon/icon.js +7 -6
  20. package/esm/browser/icon/icon.js.map +1 -1
  21. package/esm/browser/index.d.ts +1 -0
  22. package/esm/browser/index.js +1 -0
  23. package/esm/browser/index.js.map +1 -1
  24. package/esm/browser/intl/index.d.ts +1 -0
  25. package/esm/browser/intl/index.js +2 -0
  26. package/esm/browser/intl/index.js.map +1 -0
  27. package/esm/browser/intl/intl-context.d.ts +13 -0
  28. package/esm/browser/{locale/locale-context.js → intl/intl-context.js} +12 -12
  29. package/esm/browser/intl/intl-context.js.map +1 -0
  30. package/esm/browser/layout/layout.d.ts +1 -1
  31. package/esm/browser/locale/index.d.ts +1 -2
  32. package/esm/browser/locale/index.js +1 -2
  33. package/esm/browser/locale/index.js.map +1 -1
  34. package/esm/browser/locale/locale-hooks.d.ts +3 -0
  35. package/esm/browser/locale/locale-hooks.js +15 -0
  36. package/esm/browser/locale/locale-hooks.js.map +1 -0
  37. package/esm/browser/router/file-route-util.js +10 -0
  38. package/esm/browser/router/file-route-util.js.map +1 -1
  39. package/esm/browser/router/router-protocol.d.ts +10 -0
  40. package/esm/browser/router/router-protocol.js.map +1 -1
  41. package/esm/browser/router/router.d.ts +6 -0
  42. package/esm/browser/router/router.js +10 -5
  43. package/esm/browser/router/router.js.map +1 -1
  44. package/esm/browser/shell/shell.d.ts +6 -3
  45. package/esm/browser/shell/shell.js +12 -6
  46. package/esm/browser/shell/shell.js.map +1 -1
  47. package/esm/browser/slot/slot.d.ts +2 -1
  48. package/lib/browser/app/app.d.ts +1 -1
  49. package/lib/browser/app/app.d.ts.map +1 -1
  50. package/lib/browser/error/error-boundary.d.ts +33 -0
  51. package/lib/browser/error/error-boundary.d.ts.map +1 -0
  52. package/lib/browser/error/error-boundary.js +76 -0
  53. package/lib/browser/error/error-boundary.js.map +1 -0
  54. package/lib/browser/error/error-boundary.spec.d.ts +2 -0
  55. package/lib/browser/error/error-boundary.spec.d.ts.map +1 -0
  56. package/lib/browser/error/error-boundary.spec.js +82 -0
  57. package/lib/browser/error/error-boundary.spec.js.map +1 -0
  58. package/lib/browser/error/index.d.ts +2 -0
  59. package/lib/browser/error/index.d.ts.map +1 -0
  60. package/lib/browser/error/index.js +18 -0
  61. package/lib/browser/error/index.js.map +1 -0
  62. package/lib/browser/hooks/container-hooks.d.ts +1 -1
  63. package/lib/browser/hooks/container-hooks.d.ts.map +1 -1
  64. package/lib/browser/hooks/container-hooks.js +4 -9
  65. package/lib/browser/hooks/container-hooks.js.map +1 -1
  66. package/lib/browser/hooks/container-hooks.spec.d.ts.map +1 -1
  67. package/lib/browser/hooks/container-hooks.spec.js +65 -7
  68. package/lib/browser/hooks/container-hooks.spec.js.map +1 -1
  69. package/lib/browser/hooks/index.d.ts +1 -0
  70. package/lib/browser/hooks/index.d.ts.map +1 -1
  71. package/lib/browser/hooks/index.js +1 -0
  72. package/lib/browser/hooks/index.js.map +1 -1
  73. package/lib/browser/hooks/rpc-hooks.d.ts +7 -0
  74. package/lib/browser/hooks/rpc-hooks.d.ts.map +1 -0
  75. package/lib/browser/hooks/rpc-hooks.js +55 -0
  76. package/lib/browser/hooks/rpc-hooks.js.map +1 -0
  77. package/lib/browser/icon/icon.d.ts +2 -1
  78. package/lib/browser/icon/icon.d.ts.map +1 -1
  79. package/lib/browser/icon/icon.js +7 -6
  80. package/lib/browser/icon/icon.js.map +1 -1
  81. package/lib/browser/index.d.ts +1 -0
  82. package/lib/browser/index.d.ts.map +1 -1
  83. package/lib/browser/index.js +1 -0
  84. package/lib/browser/index.js.map +1 -1
  85. package/lib/browser/intl/index.d.ts +2 -0
  86. package/lib/browser/intl/index.d.ts.map +1 -0
  87. package/lib/browser/intl/index.js +18 -0
  88. package/lib/browser/intl/index.js.map +1 -0
  89. package/lib/browser/intl/intl-context.d.ts +14 -0
  90. package/lib/browser/intl/intl-context.d.ts.map +1 -0
  91. package/lib/browser/{locale/locale-context.js → intl/intl-context.js} +14 -13
  92. package/lib/browser/intl/intl-context.js.map +1 -0
  93. package/lib/browser/layout/layout.d.ts +1 -1
  94. package/lib/browser/layout/layout.d.ts.map +1 -1
  95. package/lib/browser/locale/index.d.ts +1 -2
  96. package/lib/browser/locale/index.d.ts.map +1 -1
  97. package/lib/browser/locale/index.js +1 -2
  98. package/lib/browser/locale/index.js.map +1 -1
  99. package/lib/browser/locale/locale-hooks.d.ts +4 -0
  100. package/lib/browser/locale/locale-hooks.d.ts.map +1 -0
  101. package/lib/browser/locale/locale-hooks.js +51 -0
  102. package/lib/browser/locale/locale-hooks.js.map +1 -0
  103. package/lib/browser/router/file-route-util.d.ts.map +1 -1
  104. package/lib/browser/router/file-route-util.js +10 -0
  105. package/lib/browser/router/file-route-util.js.map +1 -1
  106. package/lib/browser/router/file-route-util.spec.js +18 -6
  107. package/lib/browser/router/file-route-util.spec.js.map +1 -1
  108. package/lib/browser/router/router-protocol.d.ts +10 -0
  109. package/lib/browser/router/router-protocol.d.ts.map +1 -1
  110. package/lib/browser/router/router-protocol.js.map +1 -1
  111. package/lib/browser/router/router.d.ts +6 -0
  112. package/lib/browser/router/router.d.ts.map +1 -1
  113. package/lib/browser/router/router.js +10 -4
  114. package/lib/browser/router/router.js.map +1 -1
  115. package/lib/browser/router/router.spec.d.ts +1 -1
  116. package/lib/browser/router/router.spec.d.ts.map +1 -1
  117. package/lib/browser/router/router.spec.js +8 -5
  118. package/lib/browser/router/router.spec.js.map +1 -1
  119. package/lib/browser/shell/shell.d.ts +6 -3
  120. package/lib/browser/shell/shell.d.ts.map +1 -1
  121. package/lib/browser/shell/shell.js +11 -5
  122. package/lib/browser/shell/shell.js.map +1 -1
  123. package/lib/browser/slot/slot.d.ts +2 -1
  124. package/lib/browser/slot/slot.d.ts.map +1 -1
  125. package/lib/package.spec.js +25 -2
  126. package/lib/package.spec.js.map +1 -1
  127. package/package.json +24 -8
  128. package/src/browser/error/error-boundary.spec.tsx +49 -0
  129. package/src/browser/error/error-boundary.tsx +62 -0
  130. package/src/browser/error/index.ts +1 -0
  131. package/src/browser/hooks/container-hooks.spec.tsx +65 -9
  132. package/src/browser/hooks/container-hooks.ts +5 -9
  133. package/src/browser/hooks/index.ts +1 -0
  134. package/src/browser/hooks/rpc-hooks.ts +21 -0
  135. package/src/browser/icon/icon.tsx +7 -6
  136. package/src/browser/index.ts +2 -1
  137. package/src/browser/intl/index.ts +1 -0
  138. package/src/browser/intl/intl-context.tsx +31 -0
  139. package/src/browser/locale/index.ts +1 -2
  140. package/src/browser/locale/locale-hooks.ts +15 -0
  141. package/src/browser/router/file-route-util.spec.tsx +15 -4
  142. package/src/browser/router/file-route-util.ts +12 -0
  143. package/src/browser/router/router-protocol.ts +6 -0
  144. package/src/browser/router/router.spec.tsx +10 -8
  145. package/src/browser/router/router.tsx +13 -6
  146. package/src/browser/shell/shell.tsx +16 -6
  147. package/src/package.spec.ts +22 -3
  148. package/esm/browser/locale/locale-context.d.ts +0 -8
  149. package/esm/browser/locale/locale-context.js.map +0 -1
  150. package/esm/browser/locale/locale-protocol.d.ts +0 -1
  151. package/esm/browser/locale/locale-protocol.js +0 -2
  152. package/esm/browser/locale/locale-protocol.js.map +0 -1
  153. package/lib/browser/locale/locale-context.d.ts +0 -9
  154. package/lib/browser/locale/locale-context.d.ts.map +0 -1
  155. package/lib/browser/locale/locale-context.js.map +0 -1
  156. package/lib/browser/locale/locale-protocol.d.ts +0 -2
  157. package/lib/browser/locale/locale-protocol.d.ts.map +0 -1
  158. package/lib/browser/locale/locale-protocol.js +0 -5
  159. package/lib/browser/locale/locale-protocol.js.map +0 -1
  160. package/src/browser/locale/locale-context.tsx +0 -31
  161. 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, ContainerUtil } from '@celljs/core';
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
- const boot = (props: Record<string, unknown> = {}) =>
32
- ApplicationFactory.create({ react: { path: '/app' }, ...props }, reactTestModule, specModule);
33
- const routes = () => ContainerUtil.get<RouteMetadataProvider>(RouteMetadataProvider).provide();
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(ContainerUtil.isBound('@Route:<index>')).toBe(true);
48
- expect(ContainerUtil.isBound('@Route:/about')).toBe(true);
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 ContainerUtil.get<WidgetManager<React.ReactNode>>(WidgetManager).render('header');
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
- element = React.createElement(metadata.component);
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 { ApplicationShell } from '@celljs/core/lib/browser';
2
- import { Component, Autowired, ContainerProvider } from '@celljs/core';
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 implements ApplicationShell {
11
+ export class Shell extends AbstractApplicationShell {
10
12
 
11
13
  @Autowired(APP)
12
14
  protected readonly app: React.ComponentType;
13
15
 
14
- attach(host: HTMLElement): void {
15
- const root = React.createElement(ContainerContext.Provider, { value: ContainerProvider.provide() }, React.createElement(this.app));
16
- createRoot(host).render(root);
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
  }
@@ -1,5 +1,24 @@
1
- import { describe, it } from 'bun:test';
2
- describe('react package', () => {
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
- it('support code coverage statistics', () => {});
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
- }
7
- export default class {
8
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"locale-context.js","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;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,UAAU,aAAa,CAAC,EAAE,QAAQ,EAA2B;IAC/D,MAAM,aAAa,GAAG,SAAS,CAAgB,aAAa,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,SAAS,CAAS,MAAM,CAAC,CAAC;IACzC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/E,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,MAAM,YAAY,GAAG,aAAa,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/E,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IAC5C,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,OAAO,CACH,oBAAC,YAAY,IAAC,MAAM,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,SAAS,CAAC,QAAQ,IAAI,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,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,2 +0,0 @@
1
- export const LOCALE_REACT_CONTEXT_PRIORITY = 3000;
2
- //# sourceMappingURL=locale-protocol.js.map
@@ -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;;AAGtD,MAAM,CAAC,OAAO;CAAS"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"locale-context.js","sourceRoot":"","sources":["../../../src/browser/locale/locale-context.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,KAAK,kCAAc;AAC/B,uDAAkE;AAClE,2CAA0C;AAC1C,uCAAsC;AACtC,2CAA+C;AAC/C,8CAAwC;AACxC,oCAAqC;AAErC,uBAA8B,EAAE,QAAQ,EAA2B;IAC/D,MAAM,aAAa,GAAG,IAAA,iBAAS,EAAgB,sBAAa,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,IAAA,iBAAS,EAAS,aAAM,CAAC,CAAC;IACzC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/E,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,MAAM,YAAY,GAAG,aAAa,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/E,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IAC5C,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,OAAO,CACH,oBAAC,yBAAY,IAAC,MAAM,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,SAAS,CAAC,QAAQ,IAAI,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,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,+CAA6B,CAAC;AAGxC,gBAAA;CAAQ,CAAA;AAAR;IADd,IAAA,oBAAO,EAAC,aAAa,CAAC;aACA"}
@@ -1,2 +0,0 @@
1
- export declare const LOCALE_REACT_CONTEXT_PRIORITY = 3000;
2
- //# sourceMappingURL=locale-protocol.d.ts.map
@@ -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,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LOCALE_REACT_CONTEXT_PRIORITY = void 0;
4
- exports.LOCALE_REACT_CONTEXT_PRIORITY = 3000;
5
- //# sourceMappingURL=locale-protocol.js.map
@@ -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;