shelving 1.319.1 → 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.
Files changed (106) hide show
  1. package/docs/guides/building-with-shelving.md +26 -0
  2. package/docs/llms-full.txt +752 -265
  3. package/docs/ui/BackButton.md +75 -0
  4. package/docs/ui/BackButtonProps.md +21 -0
  5. package/docs/ui/ClickableProps.md +0 -2
  6. package/docs/ui/FADE_TRANSITION_CLASS.md +9 -0
  7. package/docs/ui/FadeTransition.md +13 -0
  8. package/docs/ui/Head.md +2 -2
  9. package/docs/ui/HorizontalTransition.md +21 -5
  10. package/docs/ui/LinkClickable.md +0 -1
  11. package/docs/ui/Meta.md +3 -1
  12. package/docs/ui/Navigation.md +93 -37
  13. package/docs/ui/NavigationEntryState.md +22 -0
  14. package/docs/ui/NavigationPosition.md +24 -0
  15. package/docs/ui/NavigationPositionContext.md +8 -0
  16. package/docs/ui/NavigationProps.md +12 -2
  17. package/docs/ui/NavigationStore/back.md +6 -4
  18. package/docs/ui/NavigationStore/forward.md +6 -2
  19. package/docs/ui/NavigationStore/history.md +15 -0
  20. package/docs/ui/NavigationStore/listen.md +14 -0
  21. package/docs/ui/NavigationStore/replace.md +15 -0
  22. package/docs/ui/NavigationStore.md +100 -19
  23. package/docs/ui/RouteCache.md +72 -36
  24. package/docs/ui/RouteCacheProps.md +3 -3
  25. package/docs/ui/Router.md +4 -2
  26. package/docs/ui/SLIDE_DOWN_TRANSITION_CLASS.md +9 -0
  27. package/docs/ui/SLIDE_LEFT_TRANSITION_CLASS.md +9 -0
  28. package/docs/ui/SLIDE_RIGHT_TRANSITION_CLASS.md +9 -0
  29. package/docs/ui/SLIDE_UP_TRANSITION_CLASS.md +9 -0
  30. package/docs/ui/StackButton.md +64 -0
  31. package/docs/ui/StackButtonProps.md +21 -0
  32. package/docs/ui/VerticalTransition.md +21 -5
  33. package/docs/ui/mergeMeta.md +2 -1
  34. package/docs/ui.md +18 -10
  35. package/package.json +1 -1
  36. package/ui/button/Clickable.d.ts +1 -3
  37. package/ui/button/Clickable.js +2 -2
  38. package/ui/button/Clickable.tsx +0 -4
  39. package/ui/dialog/Dialog.d.ts +0 -1
  40. package/ui/dialog/Dialog.js +2 -2
  41. package/ui/dialog/Dialog.tsx +2 -2
  42. package/ui/notice/NoticesTransition.module.css +1 -1
  43. package/ui/page/Head.d.ts +2 -2
  44. package/ui/page/Head.js +9 -8
  45. package/ui/page/Head.tsx +8 -6
  46. package/ui/router/BackButton.d.ts +22 -0
  47. package/ui/router/BackButton.js +19 -0
  48. package/ui/router/BackButton.md +47 -0
  49. package/ui/router/BackButton.tsx +34 -0
  50. package/ui/router/Navigation.d.ts +22 -12
  51. package/ui/router/Navigation.js +67 -51
  52. package/ui/router/Navigation.md +84 -27
  53. package/ui/router/Navigation.test.tsx +27 -7
  54. package/ui/router/Navigation.tsx +90 -53
  55. package/ui/router/NavigationContext.d.ts +9 -1
  56. package/ui/router/NavigationContext.js +9 -0
  57. package/ui/router/NavigationContext.tsx +11 -1
  58. package/ui/router/NavigationStore.d.ts +126 -19
  59. package/ui/router/NavigationStore.js +301 -30
  60. package/ui/router/NavigationStore.md +82 -9
  61. package/ui/router/NavigationStore.test.ts +384 -0
  62. package/ui/router/NavigationStore.tsx +347 -30
  63. package/ui/router/RouteCache.d.ts +15 -22
  64. package/ui/router/RouteCache.js +36 -47
  65. package/ui/router/RouteCache.md +59 -16
  66. package/ui/router/RouteCache.tsx +55 -62
  67. package/ui/router/Router.d.ts +2 -1
  68. package/ui/router/Router.js +9 -14
  69. package/ui/router/Router.md +2 -1
  70. package/ui/router/Router.tsx +9 -20
  71. package/ui/router/StackButton.d.ts +24 -0
  72. package/ui/router/StackButton.js +35 -0
  73. package/ui/router/StackButton.md +34 -0
  74. package/ui/router/StackButton.tsx +44 -0
  75. package/ui/router/index.d.ts +2 -2
  76. package/ui/router/index.js +2 -2
  77. package/ui/router/index.ts +2 -2
  78. package/ui/transition/FadeTransition.d.ts +9 -1
  79. package/ui/transition/FadeTransition.js +12 -2
  80. package/ui/transition/FadeTransition.md +13 -0
  81. package/ui/transition/{FadeTransition.css → FadeTransition.module.css} +9 -2
  82. package/ui/transition/FadeTransition.tsx +13 -2
  83. package/ui/transition/HorizontalTransition.d.ts +18 -1
  84. package/ui/transition/HorizontalTransition.js +21 -2
  85. package/ui/transition/HorizontalTransition.md +21 -5
  86. package/ui/transition/{HorizontalTransition.css → HorizontalTransition.module.css} +17 -5
  87. package/ui/transition/HorizontalTransition.tsx +30 -2
  88. package/ui/transition/VerticalTransition.d.ts +18 -1
  89. package/ui/transition/VerticalTransition.js +21 -2
  90. package/ui/transition/VerticalTransition.md +21 -5
  91. package/ui/transition/{VerticalTransition.css → VerticalTransition.module.css} +17 -5
  92. package/ui/transition/VerticalTransition.tsx +25 -2
  93. package/ui/util/meta.d.ts +4 -1
  94. package/ui/util/meta.ts +4 -1
  95. package/docs/ui/NavigationStore/redirect.md +0 -12
  96. package/docs/ui/RouteConfig.md +0 -75
  97. package/docs/ui/RouteConfigProps.md +0 -24
  98. package/docs/ui/RouteContext.md +0 -6
  99. package/docs/ui/RouteState.md +0 -30
  100. package/ui/router/RouteConfig.d.ts +0 -28
  101. package/ui/router/RouteConfig.js +0 -30
  102. package/ui/router/RouteConfig.md +0 -42
  103. package/ui/router/RouteConfig.tsx +0 -44
  104. package/ui/router/RouteContext.d.ts +0 -22
  105. package/ui/router/RouteContext.js +0 -8
  106. 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. |
