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
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# BackButton
|
|
2
|
+
|
|
3
|
+
- Kind: component
|
|
4
|
+
- Import: `import { BackButton } from "shelving/ui";`
|
|
5
|
+
|
|
6
|
+
Back button for the current stack.
|
|
7
|
+
- Goes back to the page before this one in the current stack, wherever you came from.
|
|
8
|
+
- Goes to `href` when the stack has no page before this one: the app was opened at this page, or the browser has no Navigation API.
|
|
9
|
+
- It is a plain link with `className="back"`, so it slides back, and it works in a server render and with a middle-click.
|
|
10
|
+
|
|
11
|
+
The back button for a page header. It goes back to the page before this one in the current stack, wherever you came from.
|
|
12
|
+
|
|
13
|
+
**Things to know:**
|
|
14
|
+
|
|
15
|
+
- It goes to the page before this one in the current stack. If you opened a post from a search, it goes back to the search.
|
|
16
|
+
- It goes to `href` when the stack has no page before this one: for example, when the app was opened at this page. So a back button always has somewhere to go. Set `href` to the page's natural parent. On an unstacked page (for example a deep link), it goes to `href` and stays unstacked. To go into a stack, the user taps a `<StackButton>`.
|
|
17
|
+
- It is a plain link with `className="back"`. `<Navigation>` turns a click into `NavigationStore.back()`, so the page slides back. A middle-click opens the link in a new browser tab.
|
|
18
|
+
- Its default content is a `<LeftIcon>` and its default `title` is "Back". Pass `children` and `title` to change them.
|
|
19
|
+
- It takes the usual `<Button>` props, except `onClick`.
|
|
20
|
+
- Without the browser Navigation API, and in a server render, it links to `href`.
|
|
21
|
+
- In a server-rendered app the server always renders `href`, and the browser may render the page before this one. React then warns about a hydration mismatch on the first render. A client-only app (with `<App>`) has no mismatch.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { BackButton } from "shelving/ui";
|
|
27
|
+
|
|
28
|
+
function PostPage({ id }: { id: string }) {
|
|
29
|
+
return (
|
|
30
|
+
<>
|
|
31
|
+
<header>
|
|
32
|
+
<BackButton href="/home"/>
|
|
33
|
+
<h1>Post</h1>
|
|
34
|
+
</header>
|
|
35
|
+
{/* … */}
|
|
36
|
+
</>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
With a label:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
<BackButton href="/profile">Back to profile</BackButton>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
To go back to one fixed page (not to the page before), use a link with `className="back"`:
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
<Button href="/profile" className="back">Profile</Button>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Styling
|
|
54
|
+
|
|
55
|
+
`<BackButton>` renders a `<Button>`, so it has the same styling hooks. See `<Button>`.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## Signatures
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
BackButton({ href, className, title = "Back", children = <LeftIcon />, ...props }: BackButtonProps): ReactElement
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Parameters
|
|
65
|
+
|
|
66
|
+
| Param | Type | Description |
|
|
67
|
+
| --- | --- | --- |
|
|
68
|
+
| `props` | `BackButtonProps` | |
|
|
69
|
+
| `.href` | `AbsolutePath` | Where to go back to when the current stack has no page before this one (for example, the app was opened at this page). Read only. |
|
|
70
|
+
|
|
71
|
+
## Returns
|
|
72
|
+
|
|
73
|
+
| Type | Description |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `ReactElement` | |
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# BackButtonProps
|
|
2
|
+
|
|
3
|
+
- Kind: interface
|
|
4
|
+
- Import: `import { BackButtonProps } from "shelving/ui";`
|
|
5
|
+
- Extends: `Omit<ButtonProps, "href" | "onClick">`
|
|
6
|
+
|
|
7
|
+
Props for `<BackButton>`: the `href` to go back to when the stack has no page before this one, plus the usual `Button` props except `onClick`.
|
|
8
|
+
|
|
9
|
+
## Signatures
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
{
|
|
13
|
+
readonly href: AbsolutePath;
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Properties
|
|
18
|
+
|
|
19
|
+
| Property | Type | Description |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| `href` | `AbsolutePath` | Where to go back to when the current stack has no page before this one (for example, the app was opened at this page). Read only. |
|
|
@@ -17,7 +17,6 @@ Props for a thing that can be clicked — either has a string `href` link or an
|
|
|
17
17
|
download?: string | undefined;
|
|
18
18
|
title?: string | undefined;
|
|
19
19
|
selected?: boolean | undefined;
|
|
20
|
-
back?: boolean | undefined;
|
|
21
20
|
}
|
|
22
21
|
```
|
|
23
22
|
|
|
@@ -32,4 +31,3 @@ Props for a thing that can be clicked — either has a string `href` link or an
|
|
|
32
31
|
| `download` | `string \| undefined` | If `href` is present then this is the suggested filename for downloading. Optional. |
|
|
33
32
|
| `title` | `string \| undefined` | Title shown on hover. Optional. |
|
|
34
33
|
| `selected` | `boolean \| undefined` | Whether this is the selected item in a group. Sets `aria-pressed` on a `<button>`, or `aria-current` on an `<a>`. Optional. |
|
|
35
|
-
| `back` | `boolean \| undefined` | If `href` is present, then `<Navigation>` opens the link with a back transition. Use it for a "back to" link. Sets `data-back` on the `<a>`. Optional. |
|
package/docs/ui/Head.md
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
- Kind: component
|
|
4
4
|
- Import: `import { Head } from "shelving/ui";`
|
|
5
5
|
|
|
6
|
-
Emit the current page's head metadata and
|
|
6
|
+
Emit the current page's head metadata, and replace the browser URL with the page's canonical URL.
|
|
7
7
|
- Emits hoistable head elements (title, meta, links, stylesheets, scripts) inline; React 19 hoists each one into the document `<head>`.
|
|
8
8
|
- Does not render `<base>` (not hoistable — that lives in `<Head>` in the `<HTML>` shell component).
|
|
9
|
-
-
|
|
9
|
+
- When the meta `url` differs from the browser URL (a page that knows its canonical URL), calls `NavigationStore.replace()` with it. Outside `<Navigation>` it does not touch history.
|
|
10
10
|
|
|
11
11
|
Low-level emitter of hoistable head metadata from the current `Meta` context. It outputs `<title>`, `<meta>`, `<link>`, stylesheet, module, and script elements inline, and React 19 hoists each one into the document `<head>`. It also syncs `window.history` to the page URL.
|
|
12
12
|
|
|
@@ -10,7 +10,7 @@ A direction-aware `<Transition>` preset that slides its children horizontally
|
|
|
10
10
|
**Things to know:**
|
|
11
11
|
|
|
12
12
|
- Slides right by default and when the type is `"forward"`; slides left when the type is `"back"`.
|
|
13
|
-
- Inside `<Navigation>` the direction is automatic: a link click
|
|
13
|
+
- Inside `<Navigation>` the direction is automatic: a link click or `NavigationStore.forward()` sets the `"forward"` type, and a `className="back"` link or `NavigationStore.back()` sets `"back"`. The browser back and forward buttons set the type from the page's place in its stack. `NavigationStore.replace()` has no transition. Outside `<Navigation>`, set the direction with `setTransitionType("forward" | "back")` inside a `startTransition()` callback — see `<Transition>`.
|
|
14
14
|
- Pass `overlay` to raise the transition group above surrounding content during the animation (`z-index: 100`).
|
|
15
15
|
- The old and new content slide a full width apart, so they sit edge to edge and never overlap.
|
|
16
16
|
- The slide is clipped to the element's own box (`overflow: clip` on the group), so it does not paint over the content around it.
|
package/docs/ui/LinkClickable.md
CHANGED
package/docs/ui/Meta.md
CHANGED
|
@@ -11,6 +11,7 @@ Combined meta data for a website page — title, URLs, description, CSP, tags, l
|
|
|
11
11
|
{
|
|
12
12
|
readonly root?: ImmutableURL | undefined;
|
|
13
13
|
readonly url?: ImmutableURL | undefined;
|
|
14
|
+
readonly stack?: AbsolutePath | undefined;
|
|
14
15
|
readonly app?: string | undefined;
|
|
15
16
|
readonly title?: string | undefined;
|
|
16
17
|
readonly description?: string | undefined;
|
|
@@ -30,7 +31,8 @@ Combined meta data for a website page — title, URLs, description, CSP, tags, l
|
|
|
30
31
|
| Property | Type | Description |
|
|
31
32
|
| --- | --- | --- |
|
|
32
33
|
| `root` | `ImmutableURL \| undefined` | Base URL for the app (used to resolve `url` and set as `<base>` tag in `<Head>`). Read only. Optional. |
|
|
33
|
-
| `url` | `ImmutableURL \| undefined` | URL of the current page (used
|
|
34
|
+
| `url` | `ImmutableURL \| undefined` | URL of the current page (used as the initial URL for routing, and as the page's canonical URL in `<Head>`). Read only. Optional. |
|
|
35
|
+
| `stack` | `AbsolutePath \| undefined` | 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. Read only. Optional. |
|
|
34
36
|
| `app` | `string \| undefined` | Title of the entire application. Read only. Optional. |
|
|
35
37
|
| `title` | `string \| undefined` | Title of the current page (set as `<title>` in `<Head>` Read only. Optional. |
|
|
36
38
|
| `description` | `string \| undefined` | Description of the current page. Read only. Optional. |
|
package/docs/ui/Navigation.md
CHANGED
|
@@ -3,78 +3,132 @@
|
|
|
3
3
|
- Kind: component
|
|
4
4
|
- Import: `import { Navigation } from "shelving/ui";`
|
|
5
5
|
|
|
6
|
-
Top-level navigation provider.
|
|
7
|
-
- Owns a single `NavigationStore`
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
- Publishes
|
|
11
|
-
-
|
|
12
|
-
- Skips the transition when the browser already animated the change (`PopStateEvent.hasUAVisualTransition`, e.g. a swipe-back gesture).
|
|
6
|
+
Top-level navigation provider, with one stack of pages for each tab.
|
|
7
|
+
- Owns a single `NavigationStore` made from the surrounding `<Meta>` url and root.
|
|
8
|
+
- Turns clicks on same-origin links into `NavigationStore.forward()`, or `NavigationStore.back()` for a link with `className="back"`, or `NavigationStore.replace()` for a link with `className="replace"`. Clicks with a modifier key, or on links with `download` or a `target`, are left to the browser.
|
|
9
|
+
- Publishes the URL and the current `stack` into `Meta`, and the position in the stacks into `NavigationPositionContext`, all in one render.
|
|
10
|
+
- Publishes each change inside `startTransition()` with a `"forward"` or `"back"` transition type, so a `<Transition>` around the routes runs a view transition. A replace, or a change the browser already animated (for example a swipe-back), has no transition.
|
|
11
|
+
- Uses the browser Navigation API. Without it (older browsers, server renders) there are no stacks and no transitions.
|
|
13
12
|
|
|
14
|
-
Exactly one `<Navigation>` per app
|
|
13
|
+
Exactly one `<Navigation>` per app. Nested routers share its store.
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
The top-level navigation provider for a client-side app. It owns one `NavigationStore`, turns link clicks into navigation, and publishes the live URL into `<Meta>`, so each `<Router>` re-renders when the URL changes. Use exactly one `<Navigation>` per app. Nested routers all share its store.
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
Give it `stacks` for an app with a tab bar. Each stack is one tab with its own history of pages, like a phone app: each tab remembers where you left it, and a back button goes back within its tab.
|
|
19
18
|
|
|
20
19
|
**Things to know:**
|
|
21
20
|
|
|
22
|
-
- Same-origin
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
- The
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
21
|
+
- Same-origin link clicks become `NavigationStore.forward()`, so the page slides forward.
|
|
22
|
+
- A link with `className="back"` calls `NavigationStore.back()`, so the page slides back. `<BackButton>` sets this class for you.
|
|
23
|
+
- A link with `className="replace"` calls `NavigationStore.replace()`. It changes the URL with no new history entry and no slide, and keeps the same page mounted. Use it for tabs inside a page.
|
|
24
|
+
- Clicks with a modifier key (Cmd, Ctrl, Shift, Alt), a middle-click, and links with `download` or a `target` other than `_self` go to the browser as usual.
|
|
25
|
+
- It publishes each page change inside `startTransition()` with a `"forward"` or `"back"` transition type, so a `<Transition>` such as `<HorizontalTransition>` slides the page. A replace has no transition.
|
|
26
|
+
- The browser back and forward buttons slide too. Inside a stack the direction comes from the depth of the page. Across stacks it comes from tab order.
|
|
27
|
+
- When the browser already animated the change (for example a swipe-back on a phone), there is no view transition, so the page does not slide twice.
|
|
28
|
+
- It publishes `stack` (the root of the current stack) into `<Meta>` beside `url`, so any component can read the current tab with `requireMeta().stack`. With no `stacks`, the app has one stack, and `stack` is `"/"`.
|
|
29
|
+
- It reads the start URL and root from the surrounding `<Meta>`, so set `url` and `root` on an ancestor `<App>` or `<HTML>`. In the browser the URL falls back to `window.location.href`.
|
|
30
|
+
- `<Router>` works with no `<Navigation>` (server renders, static renders, tests). `<Navigation>` only makes the URL live on the client.
|
|
31
|
+
|
|
32
|
+
### Browser support
|
|
33
|
+
|
|
34
|
+
Stacks and slides use the browser [Navigation API](https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API). Without it (older browsers, a server render, or a sandboxed frame), `<Navigation>` falls back to plain navigation:
|
|
35
|
+
|
|
36
|
+
- Links still go through the app with no page reload, and the browser back button works.
|
|
37
|
+
- There are no stacks, no slides and no `<RouteCache>`. Each page mounts fresh.
|
|
38
|
+
- `<StackButton>` is a plain link to its stack's root. `<BackButton>` is a plain link to its `href`.
|
|
31
39
|
|
|
32
40
|
## Usage
|
|
33
41
|
|
|
42
|
+
### Basic setup
|
|
43
|
+
|
|
34
44
|
```tsx
|
|
35
|
-
import {
|
|
45
|
+
import { App, Navigation, Router } from "shelving/ui";
|
|
36
46
|
|
|
37
|
-
<
|
|
47
|
+
<App root="https://example.com/">
|
|
38
48
|
<Navigation>
|
|
39
49
|
<Router routes={ROUTES}/>
|
|
40
50
|
</Navigation>
|
|
41
|
-
</
|
|
51
|
+
</App>
|
|
42
52
|
```
|
|
43
53
|
|
|
44
|
-
###
|
|
54
|
+
### App with a tab bar
|
|
55
|
+
|
|
56
|
+
List the root path of each stack in tab order. Put a `<StackButton>` for each stack in the tab bar.
|
|
45
57
|
|
|
46
58
|
```tsx
|
|
47
|
-
import { HorizontalTransition, Navigation, Router } from "shelving/ui";
|
|
59
|
+
import { App, HorizontalTransition, Navigation, RouteCache, Router, StackButton } from "shelving/ui";
|
|
60
|
+
|
|
61
|
+
const STACKS = ["/home", "/discover", "/profile"] as const;
|
|
62
|
+
|
|
63
|
+
<App root="https://example.com/">
|
|
64
|
+
<Navigation stacks={STACKS}>
|
|
65
|
+
<HorizontalTransition>
|
|
66
|
+
<RouteCache>
|
|
67
|
+
<Router routes={ROUTES}/>
|
|
68
|
+
</RouteCache>
|
|
69
|
+
</HorizontalTransition>
|
|
70
|
+
<nav className="tab-bar">
|
|
71
|
+
<StackButton stack="/home">Home</StackButton>
|
|
72
|
+
<StackButton stack="/discover">Discover</StackButton>
|
|
73
|
+
<StackButton stack="/profile">Profile</StackButton>
|
|
74
|
+
</nav>
|
|
75
|
+
</Navigation>
|
|
76
|
+
</App>
|
|
77
|
+
```
|
|
48
78
|
|
|
49
|
-
|
|
50
|
-
<Navigation>
|
|
51
|
-
<HorizontalTransition>
|
|
52
|
-
<Router routes={ROUTES}/>
|
|
53
|
-
</HorizontalTransition>
|
|
54
|
-
</Navigation>
|
|
79
|
+
To select a tab when the app starts, pass the starting `stack`. The app decides which stack the opening URL belongs to, for example:
|
|
55
80
|
|
|
56
|
-
|
|
57
|
-
|
|
81
|
+
```tsx
|
|
82
|
+
const path = window.location.pathname;
|
|
83
|
+
const stack = STACKS.find(s => path === s || path.startsWith(`${s}/`));
|
|
84
|
+
|
|
85
|
+
<Navigation stacks={STACKS} stack={stack}>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Put the transition **outside** `<RouteCache>`, around the whole cache. Safari (iOS 18) loses the exit animation when each page has its own `<ViewTransition>`.
|
|
89
|
+
|
|
90
|
+
The app opens in the `stack` you set on `<Navigation>` (or on the surrounding `<Meta>`, like `url` and `root`), else in the `/` stack. A page in the `/` stack, such as a deep link or a login page, is **unstacked**: no tab is selected, and links from it stay unstacked until you tap a tab or name a stack (for example `nav.replace("/home", "/home")` after a login). See `NavigationStore`.
|
|
91
|
+
|
|
92
|
+
Each link pushes a new page onto the current stack, wherever it points. So a link from `/home` to `/profile/settings` opens the settings page in the Home tab, and the Profile tab stays where it was. Tap a `<StackButton>` to change tab.
|
|
93
|
+
|
|
94
|
+
### Links
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
// Opens a new page in the current stack. Slides forward.
|
|
98
|
+
<Button href="/home/post/1">Open post</Button>
|
|
99
|
+
|
|
100
|
+
// Goes back to a page. Slides back.
|
|
101
|
+
// If the page is already in the stack, the stack goes back to it.
|
|
102
|
+
<Button href="/home" className="back">Back to home</Button>
|
|
103
|
+
|
|
104
|
+
// The back button for a page header. Goes to the page before this one in the stack, or to `href`.
|
|
105
|
+
<BackButton href="/home"/>
|
|
106
|
+
|
|
107
|
+
// Changes the URL but keeps the same page. No slide, no new history entry.
|
|
108
|
+
<Button href="/profile/posts" className="replace">Posts</Button>
|
|
109
|
+
<Button href="/profile/likes" className="replace">Likes</Button>
|
|
58
110
|
```
|
|
59
111
|
|
|
60
112
|
### Imperative navigation
|
|
61
113
|
|
|
62
|
-
Read the
|
|
114
|
+
Read the store from anywhere in the tree with `requireNavigation()`:
|
|
63
115
|
|
|
64
116
|
```tsx
|
|
65
117
|
import { requireNavigation } from "shelving/ui";
|
|
66
118
|
|
|
67
119
|
const nav = requireNavigation();
|
|
68
|
-
nav.forward("/
|
|
69
|
-
nav.
|
|
70
|
-
nav.
|
|
120
|
+
nav.forward("/home/post/1"); // Open a page in the current stack.
|
|
121
|
+
nav.back("/home"); // Go back to a page.
|
|
122
|
+
nav.replace("/login"); // Change the URL of the current page.
|
|
71
123
|
```
|
|
72
124
|
|
|
125
|
+
See `NavigationStore` for what each method does.
|
|
126
|
+
|
|
73
127
|
|
|
74
128
|
## Signatures
|
|
75
129
|
|
|
76
130
|
```ts
|
|
77
|
-
Navigation({ children, ...meta }: NavigationProps): ReactElement
|
|
131
|
+
Navigation({ children, stacks = [], ...meta }: NavigationProps): ReactElement
|
|
78
132
|
```
|
|
79
133
|
|
|
80
134
|
## Parameters
|
|
@@ -82,6 +136,8 @@ Navigation({ children, ...meta }: NavigationProps): ReactElement
|
|
|
82
136
|
| Param | Type | Description |
|
|
83
137
|
| --- | --- | --- |
|
|
84
138
|
| `meta` | `NavigationProps` | |
|
|
139
|
+
| `.stacks` | `readonly AbsolutePath[] \| undefined` | Root path of each stack, in tab order, for an app with a tab bar (for example `["/home", "/discover", "/profile"]`). - Each stack keeps its own pages, so each tab remembers where you left it, and a back button goes back within its tab. - With no stacks, the app has one stack at `"/"`, and `stack` in `Meta` is `"/"`. Read only. Optional. |
|
|
140
|
+
| `.stack` | `AbsolutePath \| undefined` | Stack of the page the app opens at (for example `"/home"`), like `url` and `root`. - Read from this prop, else from the surrounding `<Meta>`, else `"/"`. - Used only when the opening history entry has no saved stack. A reload keeps the stack it had. Read only. Optional. |
|
|
85
141
|
|
|
86
142
|
## Returns
|
|
87
143
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# NavigationEntryState
|
|
2
|
+
|
|
3
|
+
- Kind: interface
|
|
4
|
+
- Import: `import { NavigationEntryState } from "shelving/ui";`
|
|
5
|
+
|
|
6
|
+
State that `NavigationStore` saves on each browser history entry.
|
|
7
|
+
|
|
8
|
+
## Signatures
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
{
|
|
12
|
+
readonly stack: AbsolutePath;
|
|
13
|
+
readonly depth: number;
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Properties
|
|
18
|
+
|
|
19
|
+
| Property | Type | Description |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| `stack` | `AbsolutePath` | Root path of the stack this page is in. Read only. |
|
|
22
|
+
| `depth` | `number` | Position of this page in its stack, where `0` is the root. Read only. |
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# NavigationPosition
|
|
2
|
+
|
|
3
|
+
- Kind: interface
|
|
4
|
+
- Import: `import { NavigationPosition } from "shelving/ui";`
|
|
5
|
+
- Extends: `NavigationEntryState`
|
|
6
|
+
|
|
7
|
+
Where the app is now in its stacks: the current stack and depth, the top depth of each stack, and the page before the current one.
|
|
8
|
+
- `undefined` when the browser has no Navigation API, or during a server render.
|
|
9
|
+
|
|
10
|
+
## Signatures
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
{
|
|
14
|
+
readonly tops: { readonly [stack: AbsolutePath]: number };
|
|
15
|
+
readonly parent: AbsolutePath | undefined;
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Properties
|
|
20
|
+
|
|
21
|
+
| Property | Type | Description |
|
|
22
|
+
| --- | --- | --- |
|
|
23
|
+
| `tops` | `{ readonly [stack: AbsolutePath]: number }` | Depth of the top page of each stack that has pages. Read only. |
|
|
24
|
+
| `parent` | `AbsolutePath \| undefined` | The page before the current one in its stack, or `undefined` at the bottom of the stack. Read only. |
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# NavigationPositionContext
|
|
2
|
+
|
|
3
|
+
- Kind: constant
|
|
4
|
+
- Import: `import { NavigationPositionContext } from "shelving/ui";`
|
|
5
|
+
|
|
6
|
+
React context holding where the app is in its stacks, published by `<Navigation>` with each URL change.
|
|
7
|
+
- `undefined` without the browser Navigation API, during a server render, or outside `<Navigation>`.
|
|
8
|
+
- `<RouteCache>`, `<Router>` and `<BackButton>` read it, so they change in the same render as the URL.
|
|
@@ -4,10 +4,20 @@
|
|
|
4
4
|
- Import: `import { NavigationProps } from "shelving/ui";`
|
|
5
5
|
- Extends: `PossibleMeta`
|
|
6
6
|
|
|
7
|
-
Props for `<Navigation
|
|
7
|
+
Props for `<Navigation>`: the initial `Meta` (url, root and stack), the `stacks`, and optional `children`.
|
|
8
8
|
|
|
9
9
|
## Signatures
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
|
-
{
|
|
12
|
+
{
|
|
13
|
+
readonly stacks?: readonly AbsolutePath[] | undefined;
|
|
14
|
+
readonly stack?: AbsolutePath | undefined;
|
|
15
|
+
}
|
|
13
16
|
```
|
|
17
|
+
|
|
18
|
+
## Properties
|
|
19
|
+
|
|
20
|
+
| Property | Type | Description |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| `stacks` | `readonly AbsolutePath[] \| undefined` | Root path of each stack, in tab order, for an app with a tab bar (for example `["/home", "/discover", "/profile"]`). - Each stack keeps its own pages, so each tab remembers where you left it, and a back button goes back within its tab. - With no stacks, the app has one stack at `"/"`, and `stack` in `Meta` is `"/"`. Read only. Optional. |
|
|
23
|
+
| `stack` | `AbsolutePath \| undefined` | Stack of the page the app opens at (for example `"/home"`), like `url` and `root`. - Read from this prop, else from the surrounding `<Meta>`, else `"/"`. - Used only when the opening history entry has no saved stack. A reload keeps the stack it had. Read only. Optional. |
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
- Kind: method
|
|
4
4
|
- Member of: `NavigationStore`
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
6
|
+
Go back to a URL, as a back button does.
|
|
7
|
+
- The URL is an earlier page in `stack`: go back to it. When it is the entry just before the current one, this goes back in the browser history. Else it pushes the URL again at that page's depth.
|
|
8
|
+
- The URL is the root of `stack`: push it at depth 0.
|
|
9
|
+
- Else push the URL in place of the top page of `stack`.
|
|
10
|
+
- It works when the app was opened at the current page, so a back button always has somewhere to go.
|
|
9
11
|
|
|
10
12
|
## Signatures
|
|
11
13
|
|
|
12
14
|
```ts
|
|
13
|
-
back(possible: PossibleURL): void
|
|
15
|
+
back(possible: PossibleURL, stack: AbsolutePath = this.stack.value): void
|
|
14
16
|
```
|
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
- Kind: method
|
|
4
4
|
- Member of: `NavigationStore`
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Go forward to a URL, as a link does.
|
|
7
|
+
- The URL is the top page of `stack`: switch to that stack, at the same depth. This is a tab switch.
|
|
8
|
+
- Else push the URL onto `stack`, one level deeper than its top page.
|
|
9
|
+
- The URL you are already on: replace it instead.
|
|
10
|
+
- A change of stack slides by tab order. Else it slides forward.
|
|
7
11
|
|
|
8
12
|
## Signatures
|
|
9
13
|
|
|
10
14
|
```ts
|
|
11
|
-
forward(possible: PossibleURL): void
|
|
15
|
+
forward(possible: PossibleURL, stack: AbsolutePath = this.stack.value): void
|
|
12
16
|
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# NavigationStore.history()
|
|
2
|
+
|
|
3
|
+
- Kind: method
|
|
4
|
+
- Member of: `NavigationStore`
|
|
5
|
+
|
|
6
|
+
Get the pages in a stack, root first, or every page in every stack.
|
|
7
|
+
- Read from the browser history entries up to the current one.
|
|
8
|
+
- A stack whose root entry is gone (the browser keeps a limited history) still starts with its root.
|
|
9
|
+
- Without the Navigation API this is always empty.
|
|
10
|
+
|
|
11
|
+
## Signatures
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
history(stack: AbsolutePath = this.stack.value): AbsolutePath[]
|
|
15
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# NavigationStore.listen()
|
|
2
|
+
|
|
3
|
+
- Kind: method
|
|
4
|
+
- Member of: `NavigationStore`
|
|
5
|
+
|
|
6
|
+
Start listening to the browser (back, forward and swipe).
|
|
7
|
+
- Saves the current stack and depth on the current history entry, if it has none.
|
|
8
|
+
- `<Navigation>` calls it once, when it mounts.
|
|
9
|
+
|
|
10
|
+
## Signatures
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
listen(): () => void
|
|
14
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# NavigationStore.replace()
|
|
2
|
+
|
|
3
|
+
- Kind: method
|
|
4
|
+
- Member of: `NavigationStore`
|
|
5
|
+
|
|
6
|
+
Replace the current URL, with no transition.
|
|
7
|
+
- The page stays in the same stack, at the same depth, so a cached page stays mounted.
|
|
8
|
+
- Use it for a page that knows its canonical URL, or for in-page tabs.
|
|
9
|
+
- Pass a `stack` to move the page into that stack: at its root if the URL is the root, else on top of its pages. For example, a login page calls `replace("/home", "/home")`.
|
|
10
|
+
|
|
11
|
+
## Signatures
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
replace(possible: PossibleURL, stack: AbsolutePath = this.stack.value): void
|
|
15
|
+
```
|