shelving 1.320.0 → 1.321.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.
- package/docs/guides/building-with-shelving.md +26 -0
- package/docs/llms-full.txt +629 -257
- package/docs/ui/BackButton.md +75 -0
- package/docs/ui/BackButtonProps.md +21 -0
- package/docs/ui/ClickableProps.md +0 -2
- package/docs/ui/Head.md +2 -2
- package/docs/ui/HorizontalTransition.md +1 -1
- package/docs/ui/LinkClickable.md +0 -1
- package/docs/ui/Meta.md +3 -1
- package/docs/ui/Navigation.md +93 -37
- package/docs/ui/NavigationEntryState.md +22 -0
- package/docs/ui/NavigationPosition.md +24 -0
- package/docs/ui/NavigationPositionContext.md +8 -0
- package/docs/ui/NavigationProps.md +12 -2
- package/docs/ui/NavigationStore/back.md +6 -4
- package/docs/ui/NavigationStore/forward.md +6 -2
- package/docs/ui/NavigationStore/history.md +15 -0
- package/docs/ui/NavigationStore/listen.md +14 -0
- package/docs/ui/NavigationStore/replace.md +15 -0
- package/docs/ui/NavigationStore.md +100 -19
- package/docs/ui/RouteCache.md +72 -36
- package/docs/ui/RouteCacheProps.md +3 -3
- package/docs/ui/Router.md +4 -2
- package/docs/ui/StackButton.md +64 -0
- package/docs/ui/StackButtonProps.md +21 -0
- package/docs/ui/VerticalTransition.md +1 -1
- package/docs/ui/mergeMeta.md +2 -1
- package/docs/ui.md +13 -10
- package/package.json +1 -1
- package/ui/button/Clickable.d.ts +1 -3
- package/ui/button/Clickable.js +2 -2
- package/ui/button/Clickable.tsx +0 -4
- package/ui/page/Head.d.ts +2 -2
- package/ui/page/Head.js +9 -8
- package/ui/page/Head.tsx +8 -6
- package/ui/router/BackButton.d.ts +22 -0
- package/ui/router/BackButton.js +19 -0
- package/ui/router/BackButton.md +47 -0
- package/ui/router/BackButton.tsx +34 -0
- package/ui/router/Navigation.d.ts +22 -12
- package/ui/router/Navigation.js +67 -51
- package/ui/router/Navigation.md +84 -27
- package/ui/router/Navigation.test.tsx +27 -7
- package/ui/router/Navigation.tsx +90 -53
- package/ui/router/NavigationContext.d.ts +9 -1
- package/ui/router/NavigationContext.js +9 -0
- package/ui/router/NavigationContext.tsx +11 -1
- package/ui/router/NavigationStore.d.ts +126 -19
- package/ui/router/NavigationStore.js +301 -30
- package/ui/router/NavigationStore.md +82 -9
- package/ui/router/NavigationStore.test.ts +384 -0
- package/ui/router/NavigationStore.tsx +347 -30
- package/ui/router/RouteCache.d.ts +15 -22
- package/ui/router/RouteCache.js +36 -47
- package/ui/router/RouteCache.md +59 -16
- package/ui/router/RouteCache.tsx +55 -62
- package/ui/router/Router.d.ts +2 -1
- package/ui/router/Router.js +9 -14
- package/ui/router/Router.md +2 -1
- package/ui/router/Router.tsx +9 -20
- package/ui/router/StackButton.d.ts +24 -0
- package/ui/router/StackButton.js +35 -0
- package/ui/router/StackButton.md +34 -0
- package/ui/router/StackButton.tsx +44 -0
- package/ui/router/index.d.ts +2 -2
- package/ui/router/index.js +2 -2
- package/ui/router/index.ts +2 -2
- package/ui/transition/HorizontalTransition.md +1 -1
- package/ui/transition/VerticalTransition.md +1 -1
- package/ui/util/meta.d.ts +4 -1
- package/ui/util/meta.ts +4 -1
- package/docs/ui/NavigationStore/redirect.md +0 -12
- package/docs/ui/RouteConfig.md +0 -75
- package/docs/ui/RouteConfigProps.md +0 -24
- package/docs/ui/RouteContext.md +0 -6
- package/docs/ui/RouteState.md +0 -30
- package/ui/router/RouteConfig.d.ts +0 -28
- package/ui/router/RouteConfig.js +0 -30
- package/ui/router/RouteConfig.md +0 -42
- package/ui/router/RouteConfig.tsx +0 -44
- package/ui/router/RouteContext.d.ts +0 -22
- package/ui/router/RouteContext.js +0 -8
- package/ui/router/RouteContext.tsx +0 -26
package/ui/util/meta.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ImmutableDictionary } from "../../util/dictionary.js";
|
|
|
3
3
|
import type { AnyCaller } from "../../util/function.js";
|
|
4
4
|
import { type PossibleLink } from "../../util/link.js";
|
|
5
5
|
import type { Nullish } from "../../util/null.js";
|
|
6
|
+
import type { AbsolutePath } from "../../util/path.js";
|
|
6
7
|
import { type ImmutableURI, type PossibleURI, type PossibleURIParams } from "../../util/uri.js";
|
|
7
8
|
import { ImmutableURL, type PossibleURL } from "../../util/url.js";
|
|
8
9
|
/**
|
|
@@ -51,8 +52,10 @@ export type MetaCSP = {
|
|
|
51
52
|
export interface Meta {
|
|
52
53
|
/** Base URL for the app (used to resolve `url` and set as `<base>` tag in `<Head>`). */
|
|
53
54
|
readonly root?: ImmutableURL | undefined;
|
|
54
|
-
/** URL of the current page (used
|
|
55
|
+
/** URL of the current page (used as the initial URL for routing, and as the page's canonical URL in `<Head>`). */
|
|
55
56
|
readonly url?: ImmutableURL | undefined;
|
|
57
|
+
/** Root path of the current stack (for example `"/home"`). Set it above `<Navigation>` to choose the stack the app opens in. `<Navigation>` publishes the live stack, which is `"/"` for an unstacked page. */
|
|
58
|
+
readonly stack?: AbsolutePath | undefined;
|
|
56
59
|
/** Title of the entire application. */
|
|
57
60
|
readonly app?: string | undefined;
|
|
58
61
|
/** Title of the current page (set as `<title>` in `<Head>` */
|
package/ui/util/meta.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type DictionaryItem, getDictionaryItems, type ImmutableDictionary } fro
|
|
|
3
3
|
import type { AnyCaller } from "../../util/function.js";
|
|
4
4
|
import { type PossibleLink, requireLink } from "../../util/link.js";
|
|
5
5
|
import type { Nullish } from "../../util/null.js";
|
|
6
|
+
import type { AbsolutePath } from "../../util/path.js";
|
|
6
7
|
import { type ImmutableURI, type PossibleURI, type PossibleURIParams, withURIParams } from "../../util/uri.js";
|
|
7
8
|
import { ImmutableURL, type PossibleURL, requireURL } from "../../util/url.js";
|
|
8
9
|
|
|
@@ -56,8 +57,10 @@ export type MetaCSP = { readonly [resource: string]: string[] };
|
|
|
56
57
|
export interface Meta {
|
|
57
58
|
/** Base URL for the app (used to resolve `url` and set as `<base>` tag in `<Head>`). */
|
|
58
59
|
readonly root?: ImmutableURL | undefined;
|
|
59
|
-
/** URL of the current page (used
|
|
60
|
+
/** URL of the current page (used as the initial URL for routing, and as the page's canonical URL in `<Head>`). */
|
|
60
61
|
readonly url?: ImmutableURL | undefined;
|
|
62
|
+
/** Root path of the current stack (for example `"/home"`). Set it above `<Navigation>` to choose the stack the app opens in. `<Navigation>` publishes the live stack, which is `"/"` for an unstacked page. */
|
|
63
|
+
readonly stack?: AbsolutePath | undefined;
|
|
61
64
|
/** Title of the entire application. */
|
|
62
65
|
readonly app?: string | undefined;
|
|
63
66
|
/** Title of the current page (set as `<title>` in `<Head>` */
|
package/docs/ui/RouteConfig.md
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# RouteConfig
|
|
2
|
-
|
|
3
|
-
- Kind: component
|
|
4
|
-
- Import: `import { RouteConfig } from "shelving/ui";`
|
|
5
|
-
|
|
6
|
-
Configure the current page for the surrounding `<Router>` (and `<RouteCache>`).
|
|
7
|
-
- `path` says the page owns every path that matches a template. A navigation to a path the page owns keeps the same
|
|
8
|
-
page mounted, so it keeps its scroll and state, and a `<ViewTransition>` around the page does not run an enter or
|
|
9
|
-
exit. The page updates for the new URL. Use it for a page whose tabs each have their own path: `path="/dave/{tab}"`.
|
|
10
|
-
- Put the real values in the template. `/{name}/{tab}` would make every person's profile one page.
|
|
11
|
-
- `cache={false}` makes `<RouteCache>` drop the page when you leave it, so the next visit starts again with no old
|
|
12
|
-
state. Use it for a form that makes or edits something, for example a "New challenge" page.
|
|
13
|
-
|
|
14
|
-
Configure the current page for the surrounding `<Router>` (and `<RouteCache>`, if there is one). It has one prop for each setting, so a page wraps itself in one `<RouteConfig>` for all its settings.
|
|
15
|
-
|
|
16
|
-
- `path` says the page owns every path that matches a template. A navigation between paths the page owns keeps the same page mounted: it keeps its scroll and state, and a `<ViewTransition>` around the page does not slide. Use it for a page whose tabs each have their own path.
|
|
17
|
-
- `cache={false}` tells `<RouteCache>` to drop the page when you leave it. The next visit starts again, with no old state. Use it for a form that makes or edits something, so it never shows old input.
|
|
18
|
-
|
|
19
|
-
**Things to know:**
|
|
20
|
-
|
|
21
|
-
- Without `path`, each path is its own page, so `/challenge/123` and `/challenge/456` stay separate pages.
|
|
22
|
-
- Put the real values in the template (`/dave/{tab}`). A template such as `/{name}/{tab}` makes every profile the same page.
|
|
23
|
-
- The page still renders for the new URL, so it reads the tab from the URL as usual.
|
|
24
|
-
- The cache key is the path only, not the `?query`. A page that reads its `?query` once (for example `/new?from=123`) should use `cache={false}`, so a visit with another `?query` does not show the old page.
|
|
25
|
-
- It works with or without a `<RouteCache>`. In a nested router's page, it tells only that nested router.
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
|
|
29
|
-
```tsx
|
|
30
|
-
import { Page, RouteConfig } from "shelving/ui";
|
|
31
|
-
|
|
32
|
-
// Each tab has its own path, and all of them are the same page.
|
|
33
|
-
function ProfilePage({ name, tab }: { name: string; tab?: string }) {
|
|
34
|
-
return (
|
|
35
|
-
<RouteConfig path={`/${name}/{tab}`}>
|
|
36
|
-
<Page title={name}>
|
|
37
|
-
<ProfileTabs tab={tab} />
|
|
38
|
-
</Page>
|
|
39
|
-
</RouteConfig>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// A new form on each visit.
|
|
44
|
-
function NewChallengePage({ from }: { from?: string }) {
|
|
45
|
-
return (
|
|
46
|
-
<RouteConfig cache={false}>
|
|
47
|
-
<Page title="New challenge">
|
|
48
|
-
<ChallengeForm from={from} />
|
|
49
|
-
</Page>
|
|
50
|
-
</RouteConfig>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
## Signatures
|
|
57
|
-
|
|
58
|
-
```ts
|
|
59
|
-
RouteConfig({ path, cache, children }: RouteConfigProps): ReactNode
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Parameters
|
|
63
|
-
|
|
64
|
-
| Param | Type | Description |
|
|
65
|
-
| --- | --- | --- |
|
|
66
|
-
| `props` | `RouteConfigProps` | |
|
|
67
|
-
| `.path` | `AbsolutePath \| undefined` | Path template the page owns, for example `/dave/{tab}`. Every path that matches it shows this same page. Read only. Optional. |
|
|
68
|
-
| `.cache` | `boolean \| undefined` | Set to `false` so `<RouteCache>` drops the page when you leave it, and the next visit shows a new page. Defaults to `true`. Read only. Optional. |
|
|
69
|
-
| `.children` | `ReactNode` | The page content. Read only. Optional. |
|
|
70
|
-
|
|
71
|
-
## Returns
|
|
72
|
-
|
|
73
|
-
| Type | Description |
|
|
74
|
-
| --- | --- |
|
|
75
|
-
| `ReactNode` | |
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# RouteConfigProps
|
|
2
|
-
|
|
3
|
-
- Kind: interface
|
|
4
|
-
- Import: `import { RouteConfigProps } from "shelving/ui";`
|
|
5
|
-
|
|
6
|
-
Props for `<RouteConfig>` — the settings of a page for the surrounding `<Router>` and `<RouteCache>`, and the page content.
|
|
7
|
-
|
|
8
|
-
## Signatures
|
|
9
|
-
|
|
10
|
-
```ts
|
|
11
|
-
{
|
|
12
|
-
readonly path?: AbsolutePath | undefined;
|
|
13
|
-
readonly cache?: boolean | undefined;
|
|
14
|
-
readonly children?: ReactNode;
|
|
15
|
-
}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Properties
|
|
19
|
-
|
|
20
|
-
| Property | Type | Description |
|
|
21
|
-
| --- | --- | --- |
|
|
22
|
-
| `path` | `AbsolutePath \| undefined` | Path template the page owns, for example `/dave/{tab}`. Every path that matches it shows this same page. Read only. Optional. |
|
|
23
|
-
| `cache` | `boolean \| undefined` | Set to `false` so `<RouteCache>` drops the page when you leave it, and the next visit shows a new page. Defaults to `true`. Read only. Optional. |
|
|
24
|
-
| `children` | `ReactNode` | The page content. Read only. Optional. |
|
package/docs/ui/RouteContext.md
DELETED
package/docs/ui/RouteState.md
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# RouteState
|
|
2
|
-
|
|
3
|
-
- Kind: interface
|
|
4
|
-
- Import: `import { RouteState } from "shelving/ui";`
|
|
5
|
-
|
|
6
|
-
The route state of one page, shared by `<Router>`, `<RouteCache>` and `<RouteConfig>`.
|
|
7
|
-
- `path` is the template of the paths the page owns, set by `<RouteConfig path>`.
|
|
8
|
-
- `cache` is `false` when `<RouteCache>` drops the page as you leave it, set by `<RouteConfig cache>`.
|
|
9
|
-
- `entry` is the page's `<RouteCache>` entry, so `<RouteConfig>` in a top-level page also tells the cache.
|
|
10
|
-
- `router` marks a state made by `<Router>`, so a nested router does not pass the cache entry on.
|
|
11
|
-
|
|
12
|
-
## Signatures
|
|
13
|
-
|
|
14
|
-
```ts
|
|
15
|
-
{
|
|
16
|
-
path?: AbsolutePath | undefined;
|
|
17
|
-
cache?: boolean | undefined;
|
|
18
|
-
readonly entry?: RouteState | undefined;
|
|
19
|
-
readonly router?: true | undefined;
|
|
20
|
-
}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Properties
|
|
24
|
-
|
|
25
|
-
| Property | Type | Description |
|
|
26
|
-
| --- | --- | --- |
|
|
27
|
-
| `path` | `AbsolutePath \| undefined` | Optional. |
|
|
28
|
-
| `cache` | `boolean \| undefined` | Optional. |
|
|
29
|
-
| `entry` | `RouteState \| undefined` | Read only. Optional. |
|
|
30
|
-
| `router` | `true \| undefined` | Read only. Optional. |
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
2
|
-
import type { AbsolutePath } from "../../util/path.js";
|
|
3
|
-
/**
|
|
4
|
-
* Props for `<RouteConfig>` — the settings of a page for the surrounding `<Router>` and `<RouteCache>`, and the page content.
|
|
5
|
-
*
|
|
6
|
-
* @see https://shelving.cc/ui/RouteConfigProps
|
|
7
|
-
*/
|
|
8
|
-
export interface RouteConfigProps {
|
|
9
|
-
/** Path template the page owns, for example `/dave/{tab}`. Every path that matches it shows this same page. */
|
|
10
|
-
readonly path?: AbsolutePath | undefined;
|
|
11
|
-
/** Set to `false` so `<RouteCache>` drops the page when you leave it, and the next visit shows a new page. Defaults to `true`. */
|
|
12
|
-
readonly cache?: boolean | undefined;
|
|
13
|
-
/** The page content. */
|
|
14
|
-
readonly children?: ReactNode;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Configure the current page for the surrounding `<Router>` (and `<RouteCache>`).
|
|
18
|
-
* - `path` says the page owns every path that matches a template. A navigation to a path the page owns keeps the same
|
|
19
|
-
* page mounted, so it keeps its scroll and state, and a `<ViewTransition>` around the page does not run an enter or
|
|
20
|
-
* exit. The page updates for the new URL. Use it for a page whose tabs each have their own path: `path="/dave/{tab}"`.
|
|
21
|
-
* - Put the real values in the template. `/{name}/{tab}` would make every person's profile one page.
|
|
22
|
-
* - `cache={false}` makes `<RouteCache>` drop the page when you leave it, so the next visit starts again with no old
|
|
23
|
-
* state. Use it for a form that makes or edits something, for example a "New challenge" page.
|
|
24
|
-
*
|
|
25
|
-
* @kind component
|
|
26
|
-
* @see https://shelving.cc/ui/RouteConfig
|
|
27
|
-
*/
|
|
28
|
-
export declare function RouteConfig({ path, cache, children }: RouteConfigProps): ReactNode;
|
package/ui/router/RouteConfig.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { use } from "react";
|
|
2
|
-
import { RouteContext } from "./RouteContext.js";
|
|
3
|
-
/**
|
|
4
|
-
* Configure the current page for the surrounding `<Router>` (and `<RouteCache>`).
|
|
5
|
-
* - `path` says the page owns every path that matches a template. A navigation to a path the page owns keeps the same
|
|
6
|
-
* page mounted, so it keeps its scroll and state, and a `<ViewTransition>` around the page does not run an enter or
|
|
7
|
-
* exit. The page updates for the new URL. Use it for a page whose tabs each have their own path: `path="/dave/{tab}"`.
|
|
8
|
-
* - Put the real values in the template. `/{name}/{tab}` would make every person's profile one page.
|
|
9
|
-
* - `cache={false}` makes `<RouteCache>` drop the page when you leave it, so the next visit starts again with no old
|
|
10
|
-
* state. Use it for a form that makes or edits something, for example a "New challenge" page.
|
|
11
|
-
*
|
|
12
|
-
* @kind component
|
|
13
|
-
* @see https://shelving.cc/ui/RouteConfig
|
|
14
|
-
*/
|
|
15
|
-
export function RouteConfig({ path, cache, children }) {
|
|
16
|
-
const state = use(RouteContext);
|
|
17
|
-
if (state) {
|
|
18
|
-
_configure(state, path, cache);
|
|
19
|
-
if (state.entry)
|
|
20
|
-
_configure(state.entry, path, cache);
|
|
21
|
-
}
|
|
22
|
-
return children;
|
|
23
|
-
}
|
|
24
|
-
/** Set the given settings on a page's route state. */
|
|
25
|
-
function _configure(state, path, cache) {
|
|
26
|
-
if (path !== undefined)
|
|
27
|
-
state.path = path;
|
|
28
|
-
if (cache !== undefined)
|
|
29
|
-
state.cache = cache;
|
|
30
|
-
}
|
package/ui/router/RouteConfig.md
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# RouteConfig
|
|
2
|
-
|
|
3
|
-
Configure the current page for the surrounding `<Router>` (and `<RouteCache>`, if there is one). It has one prop for each setting, so a page wraps itself in one `<RouteConfig>` for all its settings.
|
|
4
|
-
|
|
5
|
-
- `path` says the page owns every path that matches a template. A navigation between paths the page owns keeps the same page mounted: it keeps its scroll and state, and a `<ViewTransition>` around the page does not slide. Use it for a page whose tabs each have their own path.
|
|
6
|
-
- `cache={false}` tells `<RouteCache>` to drop the page when you leave it. The next visit starts again, with no old state. Use it for a form that makes or edits something, so it never shows old input.
|
|
7
|
-
|
|
8
|
-
**Things to know:**
|
|
9
|
-
|
|
10
|
-
- Without `path`, each path is its own page, so `/challenge/123` and `/challenge/456` stay separate pages.
|
|
11
|
-
- Put the real values in the template (`/dave/{tab}`). A template such as `/{name}/{tab}` makes every profile the same page.
|
|
12
|
-
- The page still renders for the new URL, so it reads the tab from the URL as usual.
|
|
13
|
-
- The cache key is the path only, not the `?query`. A page that reads its `?query` once (for example `/new?from=123`) should use `cache={false}`, so a visit with another `?query` does not show the old page.
|
|
14
|
-
- It works with or without a `<RouteCache>`. In a nested router's page, it tells only that nested router.
|
|
15
|
-
|
|
16
|
-
## Usage
|
|
17
|
-
|
|
18
|
-
```tsx
|
|
19
|
-
import { Page, RouteConfig } from "shelving/ui";
|
|
20
|
-
|
|
21
|
-
// Each tab has its own path, and all of them are the same page.
|
|
22
|
-
function ProfilePage({ name, tab }: { name: string; tab?: string }) {
|
|
23
|
-
return (
|
|
24
|
-
<RouteConfig path={`/${name}/{tab}`}>
|
|
25
|
-
<Page title={name}>
|
|
26
|
-
<ProfileTabs tab={tab} />
|
|
27
|
-
</Page>
|
|
28
|
-
</RouteConfig>
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// A new form on each visit.
|
|
33
|
-
function NewChallengePage({ from }: { from?: string }) {
|
|
34
|
-
return (
|
|
35
|
-
<RouteConfig cache={false}>
|
|
36
|
-
<Page title="New challenge">
|
|
37
|
-
<ChallengeForm from={from} />
|
|
38
|
-
</Page>
|
|
39
|
-
</RouteConfig>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
```
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { type ReactNode, use } from "react";
|
|
2
|
-
import type { AbsolutePath } from "../../util/path.js";
|
|
3
|
-
import { RouteContext, type RouteState } from "./RouteContext.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Props for `<RouteConfig>` — the settings of a page for the surrounding `<Router>` and `<RouteCache>`, and the page content.
|
|
7
|
-
*
|
|
8
|
-
* @see https://shelving.cc/ui/RouteConfigProps
|
|
9
|
-
*/
|
|
10
|
-
export interface RouteConfigProps {
|
|
11
|
-
/** Path template the page owns, for example `/dave/{tab}`. Every path that matches it shows this same page. */
|
|
12
|
-
readonly path?: AbsolutePath | undefined;
|
|
13
|
-
/** Set to `false` so `<RouteCache>` drops the page when you leave it, and the next visit shows a new page. Defaults to `true`. */
|
|
14
|
-
readonly cache?: boolean | undefined;
|
|
15
|
-
/** The page content. */
|
|
16
|
-
readonly children?: ReactNode;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Configure the current page for the surrounding `<Router>` (and `<RouteCache>`).
|
|
21
|
-
* - `path` says the page owns every path that matches a template. A navigation to a path the page owns keeps the same
|
|
22
|
-
* page mounted, so it keeps its scroll and state, and a `<ViewTransition>` around the page does not run an enter or
|
|
23
|
-
* exit. The page updates for the new URL. Use it for a page whose tabs each have their own path: `path="/dave/{tab}"`.
|
|
24
|
-
* - Put the real values in the template. `/{name}/{tab}` would make every person's profile one page.
|
|
25
|
-
* - `cache={false}` makes `<RouteCache>` drop the page when you leave it, so the next visit starts again with no old
|
|
26
|
-
* state. Use it for a form that makes or edits something, for example a "New challenge" page.
|
|
27
|
-
*
|
|
28
|
-
* @kind component
|
|
29
|
-
* @see https://shelving.cc/ui/RouteConfig
|
|
30
|
-
*/
|
|
31
|
-
export function RouteConfig({ path, cache, children }: RouteConfigProps): ReactNode {
|
|
32
|
-
const state = use(RouteContext);
|
|
33
|
-
if (state) {
|
|
34
|
-
_configure(state, path, cache);
|
|
35
|
-
if (state.entry) _configure(state.entry, path, cache);
|
|
36
|
-
}
|
|
37
|
-
return children;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Set the given settings on a page's route state. */
|
|
41
|
-
function _configure(state: RouteState, path: AbsolutePath | undefined, cache: boolean | undefined): void {
|
|
42
|
-
if (path !== undefined) state.path = path;
|
|
43
|
-
if (cache !== undefined) state.cache = cache;
|
|
44
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { AbsolutePath } from "../../util/path.js";
|
|
2
|
-
/**
|
|
3
|
-
* The route state of one page, shared by `<Router>`, `<RouteCache>` and `<RouteConfig>`.
|
|
4
|
-
* - `path` is the template of the paths the page owns, set by `<RouteConfig path>`.
|
|
5
|
-
* - `cache` is `false` when `<RouteCache>` drops the page as you leave it, set by `<RouteConfig cache>`.
|
|
6
|
-
* - `entry` is the page's `<RouteCache>` entry, so `<RouteConfig>` in a top-level page also tells the cache.
|
|
7
|
-
* - `router` marks a state made by `<Router>`, so a nested router does not pass the cache entry on.
|
|
8
|
-
*
|
|
9
|
-
* @see https://shelving.cc/ui/RouteState
|
|
10
|
-
*/
|
|
11
|
-
export interface RouteState {
|
|
12
|
-
path?: AbsolutePath | undefined;
|
|
13
|
-
cache?: boolean | undefined;
|
|
14
|
-
readonly entry?: RouteState | undefined;
|
|
15
|
-
readonly router?: true | undefined;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* React context holding the `RouteState` of the current page, provided by `<Router>` and `<RouteCache>`.
|
|
19
|
-
*
|
|
20
|
-
* @see https://shelving.cc/ui/RouteContext
|
|
21
|
-
*/
|
|
22
|
-
export declare const RouteContext: import("react").Context<RouteState | undefined>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createContext } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* React context holding the `RouteState` of the current page, provided by `<Router>` and `<RouteCache>`.
|
|
4
|
-
*
|
|
5
|
-
* @see https://shelving.cc/ui/RouteContext
|
|
6
|
-
*/
|
|
7
|
-
export const RouteContext = createContext(undefined);
|
|
8
|
-
RouteContext.displayName = "RouteContext";
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createContext } from "react";
|
|
2
|
-
import type { AbsolutePath } from "../../util/path.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The route state of one page, shared by `<Router>`, `<RouteCache>` and `<RouteConfig>`.
|
|
6
|
-
* - `path` is the template of the paths the page owns, set by `<RouteConfig path>`.
|
|
7
|
-
* - `cache` is `false` when `<RouteCache>` drops the page as you leave it, set by `<RouteConfig cache>`.
|
|
8
|
-
* - `entry` is the page's `<RouteCache>` entry, so `<RouteConfig>` in a top-level page also tells the cache.
|
|
9
|
-
* - `router` marks a state made by `<Router>`, so a nested router does not pass the cache entry on.
|
|
10
|
-
*
|
|
11
|
-
* @see https://shelving.cc/ui/RouteState
|
|
12
|
-
*/
|
|
13
|
-
export interface RouteState {
|
|
14
|
-
path?: AbsolutePath | undefined;
|
|
15
|
-
cache?: boolean | undefined;
|
|
16
|
-
readonly entry?: RouteState | undefined;
|
|
17
|
-
readonly router?: true | undefined;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* React context holding the `RouteState` of the current page, provided by `<Router>` and `<RouteCache>`.
|
|
22
|
-
*
|
|
23
|
-
* @see https://shelving.cc/ui/RouteContext
|
|
24
|
-
*/
|
|
25
|
-
export const RouteContext = createContext<RouteState | undefined>(undefined);
|
|
26
|
-
RouteContext.displayName = "RouteContext";
|