@celljs/react 4.2.0 → 4.4.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 (145) hide show
  1. package/README.md +73 -1
  2. package/cell.schema.json +35 -0
  3. package/cell.yml +4 -6
  4. package/esm/browser/annotation/route.js +7 -2
  5. package/esm/browser/annotation/route.js.map +1 -1
  6. package/esm/browser/app/app.d.ts +3 -6
  7. package/esm/browser/app/app.js +14 -25
  8. package/esm/browser/app/app.js.map +1 -1
  9. package/esm/browser/hooks/container-hooks.d.ts +13 -0
  10. package/esm/browser/hooks/container-hooks.js +31 -0
  11. package/esm/browser/hooks/container-hooks.js.map +1 -0
  12. package/esm/browser/hooks/index.d.ts +1 -0
  13. package/esm/browser/hooks/index.js +2 -0
  14. package/esm/browser/hooks/index.js.map +1 -0
  15. package/esm/browser/index.d.ts +1 -0
  16. package/esm/browser/index.js +1 -0
  17. package/esm/browser/index.js.map +1 -1
  18. package/esm/browser/locale/locale-context.js +6 -5
  19. package/esm/browser/locale/locale-context.js.map +1 -1
  20. package/esm/browser/resolver/path-resolver.js +1 -1
  21. package/esm/browser/resolver/path-resolver.js.map +1 -1
  22. package/esm/browser/router/dynamic-routes.d.ts +6 -0
  23. package/esm/browser/router/dynamic-routes.js +6 -0
  24. package/esm/browser/router/dynamic-routes.js.map +1 -0
  25. package/esm/browser/router/file-route-util.d.ts +11 -0
  26. package/esm/browser/router/file-route-util.js +47 -0
  27. package/esm/browser/router/file-route-util.js.map +1 -0
  28. package/esm/browser/router/index.d.ts +2 -0
  29. package/esm/browser/router/index.js +3 -0
  30. package/esm/browser/router/index.js.map +1 -1
  31. package/esm/browser/router/route-metadata-converter.d.ts +2 -2
  32. package/esm/browser/router/route-metadata-converter.js +6 -5
  33. package/esm/browser/router/route-metadata-converter.js.map +1 -1
  34. package/esm/browser/router/route-metadata-provider.js +9 -2
  35. package/esm/browser/router/route-metadata-provider.js.map +1 -1
  36. package/esm/browser/router/router-protocol.d.ts +18 -1
  37. package/esm/browser/router/router.js +27 -30
  38. package/esm/browser/router/router.js.map +1 -1
  39. package/esm/browser/shell/shell.js +4 -2
  40. package/esm/browser/shell/shell.js.map +1 -1
  41. package/esm/browser/slot/slot.d.ts +1 -0
  42. package/esm/browser/slot/slot.js +11 -10
  43. package/esm/browser/slot/slot.js.map +1 -1
  44. package/esm/browser/test/test-module.d.ts +15 -0
  45. package/esm/browser/test/test-module.js +17 -0
  46. package/esm/browser/test/test-module.js.map +1 -0
  47. package/esm/browser/widget/widget-factory.d.ts +1 -0
  48. package/esm/browser/widget/widget-factory.js +5 -1
  49. package/esm/browser/widget/widget-factory.js.map +1 -1
  50. package/lib/browser/annotation/route.js +7 -2
  51. package/lib/browser/annotation/route.js.map +1 -1
  52. package/lib/browser/app/app.d.ts +3 -6
  53. package/lib/browser/app/app.d.ts.map +1 -1
  54. package/lib/browser/app/app.js +15 -26
  55. package/lib/browser/app/app.js.map +1 -1
  56. package/lib/browser/hooks/container-hooks.d.ts +14 -0
  57. package/lib/browser/hooks/container-hooks.d.ts.map +1 -0
  58. package/lib/browser/hooks/container-hooks.js +70 -0
  59. package/lib/browser/hooks/container-hooks.js.map +1 -0
  60. package/lib/browser/hooks/container-hooks.spec.d.ts +14 -0
  61. package/lib/browser/hooks/container-hooks.spec.d.ts.map +1 -0
  62. package/lib/browser/hooks/container-hooks.spec.js +136 -0
  63. package/lib/browser/hooks/container-hooks.spec.js.map +1 -0
  64. package/lib/browser/hooks/index.d.ts +2 -0
  65. package/lib/browser/hooks/index.d.ts.map +1 -0
  66. package/lib/browser/hooks/index.js +18 -0
  67. package/lib/browser/hooks/index.js.map +1 -0
  68. package/lib/browser/index.d.ts +1 -0
  69. package/lib/browser/index.d.ts.map +1 -1
  70. package/lib/browser/index.js +1 -0
  71. package/lib/browser/index.js.map +1 -1
  72. package/lib/browser/locale/locale-context.d.ts.map +1 -1
  73. package/lib/browser/locale/locale-context.js +5 -4
  74. package/lib/browser/locale/locale-context.js.map +1 -1
  75. package/lib/browser/resolver/path-resolver.js +1 -1
  76. package/lib/browser/resolver/path-resolver.js.map +1 -1
  77. package/lib/browser/router/dynamic-routes.d.ts +7 -0
  78. package/lib/browser/router/dynamic-routes.d.ts.map +1 -0
  79. package/lib/browser/router/dynamic-routes.js +9 -0
  80. package/lib/browser/router/dynamic-routes.js.map +1 -0
  81. package/lib/browser/router/file-route-util.d.ts +12 -0
  82. package/lib/browser/router/file-route-util.d.ts.map +1 -0
  83. package/lib/browser/router/file-route-util.js +83 -0
  84. package/lib/browser/router/file-route-util.js.map +1 -0
  85. package/lib/browser/router/file-route-util.spec.d.ts +2 -0
  86. package/lib/browser/router/file-route-util.spec.d.ts.map +1 -0
  87. package/lib/browser/router/file-route-util.spec.js +105 -0
  88. package/lib/browser/router/file-route-util.spec.js.map +1 -0
  89. package/lib/browser/router/index.d.ts +2 -0
  90. package/lib/browser/router/index.d.ts.map +1 -1
  91. package/lib/browser/router/index.js +13 -0
  92. package/lib/browser/router/index.js.map +1 -1
  93. package/lib/browser/router/route-metadata-converter.d.ts +2 -2
  94. package/lib/browser/router/route-metadata-converter.d.ts.map +1 -1
  95. package/lib/browser/router/route-metadata-converter.js +6 -5
  96. package/lib/browser/router/route-metadata-converter.js.map +1 -1
  97. package/lib/browser/router/route-metadata-provider.d.ts.map +1 -1
  98. package/lib/browser/router/route-metadata-provider.js +8 -1
  99. package/lib/browser/router/route-metadata-provider.js.map +1 -1
  100. package/lib/browser/router/router-protocol.d.ts +18 -1
  101. package/lib/browser/router/router-protocol.d.ts.map +1 -1
  102. package/lib/browser/router/router.d.ts.map +1 -1
  103. package/lib/browser/router/router.js +30 -33
  104. package/lib/browser/router/router.js.map +1 -1
  105. package/lib/browser/router/router.spec.d.ts +9 -0
  106. package/lib/browser/router/router.spec.d.ts.map +1 -0
  107. package/lib/browser/router/router.spec.js +108 -0
  108. package/lib/browser/router/router.spec.js.map +1 -0
  109. package/lib/browser/shell/shell.d.ts.map +1 -1
  110. package/lib/browser/shell/shell.js +3 -1
  111. package/lib/browser/shell/shell.js.map +1 -1
  112. package/lib/browser/slot/slot.d.ts +1 -0
  113. package/lib/browser/slot/slot.d.ts.map +1 -1
  114. package/lib/browser/slot/slot.js +11 -10
  115. package/lib/browser/slot/slot.js.map +1 -1
  116. package/lib/browser/test/test-module.d.ts +16 -0
  117. package/lib/browser/test/test-module.d.ts.map +1 -0
  118. package/lib/browser/test/test-module.js +20 -0
  119. package/lib/browser/test/test-module.js.map +1 -0
  120. package/lib/browser/widget/widget-factory.d.ts +1 -0
  121. package/lib/browser/widget/widget-factory.d.ts.map +1 -1
  122. package/lib/browser/widget/widget-factory.js +4 -0
  123. package/lib/browser/widget/widget-factory.js.map +1 -1
  124. package/package.json +11 -7
  125. package/src/browser/annotation/route.ts +7 -2
  126. package/src/browser/app/app.tsx +12 -20
  127. package/src/browser/hooks/container-hooks.spec.tsx +87 -0
  128. package/src/browser/hooks/container-hooks.ts +33 -0
  129. package/src/browser/hooks/index.ts +1 -0
  130. package/src/browser/index.ts +2 -1
  131. package/src/browser/locale/locale-context.tsx +6 -5
  132. package/src/browser/resolver/path-resolver.ts +1 -1
  133. package/src/browser/router/dynamic-routes.ts +7 -0
  134. package/src/browser/router/file-route-util.spec.tsx +75 -0
  135. package/src/browser/router/file-route-util.ts +53 -0
  136. package/src/browser/router/index.ts +3 -0
  137. package/src/browser/router/route-metadata-converter.ts +7 -8
  138. package/src/browser/router/route-metadata-provider.tsx +8 -5
  139. package/src/browser/router/router-protocol.ts +11 -1
  140. package/src/browser/router/router.spec.tsx +66 -0
  141. package/src/browser/router/router.tsx +29 -31
  142. package/src/browser/shell/shell.tsx +4 -2
  143. package/src/browser/slot/slot.tsx +11 -10
  144. package/src/browser/test/test-module.ts +17 -0
  145. package/src/browser/widget/widget-factory.ts +3 -1
