@celljs/react 4.5.1 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -3
- package/esm/browser/app/app.d.ts +1 -1
- package/esm/browser/error/error-boundary.d.ts +32 -0
- package/esm/browser/error/error-boundary.js +38 -0
- package/esm/browser/error/error-boundary.js.map +1 -0
- package/esm/browser/error/index.d.ts +1 -0
- package/esm/browser/error/index.js +2 -0
- package/esm/browser/error/index.js.map +1 -0
- package/esm/browser/hooks/container-hooks.d.ts +1 -1
- package/esm/browser/hooks/container-hooks.js +5 -10
- package/esm/browser/hooks/container-hooks.js.map +1 -1
- package/esm/browser/hooks/index.d.ts +1 -0
- package/esm/browser/hooks/index.js +1 -0
- package/esm/browser/hooks/index.js.map +1 -1
- package/esm/browser/hooks/rpc-hooks.d.ts +6 -0
- package/esm/browser/hooks/rpc-hooks.js +19 -0
- package/esm/browser/hooks/rpc-hooks.js.map +1 -0
- package/esm/browser/icon/icon.d.ts +2 -1
- package/esm/browser/icon/icon.js +7 -6
- package/esm/browser/icon/icon.js.map +1 -1
- package/esm/browser/index.d.ts +1 -0
- package/esm/browser/index.js +1 -0
- package/esm/browser/index.js.map +1 -1
- package/esm/browser/intl/index.d.ts +1 -0
- package/esm/browser/intl/index.js +2 -0
- package/esm/browser/intl/index.js.map +1 -0
- package/esm/browser/intl/intl-context.d.ts +13 -0
- package/esm/browser/{locale/locale-context.js → intl/intl-context.js} +12 -12
- package/esm/browser/intl/intl-context.js.map +1 -0
- package/esm/browser/layout/layout.d.ts +1 -1
- package/esm/browser/locale/index.d.ts +1 -2
- package/esm/browser/locale/index.js +1 -2
- package/esm/browser/locale/index.js.map +1 -1
- package/esm/browser/locale/locale-hooks.d.ts +3 -0
- package/esm/browser/locale/locale-hooks.js +15 -0
- package/esm/browser/locale/locale-hooks.js.map +1 -0
- package/esm/browser/router/file-route-util.js +10 -0
- package/esm/browser/router/file-route-util.js.map +1 -1
- package/esm/browser/router/router-protocol.d.ts +10 -0
- package/esm/browser/router/router-protocol.js.map +1 -1
- package/esm/browser/router/router.d.ts +6 -0
- package/esm/browser/router/router.js +10 -5
- package/esm/browser/router/router.js.map +1 -1
- package/esm/browser/shell/shell.d.ts +6 -3
- package/esm/browser/shell/shell.js +12 -6
- package/esm/browser/shell/shell.js.map +1 -1
- package/esm/browser/slot/slot.d.ts +2 -1
- package/lib/browser/app/app.d.ts +1 -1
- package/lib/browser/app/app.d.ts.map +1 -1
- package/lib/browser/error/error-boundary.d.ts +33 -0
- package/lib/browser/error/error-boundary.d.ts.map +1 -0
- package/lib/browser/error/error-boundary.js +76 -0
- package/lib/browser/error/error-boundary.js.map +1 -0
- package/lib/browser/error/error-boundary.spec.d.ts +2 -0
- package/lib/browser/error/error-boundary.spec.d.ts.map +1 -0
- package/lib/browser/error/error-boundary.spec.js +82 -0
- package/lib/browser/error/error-boundary.spec.js.map +1 -0
- package/lib/browser/error/index.d.ts +2 -0
- package/lib/browser/error/index.d.ts.map +1 -0
- package/lib/browser/error/index.js +18 -0
- package/lib/browser/error/index.js.map +1 -0
- package/lib/browser/hooks/container-hooks.d.ts +1 -1
- package/lib/browser/hooks/container-hooks.d.ts.map +1 -1
- package/lib/browser/hooks/container-hooks.js +4 -9
- package/lib/browser/hooks/container-hooks.js.map +1 -1
- package/lib/browser/hooks/container-hooks.spec.d.ts.map +1 -1
- package/lib/browser/hooks/container-hooks.spec.js +65 -7
- package/lib/browser/hooks/container-hooks.spec.js.map +1 -1
- package/lib/browser/hooks/index.d.ts +1 -0
- package/lib/browser/hooks/index.d.ts.map +1 -1
- package/lib/browser/hooks/index.js +1 -0
- package/lib/browser/hooks/index.js.map +1 -1
- package/lib/browser/hooks/rpc-hooks.d.ts +7 -0
- package/lib/browser/hooks/rpc-hooks.d.ts.map +1 -0
- package/lib/browser/hooks/rpc-hooks.js +55 -0
- package/lib/browser/hooks/rpc-hooks.js.map +1 -0
- package/lib/browser/icon/icon.d.ts +2 -1
- package/lib/browser/icon/icon.d.ts.map +1 -1
- package/lib/browser/icon/icon.js +7 -6
- package/lib/browser/icon/icon.js.map +1 -1
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/intl/index.d.ts +2 -0
- package/lib/browser/intl/index.d.ts.map +1 -0
- package/lib/browser/intl/index.js +18 -0
- package/lib/browser/intl/index.js.map +1 -0
- package/lib/browser/intl/intl-context.d.ts +14 -0
- package/lib/browser/intl/intl-context.d.ts.map +1 -0
- package/lib/browser/{locale/locale-context.js → intl/intl-context.js} +14 -13
- package/lib/browser/intl/intl-context.js.map +1 -0
- package/lib/browser/layout/layout.d.ts +1 -1
- package/lib/browser/layout/layout.d.ts.map +1 -1
- package/lib/browser/locale/index.d.ts +1 -2
- package/lib/browser/locale/index.d.ts.map +1 -1
- package/lib/browser/locale/index.js +1 -2
- package/lib/browser/locale/index.js.map +1 -1
- package/lib/browser/locale/locale-hooks.d.ts +4 -0
- package/lib/browser/locale/locale-hooks.d.ts.map +1 -0
- package/lib/browser/locale/locale-hooks.js +51 -0
- package/lib/browser/locale/locale-hooks.js.map +1 -0
- package/lib/browser/router/file-route-util.d.ts.map +1 -1
- package/lib/browser/router/file-route-util.js +10 -0
- package/lib/browser/router/file-route-util.js.map +1 -1
- package/lib/browser/router/file-route-util.spec.js +18 -6
- package/lib/browser/router/file-route-util.spec.js.map +1 -1
- package/lib/browser/router/router-protocol.d.ts +10 -0
- package/lib/browser/router/router-protocol.d.ts.map +1 -1
- package/lib/browser/router/router-protocol.js.map +1 -1
- package/lib/browser/router/router.d.ts +6 -0
- package/lib/browser/router/router.d.ts.map +1 -1
- package/lib/browser/router/router.js +10 -4
- package/lib/browser/router/router.js.map +1 -1
- package/lib/browser/router/router.spec.d.ts +1 -1
- package/lib/browser/router/router.spec.d.ts.map +1 -1
- package/lib/browser/router/router.spec.js +8 -5
- package/lib/browser/router/router.spec.js.map +1 -1
- package/lib/browser/shell/shell.d.ts +6 -3
- package/lib/browser/shell/shell.d.ts.map +1 -1
- package/lib/browser/shell/shell.js +11 -5
- package/lib/browser/shell/shell.js.map +1 -1
- package/lib/browser/slot/slot.d.ts +2 -1
- package/lib/browser/slot/slot.d.ts.map +1 -1
- package/lib/package.spec.js +25 -2
- package/lib/package.spec.js.map +1 -1
- package/package.json +24 -8
- package/src/browser/error/error-boundary.spec.tsx +49 -0
- package/src/browser/error/error-boundary.tsx +62 -0
- package/src/browser/error/index.ts +1 -0
- package/src/browser/hooks/container-hooks.spec.tsx +65 -9
- package/src/browser/hooks/container-hooks.ts +5 -9
- package/src/browser/hooks/index.ts +1 -0
- package/src/browser/hooks/rpc-hooks.ts +21 -0
- package/src/browser/icon/icon.tsx +7 -6
- package/src/browser/index.ts +2 -1
- package/src/browser/intl/index.ts +1 -0
- package/src/browser/intl/intl-context.tsx +31 -0
- package/src/browser/locale/index.ts +1 -2
- package/src/browser/locale/locale-hooks.ts +15 -0
- package/src/browser/router/file-route-util.spec.tsx +15 -4
- package/src/browser/router/file-route-util.ts +12 -0
- package/src/browser/router/router-protocol.ts +6 -0
- package/src/browser/router/router.spec.tsx +10 -8
- package/src/browser/router/router.tsx +13 -6
- package/src/browser/shell/shell.tsx +16 -6
- package/src/package.spec.ts +22 -3
- package/esm/browser/locale/locale-context.d.ts +0 -8
- package/esm/browser/locale/locale-context.js.map +0 -1
- package/esm/browser/locale/locale-protocol.d.ts +0 -1
- package/esm/browser/locale/locale-protocol.js +0 -2
- package/esm/browser/locale/locale-protocol.js.map +0 -1
- package/lib/browser/locale/locale-context.d.ts +0 -9
- package/lib/browser/locale/locale-context.d.ts.map +0 -1
- package/lib/browser/locale/locale-context.js.map +0 -1
- package/lib/browser/locale/locale-protocol.d.ts +0 -2
- package/lib/browser/locale/locale-protocol.d.ts.map +0 -1
- package/lib/browser/locale/locale-protocol.js +0 -5
- package/lib/browser/locale/locale-protocol.js.map +0 -1
- package/src/browser/locale/locale-context.tsx +0 -31
- package/src/browser/locale/locale-protocol.ts +0 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ The `fullstack` template of `cell init` is set up with it. `cell dev` serves the
|
|
|
11
11
|
|
|
12
12
|
## Pages
|
|
13
13
|
|
|
14
|
-
Pages are the files of `src/browser/pages/`, each with the page component as default export: `index.tsx` is `/`, `about.tsx` is `/about`, `users/[id].tsx` is `/users/:id`, `[...rest].tsx` matches the rest of the path,
|
|
14
|
+
Pages are the files of `src/browser/pages/`, each with the page component as default export: `index.tsx` is `/`, `about.tsx` is `/about`, `users/[id].tsx` is `/users/:id`, `[...rest].tsx` matches the rest of the path, `_layout.tsx` wraps the pages of its directory and below, and `_error.tsx` shows when one of them fails. Names starting with `_` and tests are not pages. The toolchain (`cell dev`, `cell build`) generates the routes (`.cell/generated/frontend/routes.js`, listed by `cell info --json`); each page is a chunk loaded when it is visited. Guide: [Frontend and RPC](https://cell.cellbang.com/guide/frontend).
|
|
15
15
|
|
|
16
16
|
```tsx
|
|
17
17
|
// src/browser/pages/users/[id].tsx
|
|
@@ -36,6 +36,21 @@ Packages, which have no pages directory, add pages and replace parts of the fron
|
|
|
36
36
|
|
|
37
37
|
Paths are resolved against `react.path` (default `server.path`, `/`).
|
|
38
38
|
|
|
39
|
+
## Errors
|
|
40
|
+
|
|
41
|
+
A page that throws while rendering, or whose code does not load, does not blank the application: an `ErrorBoundary` inside its layout shows the fallback instead, and the page is tried again when the user goes to another path. The fallback is the default export of the nearest `_error.tsx` (in the directory of the page or above), which gets `{ error, reset }` (`ErrorFallbackProps`); without one, `DefaultErrorFallback` shows the message and a button to try again. The shell puts another boundary around the whole application, for errors of layouts and of the fallbacks themselves. React logs the errors to the console.
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// src/browser/pages/_error.tsx
|
|
45
|
+
import type { ErrorFallbackProps } from '@celljs/react';
|
|
46
|
+
|
|
47
|
+
export default function PageError({ error, reset }: ErrorFallbackProps) {
|
|
48
|
+
return <p>Could not show this page ({String(error)}). <button onClick={reset}>Retry</button></p>;
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`ErrorBoundary` (`fallback`, `resetKey`) is exported for parts of a page.
|
|
53
|
+
|
|
39
54
|
## Services in components
|
|
40
55
|
|
|
41
56
|
| Hook | |
|
|
@@ -43,8 +58,10 @@ Paths are resolved against `react.path` (default `server.path`, `/`).
|
|
|
43
58
|
| `useInject<T>(id)` | A component of the container, resolved once per component instance |
|
|
44
59
|
| `useValue<T>(key, default?)` | A configuration value, like `@Value(key)` (the frontend only has public keys) |
|
|
45
60
|
| `useContainer()` | The container itself |
|
|
61
|
+
| `useRpc<T>(id)` | The proxy of a backend service (needs [`@celljs/rpc`](../../packages/rpc)), like `@Autorpc(id)` |
|
|
62
|
+
| `useLocale()` | `[locale, setLocale]`: the locale of `widget.locales` the user selected, and how to change it |
|
|
46
63
|
|
|
47
|
-
They use the container of `ContainerContext`, which the shell provides;
|
|
64
|
+
They use the container of `ContainerContext`, which the shell provides; there is no global container, so a component rendered outside the application fails with a message saying so. In a test, render the component inside `<ContainerContext.Provider value={container}>`; `reactTestModule` (`@celljs/react/lib/browser/test/test-module`) has the components of this package without the shell, which needs a DOM.
|
|
48
65
|
|
|
49
66
|
```tsx
|
|
50
67
|
function Header() {
|
|
@@ -70,4 +87,17 @@ Frontend configuration is evaluated at build time and is visible to anyone who l
|
|
|
70
87
|
|
|
71
88
|
## Calling the backend
|
|
72
89
|
|
|
73
|
-
|
|
90
|
+
`useRpc<T>(Id)` returns a typed proxy of a backend service of [`@celljs/rpc`](../../packages/rpc); its methods return promises, so call them in an effect or an event handler. For other HTTP APIs, use `fetch` or `RestOperations` from [`@celljs/http`](../../packages/http).
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
function Greeting() {
|
|
94
|
+
const greetingServer = useRpc<GreetingServer>(GreetingServer);
|
|
95
|
+
const [text, setText] = React.useState('');
|
|
96
|
+
React.useEffect(() => { greetingServer.greet('web').then(setText); }, [greetingServer]);
|
|
97
|
+
return <p>{text}</p>;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Translations with react-intl
|
|
102
|
+
|
|
103
|
+
react-intl is optional. To use it, install it and import `@celljs/react/lib/browser/intl` once in `src/browser/module.ts`: its `IntlContext` puts an `IntlProvider` with the messages of the selected locale around the application, so `useIntl()` and `<FormattedMessage>` work in every component.
|
package/esm/browser/app/app.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
/** The root component: the router inside the `@Context` providers. */
|
|
3
|
-
export declare function AppImpl(): React.ReactElement<
|
|
3
|
+
export declare function AppImpl(): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
4
4
|
export default class {
|
|
5
5
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface ErrorFallbackProps {
|
|
3
|
+
/** What the component threw, or why its code could not be loaded. */
|
|
4
|
+
error: unknown;
|
|
5
|
+
/** Renders the children again. */
|
|
6
|
+
reset(): void;
|
|
7
|
+
}
|
|
8
|
+
export interface ErrorBoundaryProps extends React.PropsWithChildren {
|
|
9
|
+
/** What shows instead of the children when they fail; {@link DefaultErrorFallback} by default. */
|
|
10
|
+
fallback?: React.ComponentType<ErrorFallbackProps>;
|
|
11
|
+
/** When it changes (the path of the page), a failed boundary renders its children again. */
|
|
12
|
+
resetKey?: unknown;
|
|
13
|
+
}
|
|
14
|
+
interface ErrorBoundaryState {
|
|
15
|
+
failed: boolean;
|
|
16
|
+
error?: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Catches the errors of the components below it, rendering or loading (a page chunk that does not
|
|
20
|
+
* load), and shows the fallback instead: one failing page does not blank the application. React logs
|
|
21
|
+
* the error to the console.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
24
|
+
state: ErrorBoundaryState;
|
|
25
|
+
static getDerivedStateFromError(error: unknown): ErrorBoundaryState;
|
|
26
|
+
componentDidUpdate(previous: ErrorBoundaryProps): void;
|
|
27
|
+
readonly reset: () => void;
|
|
28
|
+
render(): React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
/** The message of the error and a button to try again. */
|
|
31
|
+
export declare function DefaultErrorFallback({ error, reset }: ErrorFallbackProps): React.JSX.Element;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Catches the errors of the components below it, rendering or loading (a page chunk that does not
|
|
4
|
+
* load), and shows the fallback instead: one failing page does not blank the application. React logs
|
|
5
|
+
* the error to the console.
|
|
6
|
+
*/
|
|
7
|
+
export class ErrorBoundary extends React.Component {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.state = { failed: false };
|
|
11
|
+
this.reset = () => this.setState({ failed: false, error: undefined });
|
|
12
|
+
}
|
|
13
|
+
static getDerivedStateFromError(error) {
|
|
14
|
+
return { failed: true, error };
|
|
15
|
+
}
|
|
16
|
+
componentDidUpdate(previous) {
|
|
17
|
+
if (this.state.failed && previous.resetKey !== this.props.resetKey) {
|
|
18
|
+
this.reset();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
render() {
|
|
22
|
+
var _a;
|
|
23
|
+
if (this.state.failed) {
|
|
24
|
+
const Fallback = (_a = this.props.fallback) !== null && _a !== void 0 ? _a : DefaultErrorFallback;
|
|
25
|
+
return React.createElement(Fallback, { error: this.state.error, reset: this.reset });
|
|
26
|
+
}
|
|
27
|
+
return this.props.children;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** The message of the error and a button to try again. */
|
|
31
|
+
export function DefaultErrorFallback({ error, reset }) {
|
|
32
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
33
|
+
return (React.createElement("div", { role: "alert", className: "cell-error" },
|
|
34
|
+
React.createElement("p", null, "Something went wrong."),
|
|
35
|
+
React.createElement("pre", null, message),
|
|
36
|
+
React.createElement("button", { type: "button", onClick: reset }, "Try again")));
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=error-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-boundary.js","sourceRoot":"","sources":["../../../src/browser/error/error-boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAqB/B;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK,CAAC,SAAiD;IAA1F;;QAEa,UAAK,GAAuB,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAY9C,UAAK,GAAG,GAAS,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IASpF,CAAC;IAnBG,MAAM,CAAC,wBAAwB,CAAC,KAAc;QAC1C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;IAEQ,kBAAkB,CAAC,QAA4B;QACpD,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,QAAQ,CAAC,QAAQ,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACjE,IAAI,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;IACL,CAAC;IAIQ,MAAM;;QACX,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,QAAQ,SAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,mCAAI,oBAAoB,CAAC;YAC7D,OAAO,oBAAC,QAAQ,IAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,GAAI,CAAC;QACpE,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC/B,CAAC;CACJ;AAED,0DAA0D;AAC1D,MAAM,UAAU,oBAAoB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAsB;IACrE,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,CACH,6BAAK,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,YAAY;QACpC,uDAA4B;QAC5B,iCAAM,OAAO,CAAO;QACpB,gCAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,KAAK,gBAAoB,CACtD,CACT,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './error-boundary.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/browser/error/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -5,7 +5,7 @@ import * as React from 'react';
|
|
|
5
5
|
* a test renders a component inside `<ContainerContext.Provider value={container}>`.
|
|
6
6
|
*/
|
|
7
7
|
export declare const ContainerContext: React.Context<Container | undefined>;
|
|
8
|
-
/** The container of {@link ContainerContext}
|
|
8
|
+
/** The container of {@link ContainerContext}. */
|
|
9
9
|
export declare function useContainer(): Container;
|
|
10
10
|
/** A component of the container, resolved once per component instance (and again if the container changes). */
|
|
11
11
|
export declare function useInject<T>(id: ComponentId<T>): T;
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import { ConfigProvider
|
|
1
|
+
import { ConfigProvider } from '@celljs/core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
/**
|
|
4
4
|
* The DI container of the components below it. The shell provides the application's container;
|
|
5
5
|
* a test renders a component inside `<ContainerContext.Provider value={container}>`.
|
|
6
6
|
*/
|
|
7
7
|
export const ContainerContext = React.createContext(undefined);
|
|
8
|
-
/** The container of {@link ContainerContext}
|
|
8
|
+
/** The container of {@link ContainerContext}. */
|
|
9
9
|
export function useContainer() {
|
|
10
10
|
const container = React.useContext(ContainerContext);
|
|
11
|
-
if (container) {
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
return ContainerProvider.provide();
|
|
16
|
-
}
|
|
17
|
-
catch (_a) {
|
|
18
|
-
throw new Error('No DI container: render the component inside <ContainerContext.Provider value={container}>, or after the application has started.');
|
|
11
|
+
if (!container) {
|
|
12
|
+
throw new Error('No DI container: render the component inside the application, or inside <ContainerContext.Provider value={container}> in a test.');
|
|
19
13
|
}
|
|
14
|
+
return container;
|
|
20
15
|
}
|
|
21
16
|
/** A component of the container, resolved once per component instance (and again if the container changes). */
|
|
22
17
|
export function useInject(id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container-hooks.js","sourceRoot":"","sources":["../../../src/browser/hooks/container-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,cAAc,EAAa,
|
|
1
|
+
{"version":3,"file":"container-hooks.js","sourceRoot":"","sources":["../../../src/browser/hooks/container-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,cAAc,EAAa,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAwB,SAAS,CAAC,CAAC;AAEtF,iDAAiD;AACjD,MAAM,UAAU,YAAY;IACxB,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;IACrD,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,kIAAkI,CAAC,CAAC;IACxJ,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,+GAA+G;AAC/G,MAAM,UAAU,SAAS,CAAI,EAAkB;IAC3C,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAI,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,QAAQ,CAAI,GAAW,EAAE,YAAgB;IACrD,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAiB,cAAc,CAAC,CAAC,GAAG,CAAI,GAAG,EAAE,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;AAC1H,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/browser/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/browser/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ComponentId } from '@celljs/core';
|
|
2
|
+
/**
|
|
3
|
+
* The proxy of a backend service, as `@Autorpc(id)` injects it: `useRpc<GreetingServer>(GreetingServer)`.
|
|
4
|
+
* Its methods return promises; call them in an effect or an event handler. Needs `@celljs/rpc`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useRpc<T extends object>(id: ComponentId<T>): T;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useContainer } from './container-hooks.js';
|
|
3
|
+
// The identifiers of @celljs/rpc (global symbols), so this package does not depend on it.
|
|
4
|
+
const RPC = Symbol.for('@celljs/rpc/RPC');
|
|
5
|
+
const ID_KEY = Symbol.for('@celljs/rpc/ID_KEY');
|
|
6
|
+
/**
|
|
7
|
+
* The proxy of a backend service, as `@Autorpc(id)` injects it: `useRpc<GreetingServer>(GreetingServer)`.
|
|
8
|
+
* Its methods return promises; call them in an effect or an event handler. Needs `@celljs/rpc`.
|
|
9
|
+
*/
|
|
10
|
+
export function useRpc(id) {
|
|
11
|
+
const container = useContainer();
|
|
12
|
+
return React.useMemo(() => {
|
|
13
|
+
if (!container.isBound(RPC)) {
|
|
14
|
+
throw new Error('useRpc needs @celljs/rpc: add it to the dependencies of the project.');
|
|
15
|
+
}
|
|
16
|
+
return container.get(RPC, { tags: { [ID_KEY]: id } });
|
|
17
|
+
}, [container, id]);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=rpc-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-hooks.js","sourceRoot":"","sources":["../../../src/browser/hooks/rpc-hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,0FAA0F;AAC1F,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAEhD;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAmB,EAAkB;IACvD,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACtB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QAC5F,CAAC;QACD,OAAO,SAAS,CAAC,GAAG,CAAI,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7D,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare function Icon<T>(iconProps: T): React.JSX.Element;
|
package/esm/browser/icon/icon.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ContainerUtil } from '@celljs/core';
|
|
3
2
|
import { IconResolver } from './icon-protocol.js';
|
|
3
|
+
import { useInject } from '../hooks/index.js';
|
|
4
4
|
const { useState, useEffect } = React;
|
|
5
5
|
export function Icon(iconProps) {
|
|
6
|
+
const iconResolver = useInject(IconResolver);
|
|
6
7
|
const [iconNode, setIconNode] = useState([]);
|
|
7
8
|
useEffect(() => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
let current = true;
|
|
10
|
+
iconResolver.resolve(iconProps).then(node => current && setIconNode(node));
|
|
11
|
+
return () => {
|
|
12
|
+
current = false;
|
|
11
13
|
};
|
|
12
|
-
|
|
13
|
-
}, [JSON.stringify(iconProps)]);
|
|
14
|
+
}, [iconResolver, JSON.stringify(iconProps)]);
|
|
14
15
|
return (React.createElement(React.Fragment, null, iconNode));
|
|
15
16
|
}
|
|
16
17
|
//# sourceMappingURL=icon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon.js","sourceRoot":"","sources":["../../../src/browser/icon/icon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"icon.js","sourceRoot":"","sources":["../../../src/browser/icon/icon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;AAEtC,MAAM,UAAU,IAAI,CAAI,SAAY;IAChC,MAAM,YAAY,GAAG,SAAS,CAAkB,YAAY,CAAC,CAAC;IAC9D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAkB,EAAE,CAAC,CAAC;IAE9D,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3E,OAAO,GAAG,EAAE;YACR,OAAO,GAAG,KAAK,CAAC;QACpB,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAE9C,OAAO,CAAC,0CAAG,QAAQ,CAAI,CAAC,CAAC;AAC7B,CAAC"}
|
package/esm/browser/index.d.ts
CHANGED
package/esm/browser/index.js
CHANGED
package/esm/browser/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './intl-context.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/browser/intl/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare const INTL_REACT_CONTEXT_PRIORITY = 3000;
|
|
3
|
+
/**
|
|
4
|
+
* The `IntlProvider` of react-intl around the application, with the messages of the selected locale. Not
|
|
5
|
+
* loaded by default: a project that uses react-intl installs it and imports `@celljs/react/lib/browser/intl`
|
|
6
|
+
* once, in `src/browser/module.ts`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function IntlContext({ children }: React.PropsWithChildren): React.JSX.Element;
|
|
9
|
+
export declare namespace IntlContext {
|
|
10
|
+
export { INTL_REACT_CONTEXT_PRIORITY as priority };
|
|
11
|
+
}
|
|
12
|
+
export default class {
|
|
13
|
+
}
|
|
@@ -5,31 +5,31 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import * as React from 'react';
|
|
8
|
-
import { LOCALE_REACT_CONTEXT_PRIORITY } from './locale-protocol.js';
|
|
9
8
|
import { IntlProvider } from 'react-intl';
|
|
10
9
|
import { Logger } from '@celljs/core';
|
|
11
|
-
import { LocaleManager } from '@celljs/widget';
|
|
12
10
|
import { Context } from '../annotation/index.js';
|
|
13
11
|
import { useInject } from '../hooks/index.js';
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
import { useLocale } from '../locale/index.js';
|
|
13
|
+
export const INTL_REACT_CONTEXT_PRIORITY = 3000;
|
|
14
|
+
/**
|
|
15
|
+
* The `IntlProvider` of react-intl around the application, with the messages of the selected locale. Not
|
|
16
|
+
* loaded by default: a project that uses react-intl installs it and imports `@celljs/react/lib/browser/intl`
|
|
17
|
+
* once, in `src/browser/module.ts`.
|
|
18
|
+
*/
|
|
19
|
+
export function IntlContext({ children }) {
|
|
20
|
+
const [locale] = useLocale();
|
|
16
21
|
const logger = useInject(Logger);
|
|
17
|
-
const [locale, setLocale] = React.useState(localeManager.currentSubject.value);
|
|
18
|
-
React.useEffect(() => {
|
|
19
|
-
const subscription = localeManager.currentSubject.subscribe(l => setLocale(l));
|
|
20
|
-
return () => subscription.unsubscribe();
|
|
21
|
-
}, [localeManager]);
|
|
22
22
|
return (React.createElement(IntlProvider, { locale: (locale === null || locale === void 0 ? void 0 : locale.lang) || navigator.language || 'en', messages: locale === null || locale === void 0 ? void 0 : locale.messages, onError: err => {
|
|
23
23
|
if (err.code !== 'MISSING_TRANSLATION') {
|
|
24
24
|
logger.warn(err);
|
|
25
25
|
}
|
|
26
26
|
} }, children));
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
IntlContext.priority = INTL_REACT_CONTEXT_PRIORITY;
|
|
29
29
|
let default_1 = class {
|
|
30
30
|
};
|
|
31
31
|
default_1 = __decorate([
|
|
32
|
-
Context(
|
|
32
|
+
Context(IntlContext)
|
|
33
33
|
], default_1);
|
|
34
34
|
export default default_1;
|
|
35
|
-
//# sourceMappingURL=
|
|
35
|
+
//# sourceMappingURL=intl-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl-context.js","sourceRoot":"","sources":["../../../src/browser/intl/intl-context.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,QAAQ,EAA2B;IAC7D,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAG,SAAS,CAAS,MAAM,CAAC,CAAC;IACzC,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,WAAW,CAAC,QAAQ,GAAG,2BAA2B,CAAC;AAGpC,gBAAA;CAAQ,CAAA;AAAR;IADd,OAAO,CAAC,WAAW,CAAC;aACE"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from './locale-
|
|
2
|
-
export * from './locale-context.js';
|
|
1
|
+
export * from './locale-hooks.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/browser/locale/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/browser/locale/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { LocaleManager } from '@celljs/widget';
|
|
3
|
+
import { useInject } from '../hooks/index.js';
|
|
4
|
+
/** The locale the user selected (`widget.locales`), and how to change it; renders again when it changes. */
|
|
5
|
+
export function useLocale() {
|
|
6
|
+
const localeManager = useInject(LocaleManager);
|
|
7
|
+
const subscribe = React.useCallback((onChange) => {
|
|
8
|
+
const listener = localeManager.onCurrentChanged(onChange);
|
|
9
|
+
return () => listener.dispose();
|
|
10
|
+
}, [localeManager]);
|
|
11
|
+
const locale = React.useSyncExternalStore(subscribe, () => localeManager.current, () => localeManager.current);
|
|
12
|
+
const setLocale = React.useCallback((l) => localeManager.setCurrent(l), [localeManager]);
|
|
13
|
+
return [locale, setLocale];
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=locale-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-hooks.js","sourceRoot":"","sources":["../../../src/browser/locale/locale-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAU,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,4GAA4G;AAC5G,MAAM,UAAU,SAAS;IACrB,MAAM,aAAa,GAAG,SAAS,CAAgB,aAAa,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,QAAoB,EAAE,EAAE;QACzD,MAAM,QAAQ,GAAG,aAAa,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC1D,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACpC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IACpB,MAAM,MAAM,GAAG,KAAK,CAAC,oBAAoB,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC/G,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IACjG,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
const pages = new Map();
|
|
3
3
|
const layouts = new Map();
|
|
4
|
+
const errors = new Map();
|
|
4
5
|
/** Pages of `src/browser/pages` as route metadata: lazy components, so each page is loaded when visited. */
|
|
5
6
|
export var FileRouteUtil;
|
|
6
7
|
(function (FileRouteUtil) {
|
|
@@ -10,9 +11,18 @@ export var FileRouteUtil;
|
|
|
10
11
|
priority: 1000,
|
|
11
12
|
component: page(route),
|
|
12
13
|
...(route.layouts.length ? { layout: layout(route) } : {}),
|
|
14
|
+
...(route.error ? { errorFallback: errorFallback(route.error) } : {}),
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
17
|
FileRouteUtil.toMetadata = toMetadata;
|
|
18
|
+
function errorFallback(error) {
|
|
19
|
+
let component = errors.get(error.file);
|
|
20
|
+
if (!component) {
|
|
21
|
+
component = React.lazy(async () => ({ default: componentOf(await error.load(), error.file) }));
|
|
22
|
+
errors.set(error.file, component);
|
|
23
|
+
}
|
|
24
|
+
return component;
|
|
25
|
+
}
|
|
16
26
|
/** One component per file (and per chain of layouts): React keeps a layout mounted from one page to the next. */
|
|
17
27
|
function page(route) {
|
|
18
28
|
let component = pages.get(route.file);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-route-util.js","sourceRoot":"","sources":["../../../src/browser/router/file-route-util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"file-route-util.js","sourceRoot":"","sources":["../../../src/browser/router/file-route-util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,MAAM,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAC;AACrD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAwD,CAAC;AAChF,MAAM,MAAM,GAAG,IAAI,GAAG,EAAmD,CAAC;AAE1E,4GAA4G;AAC5G,MAAM,KAAW,aAAa,CAqD7B;AArDD,WAAiB,aAAa;IAE1B,SAAgB,UAAU,CAAC,KAAgB;QACvC,OAAO;YACH,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC;YACtB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1D,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxE,CAAC;IACN,CAAC;IARe,cAAA,UAAU,aAQzB,CAAA;IAED,SAAS,aAAa,CAAC,KAAsC;QACzD,IAAI,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/F,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,iHAAiH;IACjH,SAAS,IAAI,CAAC,KAAgB;QAC1B,IAAI,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/F,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,SAAS,MAAM,CAAC,KAAgB;QAC5B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;gBAC9B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBACpG,MAAM,MAAM,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE,CACrD,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,WAAW,CAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;gBAC1J,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;YAC/B,CAAC,CAAC,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,SAAgB,WAAW,CAAI,MAAiB,EAAE,IAAY;QAC1D,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC;QACjC,IAAI,OAAO,SAAS,KAAK,UAAU,IAAI,CAAC,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,CAAC,EAAE,CAAC;YAC3F,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,mGAAmG,CAAC,CAAC;QAChI,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IANe,cAAA,WAAW,cAM1B,CAAA;AACL,CAAC,EArDgB,aAAa,KAAb,aAAa,QAqD7B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ErrorFallbackProps } from '../error/index.js';
|
|
1
2
|
export declare const ROUTER: unique symbol;
|
|
2
3
|
export declare const ROUTE_METADATA: unique symbol;
|
|
3
4
|
export declare const RouteMetadataProvider: unique symbol;
|
|
@@ -9,6 +10,8 @@ export interface RouteMetadata {
|
|
|
9
10
|
path?: string;
|
|
10
11
|
component?: React.ComponentType;
|
|
11
12
|
layout?: React.ComponentType<React.PropsWithChildren>;
|
|
13
|
+
/** What shows, inside the layout, when the page fails; `DefaultErrorFallback` by default. */
|
|
14
|
+
errorFallback?: React.ComponentType<ErrorFallbackProps>;
|
|
12
15
|
priority?: number;
|
|
13
16
|
}
|
|
14
17
|
export interface RouteMetadataConverter {
|
|
@@ -37,4 +40,11 @@ export interface FileRoute {
|
|
|
37
40
|
default?: React.ComponentType<React.PropsWithChildren>;
|
|
38
41
|
}>;
|
|
39
42
|
}[];
|
|
43
|
+
/** The nearest `_error` file: what shows when the page fails. */
|
|
44
|
+
error?: {
|
|
45
|
+
file: string;
|
|
46
|
+
load(): Promise<{
|
|
47
|
+
default?: React.ComponentType<ErrorFallbackProps>;
|
|
48
|
+
}>;
|
|
49
|
+
};
|
|
40
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-protocol.js","sourceRoot":"","sources":["../../../src/browser/router/router-protocol.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router-protocol.js","sourceRoot":"","sources":["../../../src/browser/router/router-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACvC,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEvD,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AACrE,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AACvE,MAAM,CAAC,MAAM,8BAA8B,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ErrorBoundary, ErrorFallbackProps } from '../error/index.js';
|
|
3
|
+
/** The boundary of a page, inside its layout: tries the page again when the user goes to another path. */
|
|
4
|
+
export declare function PageErrorBoundary({ fallback, children }: React.PropsWithChildren<{
|
|
5
|
+
fallback?: React.ComponentType<ErrorFallbackProps>;
|
|
6
|
+
}>): React.CElement<import("../index.js").ErrorBoundaryProps, ErrorBoundary>;
|
|
1
7
|
export default class {
|
|
2
8
|
}
|
|
@@ -6,8 +6,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import { RouteMetadataProvider } from './router-protocol.js';
|
|
9
|
-
import { useRoutes, BrowserRouter, HashRouter, MemoryRouter } from 'react-router';
|
|
9
|
+
import { useRoutes, useLocation, BrowserRouter, HashRouter, MemoryRouter } from 'react-router';
|
|
10
10
|
import { Router } from '../annotation/index.js';
|
|
11
|
+
import { ErrorBoundary } from '../error/index.js';
|
|
11
12
|
import { useInject, useValue } from '../hooks/index.js';
|
|
12
13
|
const routerMap = {
|
|
13
14
|
browser: BrowserRouter,
|
|
@@ -23,15 +24,19 @@ function RouterComponent() {
|
|
|
23
24
|
const routes = React.useMemo(() => routeMetadataProvider.provide().map(toRouteObject), [routeMetadataProvider]);
|
|
24
25
|
return React.createElement(routerMap[routerType], {}, React.createElement(Routes, { routes }));
|
|
25
26
|
}
|
|
27
|
+
/** The boundary of a page, inside its layout: tries the page again when the user goes to another path. */
|
|
28
|
+
export function PageErrorBoundary({ fallback, children }) {
|
|
29
|
+
const { pathname } = useLocation();
|
|
30
|
+
return React.createElement(ErrorBoundary, { fallback, resetKey: pathname }, children);
|
|
31
|
+
}
|
|
26
32
|
function toRouteObject(metadata) {
|
|
27
33
|
let element;
|
|
28
34
|
if (metadata.component) {
|
|
29
|
-
|
|
35
|
+
// Pages of src/browser/pages, their layouts and _error files are lazy components.
|
|
36
|
+
element = React.createElement(PageErrorBoundary, { fallback: metadata.errorFallback }, React.createElement(React.Suspense, { fallback: null }, React.createElement(metadata.component)));
|
|
30
37
|
if (metadata.layout) {
|
|
31
|
-
element = React.createElement(metadata.layout, {}, element);
|
|
38
|
+
element = React.createElement(React.Suspense, { fallback: null }, React.createElement(metadata.layout, {}, element));
|
|
32
39
|
}
|
|
33
|
-
// Pages of src/browser/pages and their layouts are lazy components.
|
|
34
|
-
element = React.createElement(React.Suspense, { fallback: null }, element);
|
|
35
40
|
}
|
|
36
41
|
return {
|
|
37
42
|
path: metadata.path,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/browser/router/router.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAiB,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/browser/router/router.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAiB,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5G,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,aAAa,EAAsB,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,SAAS,GAAG;IACd,OAAO,EAAE,aAAa;IACtB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,YAAY;CACvB,CAAC;AAEF,SAAS,MAAM,CAAC,EAAE,MAAM,EAA6B;IACjD,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,eAAe;IACpB,MAAM,UAAU,GAAG,QAAQ,CAAyB,mBAAmB,EAAE,SAAS,CAAC,CAAC;IACpF,MAAM,qBAAqB,GAAG,SAAS,CAAwB,qBAAqB,CAAC,CAAC;IACtF,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,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,0GAA0G;AAC1G,MAAM,UAAU,iBAAiB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAmF;IACrI,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,EAAE,CAAC;IACnC,OAAO,KAAK,CAAC,aAAa,CAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC;AAC1F,CAAC;AAED,SAAS,aAAa,CAAC,QAAuB;IAC1C,IAAI,OAAwB,CAAC;IAC7B,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;QACrB,kFAAkF;QAClF,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,iBAAiB,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,aAAa,EAAE,EACjF,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACtG,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YAClB,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;QACzH,CAAC;IACL,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,MAAM,CAAC,eAAe,EAAE,KAAK,CAAC;aACR"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractApplicationShell } from '@celljs/core/lib/browser';
|
|
2
|
+
import { Container } from '@celljs/core';
|
|
2
3
|
import * as React from 'react';
|
|
3
|
-
|
|
4
|
+
/** Renders the `@App` component with the container of the application, inside an error boundary. */
|
|
5
|
+
export declare class Shell extends AbstractApplicationShell {
|
|
4
6
|
protected readonly app: React.ComponentType;
|
|
5
|
-
|
|
7
|
+
protected readonly container: Container;
|
|
8
|
+
protected render(host: HTMLElement): void;
|
|
6
9
|
}
|