@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.
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
@@ -48,11 +48,13 @@ const core_1 = require("@celljs/core");
48
48
  const client_1 = require("react-dom/client");
49
49
  const React = __importStar(require("react"));
50
50
  const app_1 = require("../app");
51
+ const error_1 = require("../error");
51
52
  const hooks_1 = require("../hooks");
52
- let Shell = class Shell {
53
- attach(host) {
54
- const root = React.createElement(hooks_1.ContainerContext.Provider, { value: core_1.ContainerProvider.provide() }, React.createElement(this.app));
55
- (0, client_1.createRoot)(host).render(root);
53
+ /** Renders the `@App` component with the container of the application, inside an error boundary. */
54
+ let Shell = class Shell extends browser_1.AbstractApplicationShell {
55
+ render(host) {
56
+ (0, client_1.createRoot)(host).render(React.createElement(hooks_1.ContainerContext.Provider, { value: this.container },
57
+ React.createElement(error_1.ErrorBoundary, null, React.createElement(this.app))));
56
58
  }
57
59
  };
58
60
  exports.Shell = Shell;
@@ -60,7 +62,11 @@ __decorate([
60
62
  (0, core_1.Autowired)(app_1.APP),
61
63
  __metadata("design:type", Object)
62
64
  ], Shell.prototype, "app", void 0);
65
+ __decorate([
66
+ (0, core_1.Autowired)(core_1.Container),
67
+ __metadata("design:type", core_1.Container)
68
+ ], Shell.prototype, "container", void 0);
63
69
  exports.Shell = Shell = __decorate([
64
- (0, core_1.Component)({ id: browser_1.ApplicationShell, rebind: true })
70
+ (0, core_1.Component)({ id: core_1.ApplicationShell, rebind: true })
65
71
  ], Shell);
66
72
  //# sourceMappingURL=shell.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../../src/browser/shell/shell.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA4D;AAC5D,uCAAuE;AACvE,6CAA8C;AAC9C,MAAY,KAAK,kCAAc;AAC/B,gCAA6B;AAC7B,oCAA4C;AAGrC,IAAM,KAAK,GAAX,MAAM,KAAK;IAKd,MAAM,CAAC,IAAiB;QACpB,MAAM,IAAI,GAAG,KAAK,CAAC,aAAa,CAAC,wBAAgB,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,wBAAiB,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACnI,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACJ,CAAA;;AANsB;IADlB,IAAA,gBAAS,EAAC,SAAG,CAAC;;kCAC6B;gBAHnC,KAAK;IADjB,IAAA,gBAAS,EAAC,EAAE,EAAE,EAAE,0BAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;GACrC,KAAK,CASjB"}
1
+ {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../../src/browser/shell/shell.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAoE;AACpE,uCAAiF;AACjF,6CAA8C;AAC9C,MAAY,KAAK,kCAAc;AAC/B,gCAA6B;AAC7B,oCAAyC;AACzC,oCAA4C;AAE5C,oGAAoG;AAE7F,IAAM,KAAK,GAAX,MAAM,KAAM,SAAQ,kCAAwB;IAQrC,MAAM,CAAC,IAAiB;QAC9B,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC,MAAM,CACnB,oBAAC,wBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,IAAI,CAAC,SAAS;YAC5C,oBAAC,qBAAa,QACT,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAClB,CACQ,CAC/B,CAAC;IACN,CAAC;CACJ,CAAA;;AAdsB;IADlB,IAAA,gBAAS,EAAC,SAAG,CAAC;;kCAC6B;AAGzB;IADlB,IAAA,gBAAS,EAAC,gBAAS,CAAC;8BACS,gBAAS;wCAAC;gBAN/B,KAAK;IADjB,IAAA,gBAAS,EAAC,EAAE,EAAE,EAAE,uBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;GACrC,KAAK,CAiBjB"}
@@ -1,5 +1,6 @@
1
+ import * as React from 'react';
1
2
  /** The widgets of an area, in order of priority. */
2
3
  export declare function Slot({ area }: {
3
4
  area: string;
4
- }): JSX.Element;
5
+ }): React.JSX.Element;
5
6
  //# sourceMappingURL=slot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../../src/browser/slot/slot.tsx"],"names":[],"mappings":"AAIA,oDAAoD;AACpD,wBAAgB,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,eAa9C"}
1
+ {"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../../src/browser/slot/slot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,oDAAoD;AACpD,wBAAgB,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,qBAa9C"}
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a, _b;
6
+ var _c, _d;
2
7
  Object.defineProperty(exports, "__esModule", { value: true });
3
8
  const bun_test_1 = require("bun:test");
4
- (0, bun_test_1.describe)('react package', () => {
5
- (0, bun_test_1.it)('support code coverage statistics', () => { });
9
+ const test_module_1 = require("./browser/test/test-module");
10
+ const core_1 = require("@celljs/core");
11
+ const assembly_test_util_1 = require("@celljs/core/lib/common/test/assembly-test-util");
12
+ const static_module_1 = __importDefault(require("@celljs/core/lib/common/static-module"));
13
+ const app_1 = require("./browser/app");
14
+ const router_1 = require("./browser/router");
15
+ core_1.currentThis.cellProps = { react: { path: '/' } };
16
+ (_a = (_c = globalThis).localStorage) !== null && _a !== void 0 ? _a : (_c.localStorage = { getItem: () => null, setItem: () => undefined, removeItem: () => undefined });
17
+ // Node.js before 21 has no navigator; the LocaleManager reads its language.
18
+ (_b = (_d = globalThis).navigator) !== null && _b !== void 0 ? _b : (_d.navigator = { language: 'en-US' });
19
+ (0, bun_test_1.describe)('@celljs/react', () => {
20
+ // The components of this package and of @celljs/widget, without the shell, which needs a DOM.
21
+ (0, bun_test_1.it)('its components load after core and every binding resolves', () => {
22
+ const { container, changed, errors } = assembly_test_util_1.AssemblyTestUtil.check([static_module_1.default], test_module_1.reactTestModule);
23
+ (0, bun_test_1.expect)(errors).toEqual([]);
24
+ (0, bun_test_1.expect)(changed).toBeGreaterThan(0);
25
+ (0, bun_test_1.expect)(container.isBound(app_1.APP)).toBe(true);
26
+ (0, bun_test_1.expect)(container.isBound(router_1.ROUTER)).toBe(true);
27
+ (0, bun_test_1.expect)(container.get(router_1.RouteMetadataProvider).provide()).toEqual([]);
28
+ });
6
29
  });
7
30
  //# sourceMappingURL=package.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,IAAA,mBAAQ,EAAC,eAAe,EAAE,GAAG,EAAE;IAE3B,IAAA,aAAE,EAAC,kCAAkC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":";;;;;;;AAAA,uCAAgD;AAChD,4DAA6D;AAC7D,uCAA2C;AAC3C,wFAAmF;AACnF,0FAAiE;AACjE,uCAAoC;AACpC,6CAAiE;AAEjE,kBAAW,CAAC,SAAS,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;AACjD,YAAC,UAAkB,EAAC,YAAY,uCAAZ,YAAY,GAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,EAAC;AACpH,4EAA4E;AAC5E,YAAC,UAAkB,EAAC,SAAS,uCAAT,SAAS,GAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAC;AAExD,IAAA,mBAAQ,EAAC,eAAe,EAAE,GAAG,EAAE;IAC3B,8FAA8F;IAC9F,IAAA,aAAE,EAAC,2DAA2D,EAAE,GAAG,EAAE;QACjE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,qCAAgB,CAAC,KAAK,CAAC,CAAC,uBAAY,CAAC,EAAE,6BAAe,CAAC,CAAC;QAC/F,IAAA,iBAAM,EAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC3B,IAAA,iBAAM,EAAC,OAAO,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACnC,IAAA,iBAAM,EAAC,SAAS,CAAC,OAAO,CAAC,SAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAA,iBAAM,EAAC,SAAS,CAAC,OAAO,CAAC,eAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAA,iBAAM,EAAC,SAAS,CAAC,GAAG,CAAwB,8BAAqB,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/react",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "cell-component"
@@ -33,12 +33,11 @@
33
33
  "watch": "tsc -b -w --preserveWatchOutput"
34
34
  },
35
35
  "dependencies": {
36
- "@celljs/core": "4.5.0",
37
- "@celljs/widget": "4.5.0",
38
- "@types/react": "^18.0.17",
39
- "react": "^18.2.0",
40
- "react-dom": "^18.2.0",
41
- "react-intl": "^6.0.5",
36
+ "@celljs/core": "4.6.0",
37
+ "@celljs/widget": "4.6.0",
38
+ "@types/react": "^19.3.0",
39
+ "react": "^19.3.1",
40
+ "react-dom": "^19.3.1",
42
41
  "react-router": "^7.18.5"
43
42
  },
44
43
  "publishConfig": {
@@ -66,6 +65,10 @@
66
65
  "import": "./esm/browser/context/index.js",
67
66
  "default": "./lib/browser/context/index.js"
68
67
  },
68
+ "./lib/browser/error": {
69
+ "import": "./esm/browser/error/index.js",
70
+ "default": "./lib/browser/error/index.js"
71
+ },
69
72
  "./lib/browser/hooks": {
70
73
  "import": "./esm/browser/hooks/index.js",
71
74
  "default": "./lib/browser/hooks/index.js"
@@ -74,6 +77,10 @@
74
77
  "import": "./esm/browser/icon/index.js",
75
78
  "default": "./lib/browser/icon/index.js"
76
79
  },
80
+ "./lib/browser/intl": {
81
+ "import": "./esm/browser/intl/index.js",
82
+ "default": "./lib/browser/intl/index.js"
83
+ },
77
84
  "./lib/browser/layout": {
78
85
  "import": "./esm/browser/layout/index.js",
79
86
  "default": "./lib/browser/layout/index.js"
@@ -120,6 +127,15 @@
120
127
  }
121
128
  },
122
129
  "devDependencies": {
123
- "@types/react-dom": "^18.0.6"
130
+ "@types/react-dom": "^19.3.0",
131
+ "react-intl": "^7.1.14"
132
+ },
133
+ "peerDependencies": {
134
+ "react-intl": ">=6.0.0"
135
+ },
136
+ "peerDependenciesMeta": {
137
+ "react-intl": {
138
+ "optional": true
139
+ }
124
140
  }
125
141
  }