@@ -0,0 +1,9 @@
1
+ # FADE_TRANSITION_CLASS
2
+
3
+ - Kind: constant
4
+ - Import: `import { FADE_TRANSITION_CLASS } from "shelving/ui";`
5
+
6
+ View transition class that fades content in and out.
7
+
8
+ - Pass it to React's `<ViewTransition>` (for example `enter` or `exit`) to use this animation without the component.
9
+ - Also adds the plain global `fade` class, so app CSS can target it with `::view-transition-group(.fade)`.
@@ -27,6 +27,19 @@ function Panel({ visible }: { visible: boolean }) {
27
27
  }
28
28
  ```
29
29
 
30
+ ## Use the class without the component
31
+
32
+ The CSS is a CSS module, so its class names are hashed. To use the same animation on your own `<ViewTransition>`, import `FADE_TRANSITION_CLASS`. Each one also holds a plain global class name, so your CSS can still target it.
33
+
34
+ ```tsx
35
+ import { ViewTransition } from "react";
36
+ import { FADE_TRANSITION_CLASS } from "shelving/ui";
37
+
38
+ <ViewTransition enter={FADE_TRANSITION_CLASS} exit={FADE_TRANSITION_CLASS}>
39
+ <div className="panel">…</div>
40
+ </ViewTransition>
41
+ ```
42
+
30
43
  ## Styling
31
44
 
32
45
  | Variable | Styles | Default |
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 sync browser history to its URL.
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
- - Updates `window.history` to match the page URL.
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,16 +10,19 @@ 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, `NavigationStore.forward()` or `NavigationStore.redirect()` sets the `"forward"` type, and the browser back or forward button sets `"back"`. Outside `<Navigation>`, set the direction with `setTransitionType("forward" | "back")` inside a `startTransition()` callback — see `<Transition>`.
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.
17
- - During the slide, the snapshots paint above fixed elements such as a bottom bar. To keep a fixed element on top, give it its own `view-transition-name` and put the slide groups below it:
17
+ - During the slide, the snapshots paint above fixed elements such as a bottom bar. To keep a fixed element on top, give it its own `view-transition-name` and raise its group:
18
18
 
19
19
  ```css
