shelving 1.262.0 → 1.262.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/package.json +1 -1
- package/react/createAPIContext.d.ts +5 -8
- package/react/createAPIContext.js +0 -2
- package/ui/inline/Code.module.css +1 -1
- package/ui/inline/Mark.module.css +2 -2
- package/ui/misc/Catcher.d.ts +9 -30
- package/ui/misc/Catcher.js +11 -10
- package/ui/misc/Catcher.tsx +13 -33
- package/ui/misc/Loader.d.ts +31 -0
- package/ui/misc/Loader.js +29 -0
- package/ui/misc/Loader.tsx +49 -0
- package/ui/misc/index.d.ts +1 -0
- package/ui/misc/index.js +1 -0
- package/ui/misc/index.tsx +1 -0
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { type ReactElement
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
2
|
import type { Endpoint } from "../api/endpoint/Endpoint.js";
|
|
3
3
|
import type { APIProvider } from "../api/provider/APIProvider.js";
|
|
4
4
|
import type { EndpointStore } from "../api/store/EndpointStore.js";
|
|
5
|
+
import type { ChildProps } from "../ui/index.js";
|
|
5
6
|
import type { Nullish } from "../util/null.js";
|
|
6
7
|
/**
|
|
7
|
-
* Bundle of hooks and a provider component returned by `createAPIContext()
|
|
8
|
+
* Bundle of hooks and a provider component returned by `createAPIContext()`
|
|
8
9
|
*
|
|
9
10
|
* @see https://shelving.cc/react/APIContext
|
|
10
11
|
*/
|
|
11
12
|
export interface APIContext<P, R> {
|
|
12
|
-
/**
|
|
13
|
+
/** React hook to return an `EndpointStore` for the specified endpoint/payload in the current `APIProvider` context. */
|
|
13
14
|
useAPI<PP extends P, RR extends R>(this: void, endpoint: Endpoint<PP, RR>, payload: PP): EndpointStore<PP, RR>;
|
|
14
15
|
useAPI<PP extends P, RR extends R>(this: void, endpoint: Nullish<Endpoint<PP, RR>>, payload: PP): EndpointStore<PP, RR> | undefined;
|
|
15
16
|
/** The `<APIContext>` wrapper to give your React components access to this API provider. */
|
|
16
|
-
readonly APIContext: (
|
|
17
|
-
children: ReactNode;
|
|
18
|
-
}) => ReactElement;
|
|
17
|
+
readonly APIContext: (props: ChildProps) => ReactElement;
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
20
|
* Create an API context.
|
|
@@ -24,8 +23,6 @@ export interface APIContext<P, R> {
|
|
|
24
23
|
*
|
|
25
24
|
* @param provider `APIProvider` the created context resolves endpoint stores against.
|
|
26
25
|
*
|
|
27
|
-
* @todo Use and integreate our `EndpointCache` functionality and use it in this.
|
|
28
|
-
*
|
|
29
26
|
* @see https://shelving.cc/react/createAPIContext
|
|
30
27
|
*/
|
|
31
28
|
export declare function createAPIContext<P, R>(provider: APIProvider<P, R>): APIContext<P, R>;
|
|
@@ -11,8 +11,6 @@ import { useStore } from "./useStore.js";
|
|
|
11
11
|
*
|
|
12
12
|
* @param provider `APIProvider` the created context resolves endpoint stores against.
|
|
13
13
|
*
|
|
14
|
-
* @todo Use and integreate our `EndpointCache` functionality and use it in this.
|
|
15
|
-
*
|
|
16
14
|
* @see https://shelving.cc/react/createAPIContext
|
|
17
15
|
*/
|
|
18
16
|
export function createAPIContext(provider) {
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
.prose :is(code, kbd, samp, var):not(pre *) {
|
|
20
20
|
/* Box */
|
|
21
21
|
display: inline-block;
|
|
22
|
-
vertical-align: text-bottom;
|
|
23
22
|
padding-inline: var(--code-padding, var(--space-xxsmall));
|
|
24
23
|
border-radius: var(--code-radius, var(--radius-xxsmall));
|
|
24
|
+
vertical-align: baseline;
|
|
25
25
|
|
|
26
26
|
/* Style */
|
|
27
27
|
background: var(--code-background, var(--tint-90));
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
display: inline-block;
|
|
13
13
|
padding-inline: var(--mark-padding, var(--space-xxsmall));
|
|
14
14
|
border-radius: var(--mark-radius, var(--radius-xxsmall));
|
|
15
|
-
vertical-align:
|
|
15
|
+
vertical-align: baseline;
|
|
16
16
|
|
|
17
17
|
/* Style */
|
|
18
|
-
background
|
|
18
|
+
background: var(--mark-background, var(--tint-80));
|
|
19
19
|
color: var(--mark-color, var(--tint-00));
|
|
20
20
|
|
|
21
21
|
/* Text */
|
package/ui/misc/Catcher.d.ts
CHANGED
|
@@ -22,9 +22,9 @@ export declare function RetryButton({ children, ...props }: RetryButtonProps): R
|
|
|
22
22
|
/**
|
|
23
23
|
* Props for a component that renders a caught error `reason`.
|
|
24
24
|
*
|
|
25
|
-
* @see https://shelving.cc/ui/
|
|
25
|
+
* @see https://shelving.cc/ui/ErrorProps
|
|
26
26
|
*/
|
|
27
|
-
export interface
|
|
27
|
+
export interface ErrorProps {
|
|
28
28
|
reason: unknown;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
@@ -34,7 +34,7 @@ export interface ErrorComponentProps {
|
|
|
34
34
|
*/
|
|
35
35
|
export interface CatcherProps extends ChildProps {
|
|
36
36
|
/** Component to render an error (defaults to `<ErrorNotice />`) */
|
|
37
|
-
as: (props:
|
|
37
|
+
as: (props: ErrorProps) => ReactElement;
|
|
38
38
|
}
|
|
39
39
|
type CatcherState = {
|
|
40
40
|
/** The error that was caught. */
|
|
@@ -56,27 +56,6 @@ export declare class Catcher extends Component<CatcherProps, CatcherState> {
|
|
|
56
56
|
static getDerivedStateFromError(reason: unknown): CatcherState;
|
|
57
57
|
render(): ReactNode;
|
|
58
58
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Props for `<PageCatcher>` — the page `children` to guard.
|
|
61
|
-
*
|
|
62
|
-
* @see https://shelving.cc/ui/PageCatcherProps
|
|
63
|
-
*/
|
|
64
|
-
export interface PageCatcherProps extends ChildProps {
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Error boundary for a whole page that renders a full `<ErrorPage>` fallback on error.
|
|
68
|
-
*
|
|
69
|
-
* @kind component
|
|
70
|
-
* @see https://shelving.cc/ui/PageCatcher
|
|
71
|
-
*/
|
|
72
|
-
export declare function PageCatcher({ children }: PageCatcherProps): ReactElement;
|
|
73
|
-
/**
|
|
74
|
-
* Props for `<ErrorNotice>` — the caught error `reason`.
|
|
75
|
-
*
|
|
76
|
-
* @see https://shelving.cc/ui/ErrorNoticeProps
|
|
77
|
-
*/
|
|
78
|
-
export interface ErrorNoticeProps extends ErrorComponentProps {
|
|
79
|
-
}
|
|
80
59
|
/**
|
|
81
60
|
* Render a caught error as an inline `<Notice>` with a retry button.
|
|
82
61
|
*
|
|
@@ -85,14 +64,14 @@ export interface ErrorNoticeProps extends ErrorComponentProps {
|
|
|
85
64
|
* @kind component
|
|
86
65
|
* @see https://shelving.cc/ui/ErrorNotice
|
|
87
66
|
*/
|
|
88
|
-
export declare function ErrorNotice({ reason }:
|
|
67
|
+
export declare function ErrorNotice({ reason }: ErrorProps): ReactElement;
|
|
89
68
|
/**
|
|
90
|
-
*
|
|
69
|
+
* Error boundary for a whole page that renders a full `<ErrorPage>` fallback on error.
|
|
91
70
|
*
|
|
92
|
-
* @
|
|
71
|
+
* @kind component
|
|
72
|
+
* @see https://shelving.cc/ui/PageCatcher
|
|
93
73
|
*/
|
|
94
|
-
export
|
|
95
|
-
}
|
|
74
|
+
export declare function PageCatcher({ children }: ChildProps): ReactElement;
|
|
96
75
|
/**
|
|
97
76
|
* Render a caught error as a full-page `<Page>` with an error `<Card>` and retry button.
|
|
98
77
|
*
|
|
@@ -101,5 +80,5 @@ export interface ErrorPageProps extends ErrorComponentProps {
|
|
|
101
80
|
* @kind component
|
|
102
81
|
* @see https://shelving.cc/ui/ErrorPage
|
|
103
82
|
*/
|
|
104
|
-
export declare function ErrorPage({ reason }:
|
|
83
|
+
export declare function ErrorPage({ reason }: ErrorProps): ReactElement;
|
|
105
84
|
export {};
|
package/ui/misc/Catcher.js
CHANGED
|
@@ -3,6 +3,7 @@ import { ArrowPathIcon } from "@heroicons/react/24/solid";
|
|
|
3
3
|
import { Component, createContext, use } from "react";
|
|
4
4
|
import { getMessage } from "../../util/error.js";
|
|
5
5
|
import { Card } from "../block/Card.js";
|
|
6
|
+
import { Paragraph } from "../block/Paragraph.js";
|
|
6
7
|
import { Row } from "../block/Row.js";
|
|
7
8
|
import { Subheading } from "../block/Subheading.js";
|
|
8
9
|
import { Button } from "../form/Button.js";
|
|
@@ -59,15 +60,6 @@ export class Catcher extends Component {
|
|
|
59
60
|
return (_jsx(RetryContext, { value: retry, children: _jsx(ErrorComponent, { reason: reason }) }));
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Error boundary for a whole page that renders a full `<ErrorPage>` fallback on error.
|
|
64
|
-
*
|
|
65
|
-
* @kind component
|
|
66
|
-
* @see https://shelving.cc/ui/PageCatcher
|
|
67
|
-
*/
|
|
68
|
-
export function PageCatcher({ children }) {
|
|
69
|
-
return _jsx(Catcher, { as: ErrorPage, children: children });
|
|
70
|
-
}
|
|
71
63
|
/**
|
|
72
64
|
* Render a caught error as an inline `<Notice>` with a retry button.
|
|
73
65
|
*
|
|
@@ -78,7 +70,16 @@ export function PageCatcher({ children }) {
|
|
|
78
70
|
*/
|
|
79
71
|
export function ErrorNotice({ reason }) {
|
|
80
72
|
const message = getMessage(reason) ?? "Unknown error";
|
|
81
|
-
return (_jsxs(Notice, { status: "error", children: [_jsx(
|
|
73
|
+
return (_jsxs(Notice, { status: "error", children: [_jsx(Paragraph, { children: message }), _jsx(RetryButton, { small: true })] }));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Error boundary for a whole page that renders a full `<ErrorPage>` fallback on error.
|
|
77
|
+
*
|
|
78
|
+
* @kind component
|
|
79
|
+
* @see https://shelving.cc/ui/PageCatcher
|
|
80
|
+
*/
|
|
81
|
+
export function PageCatcher({ children }) {
|
|
82
|
+
return _jsx(Catcher, { as: ErrorPage, children: children });
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
84
85
|
* Render a caught error as a full-page `<Page>` with an error `<Card>` and retry button.
|
package/ui/misc/Catcher.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { Component, createContext, type ReactElement, type ReactNode, use } from
|
|
|
3
3
|
import { getMessage } from "../../util/error.js";
|
|
4
4
|
import type { Callback } from "../../util/function.js";
|
|
5
5
|
import { Card } from "../block/Card.js";
|
|
6
|
+
import { Paragraph } from "../block/Paragraph.js";
|
|
6
7
|
import { Row } from "../block/Row.js";
|
|
7
8
|
import { Subheading } from "../block/Subheading.js";
|
|
8
9
|
import { Button, type ButtonVariants } from "../form/Button.js";
|
|
@@ -51,9 +52,9 @@ export function RetryButton({ children = RETRY_CHILDREN, ...props }: RetryButton
|
|
|
51
52
|
/**
|
|
52
53
|
* Props for a component that renders a caught error `reason`.
|
|
53
54
|
*
|
|
54
|
-
* @see https://shelving.cc/ui/
|
|
55
|
+
* @see https://shelving.cc/ui/ErrorProps
|
|
55
56
|
*/
|
|
56
|
-
export interface
|
|
57
|
+
export interface ErrorProps {
|
|
57
58
|
reason: unknown;
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -64,7 +65,7 @@ export interface ErrorComponentProps {
|
|
|
64
65
|
*/
|
|
65
66
|
export interface CatcherProps extends ChildProps {
|
|
66
67
|
/** Component to render an error (defaults to `<ErrorNotice />`) */
|
|
67
|
-
as: (props:
|
|
68
|
+
as: (props: ErrorProps) => ReactElement;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
type CatcherState = {
|
|
@@ -107,30 +108,6 @@ export class Catcher extends Component<CatcherProps, CatcherState> {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
/**
|
|
111
|
-
* Props for `<PageCatcher>` — the page `children` to guard.
|
|
112
|
-
*
|
|
113
|
-
* @see https://shelving.cc/ui/PageCatcherProps
|
|
114
|
-
*/
|
|
115
|
-
export interface PageCatcherProps extends ChildProps {}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Error boundary for a whole page that renders a full `<ErrorPage>` fallback on error.
|
|
119
|
-
*
|
|
120
|
-
* @kind component
|
|
121
|
-
* @see https://shelving.cc/ui/PageCatcher
|
|
122
|
-
*/
|
|
123
|
-
export function PageCatcher({ children }: PageCatcherProps): ReactElement {
|
|
124
|
-
return <Catcher as={ErrorPage}>{children}</Catcher>;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Props for `<ErrorNotice>` — the caught error `reason`.
|
|
129
|
-
*
|
|
130
|
-
* @see https://shelving.cc/ui/ErrorNoticeProps
|
|
131
|
-
*/
|
|
132
|
-
export interface ErrorNoticeProps extends ErrorComponentProps {}
|
|
133
|
-
|
|
134
111
|
/**
|
|
135
112
|
* Render a caught error as an inline `<Notice>` with a retry button.
|
|
136
113
|
*
|
|
@@ -139,22 +116,25 @@ export interface ErrorNoticeProps extends ErrorComponentProps {}
|
|
|
139
116
|
* @kind component
|
|
140
117
|
* @see https://shelving.cc/ui/ErrorNotice
|
|
141
118
|
*/
|
|
142
|
-
export function ErrorNotice({ reason }:
|
|
119
|
+
export function ErrorNotice({ reason }: ErrorProps): ReactElement {
|
|
143
120
|
const message = getMessage(reason) ?? "Unknown error";
|
|
144
121
|
return (
|
|
145
122
|
<Notice status="error">
|
|
146
|
-
<
|
|
123
|
+
<Paragraph>{message}</Paragraph>
|
|
147
124
|
<RetryButton small />
|
|
148
125
|
</Notice>
|
|
149
126
|
);
|
|
150
127
|
}
|
|
151
128
|
|
|
152
129
|
/**
|
|
153
|
-
*
|
|
130
|
+
* Error boundary for a whole page that renders a full `<ErrorPage>` fallback on error.
|
|
154
131
|
*
|
|
155
|
-
* @
|
|
132
|
+
* @kind component
|
|
133
|
+
* @see https://shelving.cc/ui/PageCatcher
|
|
156
134
|
*/
|
|
157
|
-
export
|
|
135
|
+
export function PageCatcher({ children }: ChildProps): ReactElement {
|
|
136
|
+
return <Catcher as={ErrorPage}>{children}</Catcher>;
|
|
137
|
+
}
|
|
158
138
|
|
|
159
139
|
/**
|
|
160
140
|
* Render a caught error as a full-page `<Page>` with an error `<Card>` and retry button.
|
|
@@ -164,7 +144,7 @@ export interface ErrorPageProps extends ErrorComponentProps {}
|
|
|
164
144
|
* @kind component
|
|
165
145
|
* @see https://shelving.cc/ui/ErrorPage
|
|
166
146
|
*/
|
|
167
|
-
export function ErrorPage({ reason }:
|
|
147
|
+
export function ErrorPage({ reason }: ErrorProps): ReactElement {
|
|
168
148
|
const message = getMessage(reason) ?? "Unknown error";
|
|
169
149
|
return (
|
|
170
150
|
<Page title="Error">
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { ChildProps } from "../util/props.js";
|
|
3
|
+
/**
|
|
4
|
+
* Props for `<Loader>` and `<PageLoader>` — the `children` to load plus an optional `fallback` shown while they suspend.
|
|
5
|
+
*
|
|
6
|
+
* @see https://shelving.cc/ui/LoaderProps
|
|
7
|
+
*/
|
|
8
|
+
export interface LoaderProps extends ChildProps {
|
|
9
|
+
/** Element rendered while `children` suspend (defaults to `LOADING`). */
|
|
10
|
+
readonly fallback?: ReactNode | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Load a component.
|
|
14
|
+
*
|
|
15
|
+
* - Wrapped in `<Catcher>` so child components can throw errors.
|
|
16
|
+
* - Wrapped in `<Suspense>` so child components can throw promises.
|
|
17
|
+
*
|
|
18
|
+
* @kind component
|
|
19
|
+
* @see https://shelving.cc/ui/Loader
|
|
20
|
+
*/
|
|
21
|
+
export declare function Loader({ children, fallback }: LoaderProps): ReactElement;
|
|
22
|
+
/**
|
|
23
|
+
* Load a page.
|
|
24
|
+
*
|
|
25
|
+
* - Wrapped in `<PageCatcher>` so child components can throw errors.
|
|
26
|
+
* - Wrapped in `<Suspense>` so child components can throw promises.
|
|
27
|
+
*
|
|
28
|
+
* @kind component
|
|
29
|
+
* @see https://shelving.cc/ui/PageLoader
|
|
30
|
+
*/
|
|
31
|
+
export declare function PageLoader({ children, fallback }: LoaderProps): ReactElement;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense } from "react";
|
|
3
|
+
import { CenteredLayout } from "../layout/CenteredLayout.js";
|
|
4
|
+
import { Catcher, PageCatcher } from "./Catcher.js";
|
|
5
|
+
import { LOADING } from "./Loading.js";
|
|
6
|
+
/**
|
|
7
|
+
* Load a component.
|
|
8
|
+
*
|
|
9
|
+
* - Wrapped in `<Catcher>` so child components can throw errors.
|
|
10
|
+
* - Wrapped in `<Suspense>` so child components can throw promises.
|
|
11
|
+
*
|
|
12
|
+
* @kind component
|
|
13
|
+
* @see https://shelving.cc/ui/Loader
|
|
14
|
+
*/
|
|
15
|
+
export function Loader({ children, fallback = LOADING }) {
|
|
16
|
+
return (_jsx(Catcher, { children: _jsx(Suspense, { fallback: fallback, children: children }) }));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Load a page.
|
|
20
|
+
*
|
|
21
|
+
* - Wrapped in `<PageCatcher>` so child components can throw errors.
|
|
22
|
+
* - Wrapped in `<Suspense>` so child components can throw promises.
|
|
23
|
+
*
|
|
24
|
+
* @kind component
|
|
25
|
+
* @see https://shelving.cc/ui/PageLoader
|
|
26
|
+
*/
|
|
27
|
+
export function PageLoader({ children, fallback = _jsx(CenteredLayout, { children: LOADING }) }) {
|
|
28
|
+
return (_jsx(PageCatcher, { children: _jsx(Suspense, { fallback: fallback, children: children }) }));
|
|
29
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode, Suspense } from "react";
|
|
2
|
+
import { CenteredLayout } from "../layout/CenteredLayout.js";
|
|
3
|
+
import type { ChildProps } from "../util/props.js";
|
|
4
|
+
import { Catcher, PageCatcher } from "./Catcher.js";
|
|
5
|
+
import { LOADING } from "./Loading.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for `<Loader>` and `<PageLoader>` — the `children` to load plus an optional `fallback` shown while they suspend.
|
|
9
|
+
*
|
|
10
|
+
* @see https://shelving.cc/ui/LoaderProps
|
|
11
|
+
*/
|
|
12
|
+
export interface LoaderProps extends ChildProps {
|
|
13
|
+
/** Element rendered while `children` suspend (defaults to `LOADING`). */
|
|
14
|
+
readonly fallback?: ReactNode | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Load a component.
|
|
19
|
+
*
|
|
20
|
+
* - Wrapped in `<Catcher>` so child components can throw errors.
|
|
21
|
+
* - Wrapped in `<Suspense>` so child components can throw promises.
|
|
22
|
+
*
|
|
23
|
+
* @kind component
|
|
24
|
+
* @see https://shelving.cc/ui/Loader
|
|
25
|
+
*/
|
|
26
|
+
export function Loader({ children, fallback = LOADING }: LoaderProps): ReactElement {
|
|
27
|
+
return (
|
|
28
|
+
<Catcher>
|
|
29
|
+
<Suspense fallback={fallback}>{children}</Suspense>
|
|
30
|
+
</Catcher>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Load a page.
|
|
36
|
+
*
|
|
37
|
+
* - Wrapped in `<PageCatcher>` so child components can throw errors.
|
|
38
|
+
* - Wrapped in `<Suspense>` so child components can throw promises.
|
|
39
|
+
*
|
|
40
|
+
* @kind component
|
|
41
|
+
* @see https://shelving.cc/ui/PageLoader
|
|
42
|
+
*/
|
|
43
|
+
export function PageLoader({ children, fallback = <CenteredLayout>{LOADING}</CenteredLayout> }: LoaderProps): ReactElement {
|
|
44
|
+
return (
|
|
45
|
+
<PageCatcher>
|
|
46
|
+
<Suspense fallback={fallback}>{children}</Suspense>
|
|
47
|
+
</PageCatcher>
|
|
48
|
+
);
|
|
49
|
+
}
|
package/ui/misc/index.d.ts
CHANGED
package/ui/misc/index.js
CHANGED