@@ -0,0 +1,49 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import * as React from 'react';
3
+ import { renderToStaticMarkup } from 'react-dom/server';
4
+ import { DefaultErrorFallback, ErrorBoundary, ErrorBoundaryProps, ErrorFallbackProps } from './error-boundary';
5
+
6
+ /** Server rendering does not catch errors, so the boundary is driven the way React drives it in the browser. */
7
+ function boundary(props: ErrorBoundaryProps) {
8
+ const instance = new ErrorBoundary(props);
9
+ instance.setState = (state: any) => {
10
+ instance.state = { ...instance.state, ...state };
11
+ };
12
+ return instance;
13
+ }
14
+
15
+ describe('ErrorBoundary', () => {
16
+
17
+ it('renders its children until one throws', () => {
18
+ expect(renderToStaticMarkup(<ErrorBoundary><p>page</p></ErrorBoundary>)).toBe('<p>page</p>');
19
+ });
20
+
21
+ it('then renders the fallback with the error, and the children again after reset', () => {
22
+ const Fallback = ({ error }: ErrorFallbackProps) => <p>failed: {(error as Error).message}</p>;
23
+ const instance = boundary({ fallback: Fallback, children: <p>page</p> });
24
+ instance.state = ErrorBoundary.getDerivedStateFromError(new Error('boom'));
25
+ expect(renderToStaticMarkup(<>{instance.render()}</>)).toBe('<p>failed: boom</p>');
26
+ instance.reset();
27
+ expect(renderToStaticMarkup(<>{instance.render()}</>)).toBe('<p>page</p>');
28
+ });
29
+
30
+ it('without a fallback shows the message and a button to try again', () => {
31
+ const instance = boundary({ children: null });
32
+ instance.state = ErrorBoundary.getDerivedStateFromError(new Error('chunk failed to load'));
33
+ const html = renderToStaticMarkup(<>{instance.render()}</>);
34
+ expect(html).toContain('role="alert"');
35
+ expect(html).toContain('<pre>chunk failed to load</pre>');
36
+ expect(html).toContain('Try again');
37
+ expect(renderToStaticMarkup(<DefaultErrorFallback error="text" reset={() => undefined} />)).toContain('<pre>text</pre>');
38
+ });
39
+
40
+ it('resets when resetKey changes (the user went to another page), not otherwise', () => {
41
+ const instance = boundary({ resetKey: '/a', children: <p>page</p> });
42
+ instance.state = ErrorBoundary.getDerivedStateFromError(new Error('boom'));
43
+ instance.componentDidUpdate({ resetKey: '/a' });
44
+ expect(instance.state.failed).toBe(true);
45
+ (instance as any).props = { ...instance.props, resetKey: '/b' };
46
+ instance.componentDidUpdate({ resetKey: '/a' });
47
+ expect(instance.state.failed).toBe(false);
48
+ });
49
+ });
@@ -0,0 +1,62 @@
1
+ import * as React from 'react';
2
+
3
+ export interface ErrorFallbackProps {
4
+ /** What the component threw, or why its code could not be loaded. */
5
+ error: unknown;
6
+ /** Renders the children again. */
7
+ reset(): void;
8
+ }
9
+
10
+ export interface ErrorBoundaryProps extends React.PropsWithChildren {
11
+ /** What shows instead of the children when they fail; {@link DefaultErrorFallback} by default. */
12
+ fallback?: React.ComponentType<ErrorFallbackProps>;
13
+ /** When it changes (the path of the page), a failed boundary renders its children again. */
14
+ resetKey?: unknown;
15
+ }
16
+
17
+ interface ErrorBoundaryState {
18
+ failed: boolean;
19
+ error?: unknown;
20
+ }
21
+
22
+ /**
23
+ * Catches the errors of the components below it, rendering or loading (a page chunk that does not
24
+ * load), and shows the fallback instead: one failing page does not blank the application. React logs
25
+ * the error to the console.
26
+ */
27
+ export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
28
+
29
+ override state: ErrorBoundaryState = { failed: false };
30
+
31
+ static getDerivedStateFromError(error: unknown): ErrorBoundaryState {
32
+ return { failed: true, error };
33
+ }
34
+
35
+ override componentDidUpdate(previous: ErrorBoundaryProps): void {
36
+ if (this.state.failed && previous.resetKey !== this.props.resetKey) {
37
+ this.reset();
38
+ }
39
+ }
40
+
41
+ readonly reset = (): void => this.setState({ failed: false, error: undefined });
42
+
43
+ override render(): React.ReactNode {
44
+ if (this.state.failed) {
45
+ const Fallback = this.props.fallback ?? DefaultErrorFallback;
46
+ return <Fallback error={this.state.error} reset={this.reset} />;
47
+ }
48
+ return this.props.children;
49
+ }
50
+ }
51
+
52
+ /** The message of the error and a button to try again. */
53
+ export function DefaultErrorFallback({ error, reset }: ErrorFallbackProps) {
54
+ const message = error instanceof Error ? error.message : String(error);
55
+ return (
56
+ <div role="alert" className="cell-error">
57
+ <p>Something went wrong.</p>
58
+ <pre>{message}</pre>
59
+ <button type="button" onClick={reset}>Try again</button>
60
+ </div>
61
+ );
62
+ }
@@ -0,0 +1 @@
1
+ export * from './error-boundary';
@@ -1,15 +1,21 @@
1
1
  import { reactTestModule } from '../test/test-module';