20
- ::view-transition-group(.slide-right),
21
- ::view-transition-group(.slide-left) {
22
- z-index: -1;
20
+ .bottom-bar {
21
+ view-transition-name: bottom-bar;
22
+ }
23
+
24
+ ::view-transition-group(bottom-bar) {
25
+ z-index: 1;
23
26
  }
24
27
  ```
25
28
 
@@ -38,6 +41,19 @@ import { HorizontalTransition, Navigation, Router } from "shelving/ui";
38
41
  </Navigation>
39
42
  ```
40
43
 
44
+ ## Use the class without the component
45
+
46
+ The CSS is a CSS module, so its class names are hashed. To use the same animation on your own `<ViewTransition>`, import `SLIDE_RIGHT_TRANSITION_CLASS` and `SLIDE_LEFT_TRANSITION_CLASS`. Each one also holds a plain global class name, so your CSS can still target it.
47
+
48
+ ```tsx
49
+ import { ViewTransition } from "react";
50
+ import { SLIDE_RIGHT_TRANSITION_CLASS } from "shelving/ui";
51
+
52
+ <ViewTransition enter={SLIDE_RIGHT_TRANSITION_CLASS} exit={SLIDE_RIGHT_TRANSITION_CLASS}>
53
+ <div className="panel">…</div>
54
+ </ViewTransition>
55
+ ```
56
+
41
57
  ## Styling
42
58
 
43
59
  | Variable | Styles | Default |
@@ -17,7 +17,6 @@ LinkClickable({
17
17
  download,
18
18
  title,
19
19
  selected,
20
- back,
21
20
  children = "Go",
22
21
  className,
23
22
  }: StylableClickableProps): ReactElement
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 to update history API and as the initial URL for routing). Read only. Optional. |
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. |
@@ -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` initialised from the surrounding `<Meta>` url/base.
8
- - Intercepts same-origin anchor clicks (excluding `download` anchors) and turns them into `forward()` calls, or `back()` calls for an anchor with a `data-back` attribute.
9
- - Listens for `popstate` to sync the store with browser back/forward.
10
- - Publishes the live URL into the `Meta` context via `mergeMeta()`, so descendant `<Router>`s re-render on navigation and merge invariants hold (e.g. `root` defaults to the live URL's origin when unset).
11
- - Publishes each URL change inside `startTransition()` with a `"forward"` or `"back"` transition type, so a `<Transition>` around the routes runs a view transition.
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 — nested routers share this single store.
13
+ Exactly one `<Navigation>` per app. Nested routers share its store.
15
14
 
16
- TODO: switch click/popstate handling to the browser Navigation API when broadly supported.
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
- The top-level navigation provider for a client-side app. It owns a single `NavigationStore`, publishes the live URL into the `<Meta>` context so descendant `<Router>`s re-render on navigation, and wires up browser history. Use exactly one `<Navigation>` per app — nested routers all share its single store.
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 anchor clicks are intercepted automatically and turned into `forward()` calls. Add a `download` attribute to an anchor to opt out.
23
- - An anchor with a `data-back` attribute calls `back()` instead, so the page slides back. Set it with the `back` prop on `<Button>` or `<Link>`, e.g. on a "Back to profile" button.
24
- - It listens for `popstate` so the store stays in sync with browser back/forward.
25
- - It publishes each page change inside `startTransition()`, so a `<Transition>` around the routes animates it. A link click, `NavigationStore.forward()` or `NavigationStore.redirect()` sets the `"forward"` transition type. A `data-back` link click, `NavigationStore.back()`, and the browser back or forward button set `"back"` (`popstate` does not say which way it went).
26
- - When the browser already animated the change, for example a swipe-back gesture on a phone, there is no view transition, so the page does not slide twice. The browser says so with `hasUAVisualTransition` on the `popstate` event. Other browsers still slide.
27
- - The `popstate` update waits for the next task (`setTimeout()`). React renders a transition that starts inside `popstate` as a sync update with no view transition.
28
- - It initialises the store from the surrounding `<Meta>` url/base, so set those on an ancestor `<App>` / `<HTML>` / `<Page>`. In the browser the store falls back to `window.location.href` when no url is set.
29
- - The meta it publishes always has a `root` — when none is set anywhere, `root` defaults to the live URL's origin. Setting `root` explicitly on `<App>` / `<HTML>` is still strongly recommended, especially for apps served under a sub-path.
30
- - `<Router>` works with no `<Navigation>` at all (SSR, static rendering, tests) — `<Navigation>` is only what makes the URL *live* on the client.
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 { HTML, Navigation, Router } from "shelving/ui";
45
+ import { App, Navigation, Router } from "shelving/ui";
36
46
 
37
- <HTML url={initialUrl} root="https://example.com/">
47
+ <App root="https://example.com/">
38
48
  <Navigation>
39
49
  <Router routes={ROUTES}/>
40
50
  </Navigation>
41
- </HTML>
51
+ </App>
42
52
  ```
43
53
 
44
- ### Page transitions
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
- // Links slide right. Back links and the browser back button slide left.
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
- // A "back to" link slides left too.
57
- <Button href="/profile" back>Back to profile</Button>
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 navigation store from anywhere in the tree with `requireNavigation()` for imperative URL changes:
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("/users/123"); // push a new history entry
69
- nav.redirect("/login"); // replace the current history entry
70
- nav.back("/users"); // push a new history entry that slides back
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>` — initial `Meta` (url/base) plus optional `children`.
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
- Navigate back to a URL, pushing a new browser history entry with the `"back"` transition type.
7
- - Use it for a "back to" link, so the page slides back, not forward.
8
- - It does not go back in the browser history, so it also works when the page was opened directly.
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
- Navigate forward to a URL, pushing a new browser history entry.
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
+ ```