@@ -41,43 +41,40 @@ var __importStar = (this && this.__importStar) || (function () {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  const React = __importStar(require("react"));
43
43
  const router_protocol_1 = require("./router-protocol");
44
- const react_router_dom_1 = require("react-router-dom");
44
+ const react_router_1 = require("react-router");
45
45
  const annotation_1 = require("../annotation");
46
- const core_1 = require("@celljs/core");
46
+ const hooks_1 = require("../hooks");
47
47
  const routerMap = {
48
- browser: react_router_dom_1.BrowserRouter,
49
- hash: react_router_dom_1.HashRouter,
50
- memory: react_router_dom_1.MemoryRouter
48
+ browser: react_router_1.BrowserRouter,
49
+ hash: react_router_1.HashRouter,
50
+ memory: react_router_1.MemoryRouter
51
51
  };
52
- const RouteComponent = () => {
53
- const element = (0, react_router_dom_1.useRoutes)(buildRoutes());
54
- return element;
55
- };
56
- const RouterComponent = () => {
57
- const routerType = core_1.ConfigUtil.get('cell.react.router.type');
58
- return React.createElement(routerMap[routerType], {}, React.createElement(RouteComponent));
59
- };
60
- const buildRoutes = () => {
61
- const routeMetadataProvider = core_1.ContainerUtil.get(router_protocol_1.RouteMetadataProvider);
62
- return routeMetadataProvider.provide().map(metadata => {
63
- // eslint-disable-next-line no-null/no-null
64
- let element;
65
- if (metadata.component) {
66
- if (metadata.layout) {
67
- element = React.createElement(metadata.layout, {}, React.createElement(metadata.component));
68
- }
69
- else {
70
- element = React.createElement(metadata.component);
71
- }
52
+ function Routes({ routes }) {
53
+ return (0, react_router_1.useRoutes)(routes);
54
+ }
55
+ function RouterComponent() {
56
+ const routerType = (0, hooks_1.useValue)('react.router.type', 'browser');
57
+ const routeMetadataProvider = (0, hooks_1.useInject)(router_protocol_1.RouteMetadataProvider);
58
+ const routes = React.useMemo(() => routeMetadataProvider.provide().map(toRouteObject), [routeMetadataProvider]);
59
+ return React.createElement(routerMap[routerType], {}, React.createElement(Routes, { routes }));
60
+ }
61
+ function toRouteObject(metadata) {
62
+ let element;
63
+ if (metadata.component) {
64
+ element = React.createElement(metadata.component);
65
+ if (metadata.layout) {
66
+ element = React.createElement(metadata.layout, {}, element);
72
67
  }
73
- return {
74
- path: metadata.path,
75
- index: metadata.index,
76
- caseSensitive: metadata.caseSensitive,
77
- element
78
- };
79
- });
80
- };
68
+ // Pages of src/browser/pages and their layouts are lazy components.
69
+ element = React.createElement(React.Suspense, { fallback: null }, element);
70
+ }
71
+ return {
72
+ path: metadata.path,
73
+ index: metadata.index,
74
+ caseSensitive: metadata.caseSensitive,
75
+ element
76
+ };
77
+ }
81
78
  let default_1 = class {
82
79
  };
83
80
  default_1 = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/browser/router/router.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,KAAK,kCAAc;AAC/B,uDAA0D;AAC1D,uDAAmG;AACnG,8CAAuC;AACvC,uCAAyD;AAEzD,MAAM,SAAS,GAAG;IACd,OAAO,EAAE,gCAAa;IACtB,IAAI,EAAE,6BAAU;IAChB,MAAM,EAAE,+BAAY;CACvB,CAAC;AAEF,MAAM,cAAc,GAAG,GAAG,EAAE;IACxB,MAAM,OAAO,GAAG,IAAA,4BAAS,EAAC,WAAW,EAAE,CAAC,CAAC;IACzC,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,GAAG,EAAE;IACzB,MAAM,UAAU,GAAG,iBAAU,CAAC,GAAG,CAAqB,wBAAwB,CAAC,CAAC;IAChF,OAAO,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;AAC/F,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,GAAkB,EAAE;IACpC,MAAM,qBAAqB,GAAG,oBAAa,CAAC,GAAG,CAAwB,uCAAqB,CAAC,CAAC;IAC9F,OAAO,qBAAqB,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;QAClD,2CAA2C;QAC3C,IAAI,OAA+B,CAAC;QACpC,IAAI,QAAQ,CAA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,GAAG,EAAE,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAChH,OAAO,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AACnG,CAAC;AAED,SAAS,aAAa,CAAC,QAAuB;IAC1C,IAAI,OAAwB,CAAC;IAC7B,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;QACrB,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAClD,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YAClB,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QAChE,CAAC;QACD,oEAAoE;QACpE,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO;QACH,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,aAAa,EAAE,QAAQ,CAAC,aAAa;QACrC,OAAO;KACK,CAAC;AACrB,CAAC;AAGc,gBAAA;CAAQ,CAAA;AAAR;IADd,IAAA,mBAAM,EAAC,eAAe,EAAE,KAAK,CAAC;aACR"}
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ export declare class HomeView {
3
+ }
4
+ export declare class AboutView extends React.Component {
5
+ render(): JSX.Element;
6
+ }
7
+ export declare class LogoWidget {
8
+ }
9
+ //# sourceMappingURL=router.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.spec.d.ts","sourceRoot":"","sources":["../../../src/browser/router/router.spec.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,qBACa,QAAQ;CAAG;AAExB,qBACa,SAAU,SAAQ,KAAK,CAAC,SAAS;IACjC,MAAM,gBAEd;CACJ;AAED,qBACa,UAAU;CAAG"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.LogoWidget = exports.AboutView = exports.HomeView = void 0;
43
+ const bun_test_1 = require("bun:test");
44
+ const test_module_1 = require("../test/test-module");
45
+ const core_1 = require("@celljs/core");
46
+ const application_factory_1 = require("@celljs/core/lib/common/application/application-factory");
47
+ const widget_1 = require("@celljs/widget");
48
+ const React = __importStar(require("react"));
49
+ const server_1 = require("react-dom/server");
50
+ const annotation_1 = require("../annotation");
51
+ const layout_1 = require("../layout");
52
+ const router_protocol_1 = require("./router-protocol");
53
+ const Home = () => React.createElement("h1", null, "Home");
54
+ const About = () => React.createElement("h1", null, "About");
55
+ const Logo = ({ text }) => React.createElement("b", null, text !== null && text !== void 0 ? text : 'logo');
56
+ let HomeView = class HomeView {
57
+ };
58
+ exports.HomeView = HomeView;
59
+ exports.HomeView = HomeView = __decorate([
60
+ (0, annotation_1.View)({ index: true, component: Home })
61
+ ], HomeView);
62
+ let AboutView = class AboutView extends React.Component {
63
+ render() {
64
+ return React.createElement(About, null);
65
+ }
66
+ };
67
+ exports.AboutView = AboutView;
68
+ exports.AboutView = AboutView = __decorate([
69
+ (0, annotation_1.View)('/about')
70
+ ], AboutView);
71
+ let LogoWidget = class LogoWidget {
72
+ };
73
+ exports.LogoWidget = LogoWidget;
74
+ exports.LogoWidget = LogoWidget = __decorate([
75
+ (0, widget_1.Widget)({ id: 'logo', area: 'header', component: Logo })
76
+ ], LogoWidget);
77
+ // autoBind() takes what was registered since the previous call: the classes of this file.
78
+ const specModule = (0, core_1.autoBind)();
79
+ const boot = (props = {}) => application_factory_1.ApplicationFactory.create({ react: { path: '/app' }, ...props }, test_module_1.reactTestModule, specModule);
80
+ const routes = () => core_1.ContainerUtil.get(router_protocol_1.RouteMetadataProvider).provide();
81
+ (0, bun_test_1.describe)('@celljs/react routes', () => {
82
+ (0, bun_test_1.it)('resolves paths against react.path and puts the default layout around each view', async () => {
83
+ await boot();
84
+ const all = routes();
85
+ (0, bun_test_1.expect)(all.map(r => [r.index, r.path])).toEqual([[true, undefined], [undefined, '/app/about']]);
86
+ (0, bun_test_1.expect)(all.every(r => r.layout === layout_1.EmptyLayout)).toBe(true);
87
+ (0, bun_test_1.expect)(all[1].component).toBe(AboutView);
88
+ });
89
+ (0, bun_test_1.it)('registers each route under its own id: the path, or <index>', async () => {
90
+ await boot();
91
+ (0, bun_test_1.expect)(core_1.ContainerUtil.isBound('@Route:<index>')).toBe(true);
92
+ (0, bun_test_1.expect)(core_1.ContainerUtil.isBound('@Route:/about')).toBe(true);
93
+ });
94
+ (0, bun_test_1.it)('react.router.routes overrides the metadata of a route by its path', async () => {
95
+ await boot({ react: { path: '/', router: { routes: { '/about': { caseSensitive: true, priority: 2000 } } } } });
96
+ const about = routes().find(r => r.path === '/about');
97
+ (0, bun_test_1.expect)(about.caseSensitive).toBe(true);
98
+ (0, bun_test_1.expect)(routes()[0]).toBe(about);
99
+ });
100
+ });
101
+ (0, bun_test_1.describe)('@celljs/react widgets', () => {
102
+ (0, bun_test_1.it)('@Widget components render with the props of the configuration', async () => {
103
+ await boot({ widget: { widgets: { logo: { props: { text: 'Cell' } } } } });
104
+ const nodes = await core_1.ContainerUtil.get(widget_1.WidgetManager).render('header');
105
+ (0, bun_test_1.expect)((0, server_1.renderToStaticMarkup)(React.createElement(React.Fragment, null, nodes))).toBe('<b>Cell</b>');
106
+ });
107
+ });
108
+ //# sourceMappingURL=router.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.spec.js","sourceRoot":"","sources":["../../../src/browser/router/router.spec.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAgD;AAChD,qDAAsD;AACtD,uCAAuD;AACvD,iGAA6F;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,KAAM,YAAW,gBAAgB;IAG1C,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,aAAa,CAAC;IAE5C,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAE9B;CACJ"}
1
+ {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../src/browser/shell/shell.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,qBACa,KAAM,YAAW,gBAAgB;IAG1C,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,aAAa,CAAC;IAE5C,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAG9B;CACJ"}
@@ -48,9 +48,11 @@ 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 hooks_1 = require("../hooks");
51
52
  let Shell = class Shell {
52
53
  attach(host) {
53
- (0, client_1.createRoot)(host).render(React.createElement(this.app));
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);
54
56
  }
55
57
  };
56
58
  exports.Shell = Shell;
@@ -1 +1 @@
1
- {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../../src/browser/shell/shell.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA4D;AAC5D,uCAAoD;AACpD,6CAA8C;AAC9C,MAAY,KAAK,kCAAc;AAC/B,gCAA6B;AAGtB,IAAM,KAAK,GAAX,MAAM,KAAK;IAKd,MAAM,CAAC,IAAiB;QACpB,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;;AALsB;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,CAQjB"}
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,3 +1,4 @@
1
+ /** The widgets of an area, in order of priority. */
1
2
  export declare function Slot({ area }: {
2
3
  area: string;
3
4
  }): JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../../src/browser/slot/slot.tsx"],"names":[],"mappings":"AAKA,wBAAgB,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,eAY9C"}
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"}
@@ -34,19 +34,20 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Slot = Slot;
37
- const core_1 = require("@celljs/core");
38
37
  const React = __importStar(require("react"));
39
38
  const widget_1 = require("@celljs/widget");
40
- const { useState, useEffect } = React;
39
+ const hooks_1 = require("../hooks");
40
+ /** The widgets of an area, in order of priority. */
41
41
  function Slot({ area }) {
42
- const [nodes, setNodes] = useState([]);
43
- useEffect(() => {
44
- const load = async () => {
45
- const widgetManager = core_1.ContainerUtil.get(widget_1.WidgetManager);
46
- setNodes(await widgetManager.render(area));
42
+ const widgetManager = (0, hooks_1.useInject)(widget_1.WidgetManager);
43
+ const [nodes, setNodes] = React.useState([]);
44
+ React.useEffect(() => {
45
+ let current = true;
46
+ widgetManager.render(area).then(rendered => current && setNodes(rendered));
47
+ return () => {
48
+ current = false;
47
49
  };
48
- load();
49
- }, [area]);
50
- return (React.createElement(React.Fragment, null, nodes.map(n => n)));
50
+ }, [widgetManager, area]);
51
+ return React.createElement(React.Fragment, null, nodes);
51
52
  }
52
53
  //# sourceMappingURL=slot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"slot.js","sourceRoot":"","sources":["../../../src/browser/slot/slot.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA6C;AAC7C,MAAY,KAAK,kCAAc;AAC/B,2CAA+C;AAC/C,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;AAEtC,cAAqB,EAAE,IAAI,EAAoB;IAC3C,MAAM,CAAC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G,KAAK,CAAI,CAAC;AACxB,CAAC"}
@@ -0,0 +1,16 @@
1
+ import '../annotation';
2
+ import '../app';
3
+ import '../context';
4
+ import '../hooks';
5
+ import '../layout';
6
+ import '../locale';
7
+ import '../resolver';
8
+ import '../router';
9
+ import '../slot';
10
+ import '../widget';
11
+ /**
12
+ * The components of @celljs/react and @celljs/widget without the shell (which needs a DOM), for tests
13
+ * that run in Node.js or Bun. Import it before anything that declares components.
14
+ */
15
+ export declare const reactTestModule: import("@celljs/core").ContainerModule;
16
+ //# sourceMappingURL=test-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-module.d.ts","sourceRoot":"","sources":["../../../src/browser/test/test-module.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;AACvB,OAAO,QAAQ,CAAC;AAChB,OAAO,YAAY,CAAC;AACpB,OAAO,UAAU,CAAC;AAClB,OAAO,WAAW,CAAC;AACnB,OAAO,WAAW,CAAC;AACnB,OAAO,aAAa,CAAC;AACrB,OAAO,WAAW,CAAC;AACnB,OAAO,SAAS,CAAC;AACjB,OAAO,WAAW,CAAC;AAEnB;;;GAGG;AACH,eAAO,MAAM,eAAe,wCAAa,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reactTestModule = void 0;
4
+ const core_1 = require("@celljs/core");
5
+ require("../annotation");
6
+ require("../app");
7
+ require("../context");
8
+ require("../hooks");
9
+ require("../layout");
10
+ require("../locale");
11
+ require("../resolver");
12
+ require("../router");
13
+ require("../slot");
14
+ require("../widget");
15
+ /**
16
+ * The components of @celljs/react and @celljs/widget without the shell (which needs a DOM), for tests
17
+ * that run in Node.js or Bun. Import it before anything that declares components.
18
+ */
19
+ exports.reactTestModule = (0, core_1.autoBind)();
20
+ //# sourceMappingURL=test-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-module.js","sourceRoot":"","sources":["../../../src/browser/test/test-module.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AACxC,yBAAuB;AACvB,kBAAgB;AAChB,sBAAoB;AACpB,oBAAkB;AAClB,qBAAmB;AACnB,qBAAmB;AACnB,uBAAqB;AACrB,qBAAmB;AACnB,mBAAiB;AACjB,qBAAmB;AAEnB;;;GAGG;AACU,QAAA,eAAe,GAAG,IAAA,eAAQ,GAAE,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { AbstractWidgetFactory, WidgetModel } from '@celljs/widget';
3
3
  export declare class DecoratorWidgetFactory extends AbstractWidgetFactory<React.ReactNode> {
4
+ readonly type: string;
4
5
  protected doRender(widgetModel: WidgetModel): Promise<React.ReactNode>;
5
6
  }
6
7
  //# sourceMappingURL=widget-factory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"widget-factory.d.ts","sourceRoot":"","sources":["../../../src/browser/widget/widget-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEnF,qBACa,sBAAuB,SAAQ,qBAAqB,CAAC,KAAK,CAAC,SAAS,CAAC;IAE9E,UAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAG3E;CAEJ"}
1
+ {"version":3,"file":"widget-factory.d.ts","sourceRoot":"","sources":["../../../src/browser/widget/widget-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAiB,WAAW,EAAc,MAAM,gBAAgB,CAAC;AAE/F,qBACa,sBAAuB,SAAQ,qBAAqB,CAAC,KAAK,CAAC,SAAS,CAAC;IAE9E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAwB;IAE7C,UAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAG3E;CAEJ"}
@@ -44,6 +44,10 @@ const core_1 = require("@celljs/core");
44
44
  const React = __importStar(require("react"));
45
45
  const widget_1 = require("@celljs/widget");
46
46
  let DecoratorWidgetFactory = class DecoratorWidgetFactory extends widget_1.AbstractWidgetFactory {
47
+ constructor() {
48
+ super(...arguments);
49
+ this.type = widget_1.WidgetType.Decorator;
50
+ }
47
51
  async doRender(widgetModel) {
48
52
  const component = widgetModel.matedata.component;
49
53
  return React.createElement(component, { key: widgetModel.id, ...widgetModel.props });
@@ -1 +1 @@
1
- {"version":3,"file":"widget-factory.js","sourceRoot":"","sources":["../../../src/browser/widget/widget-factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyC;AACzC,MAAY,KAAK,kCAAc;AAC/B,2CAAmF;AAG5E,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,8BAAsC;IAEpE,KAAK,CAAC,QAAQ,CAAC,WAAwB;QAC7C,MAAM,SAAS,GAAG,WAAW,CAAC,QAAS,CAAC,SAAS,CAAC;QAClD,OAAO,KAAK,CAAC,aAAa,CAAC,SAAS,EAAG,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,EAAG,GAAG,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;IAC3F,CAAC;CAEJ,CAAA;;iCAPY,sBAAsB;IADlC,IAAA,gBAAS,EAAC,sBAAa,CAAC;GACZ,sBAAsB,CAOlC"}
1
+ {"version":3,"file":"widget-factory.js","sourceRoot":"","sources":["../../../src/browser/widget/widget-factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyC;AACzC,MAAY,KAAK,kCAAc;AAC/B,2CAA+F;AAGxF,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,8BAAsC;IAA3E;;QAEM,SAAI,GAAW,mBAAU,CAAC,SAAS,CAAC;IAOjD,CAAC;IALa,KAAK,CAAC,QAAQ,CAAC,WAAwB;QAC7C,MAAM,SAAS,GAAG,WAAW,CAAC,QAAS,CAAC,SAAS,CAAC;QAClD,OAAO,KAAK,CAAC,aAAa,CAAC,SAAS,EAAG,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,EAAG,GAAG,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;IAC3F,CAAC;CAEJ,CAAA;;iCATY,sBAAsB;IADlC,IAAA,gBAAS,EAAC,sBAAa,CAAC;GACZ,sBAAsB,CASlC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/react",
3
- "version": "4.2.0",
3
+ "version": "4.4.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "cell-component"
@@ -23,7 +23,8 @@
23
23
  "lib",
24
24
  "esm",
25
25
  "src",
26
- "cell.yml"
26
+ "cell.yml",
27
+ "cell.schema.json"
27
28
  ],
28
29
  "scripts": {
29
30
  "build": "tsc -b && bun ../../scripts/build-esm.ts",
@@ -32,13 +33,13 @@
32
33
  "watch": "tsc -b -w --preserveWatchOutput"
33
34
  },
34
35
  "dependencies": {
35
- "@celljs/core": "4.2.0",
36
- "@celljs/widget": "4.2.0",
36
+ "@celljs/core": "4.4.0",
37
+ "@celljs/widget": "4.4.0",
37
38
  "@types/react": "^18.0.17",
38
39
  "react": "^18.2.0",
39
40
  "react-dom": "^18.2.0",
40
41
  "react-intl": "^6.0.5",
41
- "react-router-dom": "^6.3.0"
42
+ "react-router": "^7.18.5"
42
43
  },
43
44
  "publishConfig": {
44
45
  "access": "public"
@@ -65,6 +66,10 @@
65
66
  "import": "./esm/browser/context/index.js",
66
67
  "default": "./lib/browser/context/index.js"
67
68
  },
69
+ "./lib/browser/hooks": {
70
+ "import": "./esm/browser/hooks/index.js",
71
+ "default": "./lib/browser/hooks/index.js"
72
+ },
68
73
  "./lib/browser/icon": {
69
74
  "import": "./esm/browser/icon/index.js",
70
75
  "default": "./lib/browser/icon/index.js"
@@ -115,7 +120,6 @@
115
120
  }
116
121
  },
117
122
  "devDependencies": {
118
- "@types/react-dom": "^18.0.6",
119
- "@types/react-router-dom": "^5.3.3"
123
+ "@types/react-dom": "^18.0.6"
120
124
  }
121
125
  }
@@ -8,12 +8,17 @@ export function Route(pathOrRouteMetadata?: string | RouteMetadata, rebind = fal
8
8
  if (typeof pathOrRouteMetadata === 'string') {
9
9
  routeMetadata = { path: pathOrRouteMetadata, priority: 1000 };
10
10
  } else {
11
- routeMetadata = <RouteMetadata>{ priority: 1000, isDefaultLayout: true, ...pathOrRouteMetadata };
11
+ routeMetadata = { priority: 1000, ...pathOrRouteMetadata };
12
12
  }
13
13
  if (!routeMetadata.component) {
14
14
  routeMetadata.component = target;
15
15
  }
16
16
  Constant(ROUTE_METADATA, routeMetadata, false)(target);
17
- ReactComponent('@Route:' + routeMetadata.path, undefined, rebind)(target);
17
+ ReactComponent(routeId(routeMetadata), undefined, rebind)(target);
18
18
  };
19
19
  }
20
+
21
+ /** The component id of a route, which `rebind` replaces: its path, or `<index>` for the index route. */
22
+ function routeId(metadata: RouteMetadata): string {
23
+ return '@Route:' + (metadata.path ?? (metadata.index ? '<index>' : ''));
24
+ }
@@ -1,25 +1,17 @@
1
1
  import * as React from 'react';
2
- import { ROUTER } from '../router';
3
- import { Autowired } from '@celljs/core/lib/common/annotation/detached';
4
2
  import { App } from '../annotation';
5
3
  import { ContextProvider } from '../context';
4
+ import { useInject } from '../hooks';
5
+ import { ROUTER } from '../router';
6
6
 
7
- @App(AppImpl, false)
8
- export class AppImpl extends React.Component {
9
-
10
- @Autowired(ContextProvider)
11
- protected readonly contextProvider: ContextProvider;
12
-
13
- @Autowired(ROUTER)
14
- protected readonly router: React.ComponentType;
15
-
16
- override render(): React.ReactNode {
17
- return this.createContextAndRouter();
18
- }
19
-
20
- protected createContextAndRouter() {
21
- let child = React.createElement(this.router);
22
- this.contextProvider.provide().forEach((context, index) => child = React.createElement(context, { key: index }, child));
23
- return child;
24
- }
7
+ /** The root component: the router inside the `@Context` providers. */
8
+ export function AppImpl() {
9
+ const contextProvider = useInject<ContextProvider>(ContextProvider);
10
+ const router = useInject<React.ComponentType>(ROUTER);
11
+ let child: React.ReactNode = React.createElement(router);
12
+ contextProvider.provide().forEach((context, index) => child = React.createElement(context, { key: index }, child));
13
+ return child;
25
14
  }
15
+
16
+ @App(AppImpl, false)
17
+ export default class {}
@@ -0,0 +1,87 @@
1
+ import { reactTestModule } from '../test/test-module';
2
+ import { describe, expect, it } from 'bun:test';
3
+ import { autoBind, Component, ContainerProvider, Value } from '@celljs/core';
4
+ import { ApplicationFactory } from '@celljs/core/lib/common/application/application-factory';
5
+ import * as React from 'react';
6
+ import { renderToStaticMarkup } from 'react-dom/server';
7
+ import { Context, View } from '../annotation';
8
+ import { AppImpl } from '../app';
9
+ import { ContainerContext, useInject, useValue } from './container-hooks';
10
+
11
+ const storage = new Map<string, string>();
12
+ (globalThis as any).localStorage ??= {
13
+ getItem: (key: string) => storage.get(key) ?? null,
14
+ setItem: (key: string, value: string) => storage.set(key, value),
15
+ removeItem: (key: string) => storage.delete(key),
16
+ };
17
+
18
+ const Greeter = Symbol('Greeter');
19
+ interface Greeter {
20
+ greet(): string;
21
+ }
22
+
23
+ @Component(Greeter)
24
+ export class GreeterImpl implements Greeter {
25
+ @Value('app.greeting')
26
+ protected readonly greeting: string;
27
+
28
+ greet(): string {
29
+ return this.greeting;
30
+ }
31
+ }
32
+
33
+ function Hello() {
34
+ const greeter = useInject<Greeter>(Greeter);
35
+ const name = useValue<string>('app.name', 'nobody');
36
+ return <p>{greeter.greet()}, {name}</p>;
37
+ }
38
+
39
+ const Home = () => <h1>Home</h1>;
40
+
41
+ @View({ index: true, component: Home })
42
+ export class HomeView {}
43
+
44
+ function Framed({ children }: React.PropsWithChildren) {
45
+ return <main>{children}</main>;
46
+ }
47
+ Framed.priority = 2000;
48
+
49
+ @Context(Framed)
50
+ export class FramedContext {}
51
+
52
+ // autoBind() takes what was registered since the previous call: the classes of this file.
53
+ 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();
57
+ }
58
+
59
+ describe('@celljs/react hooks', () => {
60
+
61
+ it('useInject and useValue read the container of ContainerContext, one per tree', async () => {
62
+ const en = await boot({ greeting: 'Hello', name: 'Ada' });
63
+ const fr = await boot({ greeting: 'Bonjour' });
64
+ const render = (container: typeof en) =>
65
+ renderToStaticMarkup(<ContainerContext.Provider value={container}><Hello /></ContainerContext.Provider>);
66
+ expect(render(en)).toBe('<p>Hello, Ada</p>');
67
+ expect(render(fr)).toBe('<p>Bonjour, nobody</p>');
68
+ });
69
+
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>');
73
+ });
74
+
75
+ it('the App renders the routes inside the @Context providers', async () => {
76
+ const container = await boot({});
77
+ // React warns that the router's useLayoutEffect does nothing on the server.
78
+ const error = console.error;
79
+ console.error = () => undefined;
80
+ try {
81
+ const html = renderToStaticMarkup(<ContainerContext.Provider value={container}><AppImpl /></ContainerContext.Provider>);
82
+ expect(html).toBe('<main><h1>Home</h1></main>');
83
+ } finally {
84
+ console.error = error;
85
+ }
86
+ });
87
+ });
@@ -0,0 +1,33 @@
1
+ import { ComponentId, ConfigProvider, Container, ContainerProvider } from '@celljs/core';
2
+ import * as React from 'react';
3
+
4
+ /**
5
+ * The DI container of the components below it. The shell provides the application's container;
6
+ * a test renders a component inside `<ContainerContext.Provider value={container}>`.
7
+ */
8
+ export const ContainerContext = React.createContext<Container | undefined>(undefined);
9
+
10
+ /** The container of {@link ContainerContext}, else the application's (a component rendered in its own root). */
11
+ export function useContainer(): Container {
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.');
20
+ }
21
+ }
22
+
23
+ /** A component of the container, resolved once per component instance (and again if the container changes). */
24
+ export function useInject<T>(id: ComponentId<T>): T {
25
+ const container = useContainer();
26
+ return React.useMemo(() => container.get<T>(id), [container, id]);
27
+ }
28
+
29
+ /** A configuration value, like `@Value(key)`; the frontend only has the keys marked public. */
30
+ export function useValue<T>(key: string, defaultValue?: T): T {
31
+ const container = useContainer();
32
+ return React.useMemo(() => container.get<ConfigProvider>(ConfigProvider).get<T>(key, defaultValue), [container, key]);
33
+ }
@@ -0,0 +1 @@
1
+ export * from './container-hooks';
@@ -1,4 +1,5 @@
1
1
  export * from './annotation';
2
+ export * from './hooks';
2
3
  export * from './app';
3
4
  export * from './layout';
4
5
  export * from './context';
@@ -8,4 +9,4 @@ export * from './resolver';
8
9
  export * from './widget';
9
10
  export * from './slot';
10
11
  export * from './icon';
11
- export * from './locale';
12
+ export * from './locale';