2
2
  import { describe, expect, it } from 'bun:test';
3
- import { autoBind, Component, ContainerProvider, Value } from '@celljs/core';
3
+ import { autoBind, Component, Container, ContainerModule, Value } from '@celljs/core';
4
+ import { LocaleManager } from '@celljs/widget';
4
5
  import { ApplicationFactory } from '@celljs/core/lib/common/application/application-factory';
5
6
  import * as React from 'react';
6
7
  import { renderToStaticMarkup } from 'react-dom/server';
7
8
  import { Context, View } from '../annotation';
8
9
  import { AppImpl } from '../app';
9
10
  import { ContainerContext, useInject, useValue } from './container-hooks';
11
+ import { useRpc } from './rpc-hooks';
12
+ import { useLocale } from '../locale';
10
13
 
11
14
  const storage = new Map<string, string>();
12
- (globalThis as any).localStorage ??= {
15
+ // Node.js before 21 has no navigator; the LocaleManager reads its language.
16
+ (globalThis as any).navigator ??= { language: 'en-US' };
17
+ // Its own storage: the useLocale test reads what was saved (other spec files set a stub).
18
+ (globalThis as any).localStorage = {
13
19
  getItem: (key: string) => storage.get(key) ?? null,
14
20
  setItem: (key: string, value: string) => storage.set(key, value),
15
21
  removeItem: (key: string) => storage.delete(key),
@@ -51,9 +57,8 @@ export class FramedContext {}
51
57
 
52
58
  // autoBind() takes what was registered since the previous call: the classes of this file.
53
59
  const specModule = autoBind();
54
- async function boot(app: Record<string, unknown>, react: Record<string, unknown> = {}) {
55
- await ApplicationFactory.create({ app, react: { path: '/', router: { type: 'memory' }, ...react } }, reactTestModule, specModule);
56
- return ContainerProvider.provide();
60
+ async function boot(app: Record<string, unknown>, react: Record<string, unknown> = {}): Promise<Container> {
61
+ return ApplicationFactory.createContainer({ app, react: { path: '/', router: { type: 'memory' }, ...react } }, reactTestModule, specModule);
57
62
  }
58
63
 
59
64
  describe('@celljs/react hooks', () => {
@@ -67,9 +72,14 @@ describe('@celljs/react hooks', () => {
67
72
  expect(render(fr)).toBe('<p>Bonjour, nobody</p>');
68
73
  });
69
74
 
70
- it('without a ContainerContext they use the container of the application', async () => {
71
- await boot({ greeting: 'Hi', name: 'Bob' });
72
- expect(renderToStaticMarkup(<Hello />)).toBe('<p>Hi, Bob</p>');
75
+ it('without a ContainerContext they fail and say where to render the component', () => {
76
+ const error = console.error;
77
+ console.error = () => undefined;
78
+ try {
79
+ expect(() => renderToStaticMarkup(<Hello />)).toThrow('No DI container');
80
+ } finally {
81
+ console.error = error;
82
+ }
73
83
  });
74
84
 
75
85
  it('the App renders the routes inside the @Context providers', async () => {
@@ -84,4 +94,50 @@ describe('@celljs/react hooks', () => {
84
94
  console.error = error;
85
95
  }
86
96
  });
87
- });
97
+
98
+ it('useRpc gives the proxy @celljs/rpc binds for the service id', async () => {
99
+ const GreetingServer = Symbol('GreetingServer');
100
+ const rpc = new ContainerModule(bind => {
101
+ bind(Symbol.for('@celljs/rpc/RPC')).toDynamicValue(ctx => ({ greet: () => `proxy of ${(ctx.target.tags![Symbol.for('@celljs/rpc/ID_KEY')] as symbol).description}` }));
102
+ });
103
+ const container = ApplicationFactory.createContainer({ react: { path: '/' } }, reactTestModule, rpc);
104
+ function Greeting() {
105
+ return <p>{useRpc<{ greet(): string }>(GreetingServer).greet()}</p>;
106
+ }
107
+ expect(renderToStaticMarkup(<ContainerContext.Provider value={container}><Greeting /></ContainerContext.Provider>)).toBe('<p>proxy of GreetingServer</p>');
108
+ });
109
+
110
+ it('useRpc without @celljs/rpc says what to add', async () => {
111
+ const container = await boot({});
112
+ function Greeting() {
113
+ useRpc(Symbol('GreetingServer'));
114
+ return null;
115
+ }
116
+ const error = console.error;
117
+ console.error = () => undefined;
118
+ try {
119
+ expect(() => renderToStaticMarkup(<ContainerContext.Provider value={container}><Greeting /></ContainerContext.Provider>)).toThrow('useRpc needs @celljs/rpc');
120
+ } finally {
121
+ console.error = error;
122
+ }
123
+ });
124
+
125
+ it('useLocale reads the locale of the LocaleManager and changes it', async () => {
126
+ storage.clear();
127
+ const container = ApplicationFactory.createContainer({ react: { path: '/' }, widget: { locales: { en: { priority: 2, messages: {} }, fr: { priority: 1, messages: {} } } } }, reactTestModule);
128
+ // The manager selects the locale once created; the page creates it on its first render.
129
+ const manager = container.get<LocaleManager>(LocaleManager);
130
+ await new Promise(resolve => setTimeout(resolve));
131
+ let change: (l: any) => void = () => undefined;
132
+ function Lang() {
133
+ const [locale, setLocale] = useLocale();
134
+ change = setLocale;
135
+ return <p>{locale?.lang}</p>;
136
+ }
137
+ const render = () => renderToStaticMarkup(<ContainerContext.Provider value={container}><Lang /></ContainerContext.Provider>);
138
+ expect(render()).toBe('<p>en</p>');
139
+ change((await manager.get())[1]);
140
+ expect(render()).toBe('<p>fr</p>');
141
+ expect(storage.get('cell:lang')).toBe('fr');
142
+ });
143
+ });
@@ -1,4 +1,4 @@
1
- import { ComponentId, ConfigProvider, Container, ContainerProvider } from '@celljs/core';
1
+ import { ComponentId, ConfigProvider, Container } from '@celljs/core';
2
2
  import * as React from 'react';
3
3
 
4
4
  /**
@@ -7,17 +7,13 @@ import * as React from 'react';
7
7
  */
8
8
  export const ContainerContext = React.createContext<Container | undefined>(undefined);
9
9
 
10
- /** The container of {@link ContainerContext}, else the application's (a component rendered in its own root). */
10
+ /** The container of {@link ContainerContext}. */
11
11
  export function useContainer(): Container {
12
12
  const container = React.useContext(ContainerContext);
13
- if (container) {
14
- return container;
15
- }
16
- try {
17
- return ContainerProvider.provide();
18
- } catch {
19
- throw new Error('No DI container: render the component inside <ContainerContext.Provider value={container}>, or after the application has started.');
13
+ if (!container) {
14
+ throw new Error('No DI container: render the component inside the application, or inside <ContainerContext.Provider value={container}> in a test.');
20
15
  }
16
+ return container;
21
17
  }
22
18
 
23
19
  /** A component of the container, resolved once per component instance (and again if the container changes). */
@@ -1 +1,2 @@
1
1
  export * from './container-hooks';
2
+ export * from './rpc-hooks';
@@ -0,0 +1,21 @@
1
+ import type { ComponentId } from '@celljs/core';
2
+ import * as React from 'react';
3
+ import { useContainer } from './container-hooks';
4
+
5
+ // The identifiers of @celljs/rpc (global symbols), so this package does not depend on it.
6
+ const RPC = Symbol.for('@celljs/rpc/RPC');
7
+ const ID_KEY = Symbol.for('@celljs/rpc/ID_KEY');
8
+
9
+ /**
10
+ * The proxy of a backend service, as `@Autorpc(id)` injects it: `useRpc<GreetingServer>(GreetingServer)`.
11
+ * Its methods return promises; call them in an effect or an event handler. Needs `@celljs/rpc`.
12
+ */
13
+ export function useRpc<T extends object>(id: ComponentId<T>): T {
14
+ const container = useContainer();
15
+ return React.useMemo(() => {
16
+ if (!container.isBound(RPC)) {
17
+ throw new Error('useRpc needs @celljs/rpc: add it to the dependencies of the project.');
18
+ }
19
+ return container.get<T>(RPC, { tags: { [ID_KEY]: id } });
20
+ }, [container, id]);
21
+ }
@@ -1,19 +1,20 @@
1
1
  import * as React from 'react';
2
- import { ContainerUtil } from '@celljs/core';
3
2
  import { IconResolver } from './icon-protocol';
3
+ import { useInject } from '../hooks';
4
4
 
5
5
  const { useState, useEffect } = React;
6
6
 
7
7
  export function Icon<T>(iconProps: T) {
8
+ const iconResolver = useInject<IconResolver<T>>(IconResolver);
8
9
  const [iconNode, setIconNode] = useState<React.ReactNode>([]);
9
10
 
10
11
  useEffect(() => {
11
- const resolve = async () => {
12
- const iconResolver = ContainerUtil.get<IconResolver<T>>(IconResolver);
13
- setIconNode(await iconResolver.resolve(iconProps));
12
+ let current = true;
13
+ iconResolver.resolve(iconProps).then(node => current && setIconNode(node));
14
+ return () => {
15
+ current = false;
14
16
  };
15
- resolve();
16
- }, [JSON.stringify(iconProps)]);
17
+ }, [iconResolver, JSON.stringify(iconProps)]);
17
18
 
18
19
  return (<>{iconNode}</>);
19
20
  }
@@ -1,6 +1,7 @@
1
1
  export * from './annotation';
2
2
  export * from './hooks';
3
3
  export * from './app';
4
+ export * from './error';
4
5
  export * from './layout';
5
6
  export * from './context';
6
7
  export * from './router';
@@ -9,4 +10,4 @@ export * from './resolver';
9
10
  export * from './widget';
10
11
  export * from './slot';
11
12
  export * from './icon';
12
- export * from './locale';
13
+ export * from './locale';
@@ -0,0 +1 @@
1
+ export * from './intl-context';
@@ -0,0 +1,31 @@
1
+ import * as React from 'react';
2
+ import { IntlProvider } from 'react-intl';
3
+ import { Logger } from '@celljs/core';
4
+ import { Context } from '../annotation';
5
+ import { useInject } from '../hooks';
6
+ import { useLocale } from '../locale';
7
+
8
+ export const INTL_REACT_CONTEXT_PRIORITY = 3000;
9
+
10
+ /**
11
+ * The `IntlProvider` of react-intl around the application, with the messages of the selected locale. Not
12
+ * loaded by default: a project that uses react-intl installs it and imports `@celljs/react/lib/browser/intl`
13
+ * once, in `src/browser/module.ts`.
14
+ */
15
+ export function IntlContext({ children }: React.PropsWithChildren) {
16
+ const [locale] = useLocale();
17
+ const logger = useInject<Logger>(Logger);
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
+ IntlContext.priority = INTL_REACT_CONTEXT_PRIORITY;
29
+
30
+ @Context(IntlContext)
31
+ export default class {}
@@ -1,2 +1 @@
1
- export * from './locale-protocol';
2
- export * from './locale-context';
1
+ export * from './locale-hooks';
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { Locale, LocaleManager } from '@celljs/widget';
3
+ import { useInject } from '../hooks';
4
+
5
+ /** The locale the user selected (`widget.locales`), and how to change it; renders again when it changes. */
6
+ export function useLocale(): [Locale | undefined, (locale: Locale) => void] {
7
+ const localeManager = useInject<LocaleManager>(LocaleManager);
8
+ const subscribe = React.useCallback((onChange: () => void) => {
9
+ const listener = localeManager.onCurrentChanged(onChange);
10
+ return () => listener.dispose();
11
+ }, [localeManager]);
12
+ const locale = React.useSyncExternalStore(subscribe, () => localeManager.current, () => localeManager.current);
13
+ const setLocale = React.useCallback((l: Locale) => localeManager.setCurrent(l), [localeManager]);
14
+ return [locale, setLocale];
15
+ }
@@ -1,6 +1,5 @@
1
1
  import { reactTestModule } from '../test/test-module';
2
2
  import { afterAll, describe, expect, it } from 'bun:test';
3
- import { ContainerProvider } from '@celljs/core';
4
3
  import { ApplicationFactory } from '@celljs/core/lib/common/application/application-factory';
5
4
  import * as React from 'react';
6
5
  import { renderToPipeableStream } from 'react-dom/server';
@@ -12,6 +11,8 @@ import { FileRouteUtil } from './file-route-util';
12
11
  import { FileRoute } from './router-protocol';
13
12
 
14
13
  (globalThis as any).localStorage ??= { getItem: () => null, setItem: () => undefined, removeItem: () => undefined };
14
+ // Node.js before 21 has no navigator; the LocaleManager reads its language.
15
+ (globalThis as any).navigator ??= { language: 'en-US' };
15
16
 
16
17
  const Shell = ({ children }: React.PropsWithChildren) => <div className="shell">{children}</div>;
17
18
  const Admin = ({ children }: React.PropsWithChildren) => <section>{children}</section>;
@@ -62,14 +63,24 @@ describe('FileRouteUtil', () => {
62
63
  expect(FileRouteUtil.toMetadata(page('/c', 'pages/c.tsx', () => null, [])).layout).toBeUndefined();
63
64
  });
64
65
 
66
+ it('gives a page the component of its _error file as errorFallback, one per file', async () => {
67
+ const Oops = ({ error }: { error: unknown }) => <p>oops: {String((error as Error).message)}</p>;
68
+ const error = { file: 'pages/_error.tsx', load: async () => ({ default: Oops }) };
69
+ const a = FileRouteUtil.toMetadata({ ...page('/a', 'pages/a.tsx', () => null), error });
70
+ const b = FileRouteUtil.toMetadata({ ...page('/b', 'pages/b.tsx', () => null), error });
71
+ expect(a.errorFallback).toBe(b.errorFallback!);
72
+ expect(FileRouteUtil.toMetadata(page('/c', 'pages/c.tsx', () => null)).errorFallback).toBeUndefined();
73
+ const Fallback = a.errorFallback!;
74
+ expect(await html(<Fallback error={new Error('boom')} reset={() => undefined} />)).toBe('<p>oops: boom</p>');
75
+ });
76
+
65
77
  it('fails with the file when a page has no default export', () => {
66
78
  expect(() => FileRouteUtil.componentOf({}, 'src/browser/pages/about.tsx')).toThrow('src/browser/pages/about.tsx has no default export');
67
79
  });
68
80
 
69
81
  it('the App renders the generated pages with the router of the application', async () => {
70
82
  routes.push(page('/', 'pages/index.tsx', () => <h1>Home</h1>));
71
- await ApplicationFactory.create({ react: { path: '/', router: { type: 'memory' } } }, reactTestModule);
72
- const container = ContainerProvider.provide();
83
+ const container = ApplicationFactory.createContainer({ react: { path: '/', router: { type: 'memory' } } }, reactTestModule);
73
84
  expect(await html(<ContainerContext.Provider value={container}><AppImpl /></ContainerContext.Provider>)).toBe('<div class="shell"><h1>Home</h1></div>');
74
85
  });
75
- });
86
+ });
@@ -1,10 +1,12 @@
1
1
  import * as React from 'react';
2
2
  import { FileRoute, RouteMetadata } from './router-protocol';
3
+ import type { ErrorFallbackProps } from '../error';
3
4
 
4
5
  type Loaded<P> = { default?: React.ComponentType<P> };
5
6
 
6
7
  const pages = new Map<string, React.ComponentType>();
7
8
  const layouts = new Map<string, React.ComponentType<React.PropsWithChildren>>();
9
+ const errors = new Map<string, React.ComponentType<ErrorFallbackProps>>();
8
10
 
9
11
  /** Pages of `src/browser/pages` as route metadata: lazy components, so each page is loaded when visited. */
10
12
  export namespace FileRouteUtil {
@@ -15,9 +17,19 @@ export namespace FileRouteUtil {
15
17
  priority: 1000,
16
18
  component: page(route),
17
19
  ...(route.layouts.length ? { layout: layout(route) } : {}),
20
+ ...(route.error ? { errorFallback: errorFallback(route.error) } : {}),
18
21
  };
19
22
  }
20
23
 
24
+ function errorFallback(error: NonNullable<FileRoute['error']>): React.ComponentType<ErrorFallbackProps> {
25
+ let component = errors.get(error.file);
26
+ if (!component) {
27
+ component = React.lazy(async () => ({ default: componentOf(await error.load(), error.file) }));
28
+ errors.set(error.file, component);
29
+ }
30
+ return component;
31
+ }
32
+
21
33
  /** One component per file (and per chain of layouts): React keeps a layout mounted from one page to the next. */
22
34
  function page(route: FileRoute): React.ComponentType {
23
35
  let component = pages.get(route.file);
@@ -1,3 +1,5 @@
1
+ import type { ErrorFallbackProps } from '../error';
2
+
1
3
  export const ROUTER = Symbol('Router');
2
4
  export const ROUTE_METADATA = Symbol('ROUTE_METADATA');
3
5
 
@@ -11,6 +13,8 @@ export interface RouteMetadata {
11
13
  path?: string;
12
14
  component?: React.ComponentType;
13
15
  layout?: React.ComponentType<React.PropsWithChildren>;
16
+ /** What shows, inside the layout, when the page fails; `DefaultErrorFallback` by default. */
17
+ errorFallback?: React.ComponentType<ErrorFallbackProps>;
14
18
  priority?: number;
15
19
  }
16
20
 
@@ -35,4 +39,6 @@ export interface FileRoute {
35
39
  load(): Promise<{ default?: React.ComponentType }>;
36
40
  /** The `_layout` files around the page, outermost first. */
37
41
  layouts: { file: string; load(): Promise<{ default?: React.ComponentType<React.PropsWithChildren> }> }[];
42
+ /** The nearest `_error` file: what shows when the page fails. */
43
+ error?: { file: string; load(): Promise<{ default?: React.ComponentType<ErrorFallbackProps> }> };
38
44
  }