@k8ordo/router 0.1.0 → 1.1.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/README.md +18 -9
- package/dist/base.d.mts +16 -0
- package/dist/base.mjs +45 -0
- package/dist/boundary.d.mts +13 -9
- package/dist/boundary.mjs +19 -6
- package/dist/define-routes.d.mts +22 -17
- package/dist/define-routes.mjs +15 -2
- package/dist/index.d.mts +9 -7
- package/dist/index.mjs +6 -4
- package/dist/links.d.mts +42 -12
- package/dist/links.mjs +44 -10
- package/dist/location.d.mts +22 -6
- package/dist/location.mjs +29 -6
- package/dist/match.d.mts +13 -5
- package/dist/match.mjs +8 -3
- package/dist/navigation.d.mts +61 -19
- package/dist/navigation.mjs +107 -29
- package/dist/not-found.d.mts +11 -0
- package/dist/not-found.mjs +28 -0
- package/dist/paths.d.mts +35 -18
- package/dist/register.d.mts +83 -12
- package/dist/router.d.mts +14 -8
- package/dist/router.mjs +29 -14
- package/docs/GUIDE.md +300 -58
- package/docs/llms.txt +74 -18
- package/package.json +17 -14
package/docs/llms.txt
CHANGED
|
@@ -17,17 +17,23 @@ When installed via npm, these docs live under `node_modules/@k8ordo/router/docs/
|
|
|
17
17
|
wildcards, route groups, declaration order), mounting `<Router>` and
|
|
18
18
|
`<Outlet>`, links without a `<Link>` component, `useMatch` for active
|
|
19
19
|
sections, `Register` for checked patterns, what navigation guarantees
|
|
20
|
-
(`finished` after commit, scroll to top or fragment on a new page),
|
|
21
|
-
|
|
20
|
+
(`finished` after commit, scroll to top or fragment on a new page), how
|
|
21
|
+
a `<ViewTransition>` animates page changes by the router's transition
|
|
22
|
+
types, and how the framework reuses the navigation half (an application on
|
|
23
|
+
`@k8ordo/framework` imports that half from `@k8ordo/framework`, which
|
|
24
|
+
re-exports it, with this package installed as its peer).
|
|
22
25
|
|
|
23
26
|
## Entry point
|
|
24
27
|
|
|
25
28
|
- `@k8ordo/router` — `defineRoutes(record)` returns a table whose one operation
|
|
26
|
-
is `match(pathname)
|
|
29
|
+
is `match(pathname, accept?)` — a match `accept` declines is passed over and
|
|
30
|
+
the walk goes on to the next pattern, which is how the framework skips a
|
|
31
|
+
param a schema refused; `<Router routes>` mounts it on the Navigation API and
|
|
27
32
|
`<Outlet />` renders the rest of the matched stack; a branch's `error`
|
|
28
|
-
component (`{ error, reset }
|
|
29
|
-
layout's hole when what is below throws
|
|
30
|
-
|
|
33
|
+
component (props `ErrorProps`, `{ error, reset }`; type `ErrorComponent`)
|
|
34
|
+
renders in the layout's hole when what is below throws; the next
|
|
35
|
+
`NavigationGeneration` clears the failure without remounting what the
|
|
36
|
+
boundary wraps. `href(pattern, params?)`
|
|
31
37
|
and `navigateTo(pattern, params?, options?)` build and perform navigations
|
|
32
38
|
from the pattern **string** alone — no table import, so no cycle — with
|
|
33
39
|
params inferred from the literal and the pattern itself checked once
|
|
@@ -35,20 +41,70 @@ When installed via npm, these docs live under `node_modules/@k8ordo/router/docs/
|
|
|
35
41
|
typed params and throws if rendered under a different pattern; under the
|
|
36
42
|
framework `Register` also carries `params` — the type each pattern's
|
|
37
43
|
`paramsSchema` produces — so `href` takes a param as the page receives it
|
|
38
|
-
(`ParsedParams` / `ParsedParamsMap` / `ParamsSchemaFor`
|
|
39
|
-
generated code
|
|
40
|
-
is the untyped form.
|
|
41
|
-
`@k8ordo/state`'s `Register
|
|
44
|
+
(`ParsedParams` / `ParsedParamsMap` / `ParamsSchemaFor` / `ParamsOf` /
|
|
45
|
+
`ErrorComponent` are the types the generated code imports); `useRoute()`
|
|
46
|
+
is the untyped form.
|
|
47
|
+
`@k8ordo/state`'s `Register` takes the same `routes: typeof routes`;
|
|
48
|
+
`NavigablePath<typeof routes, Path>` is `Path` when a linkable pattern
|
|
49
|
+
matches it segment by segment (a `:param` takes one non-empty segment)
|
|
50
|
+
and `never` otherwise — a check of the path given, never a union of every
|
|
51
|
+
path, which a `/:locale` page would turn into `/${string}` — for any other
|
|
52
|
+
typed-path consumer. `usePathname()` reads the platform's
|
|
42
53
|
pathname — never the search — so it works with or without a table, which
|
|
43
54
|
makes it the location hook that also works under the framework;
|
|
44
|
-
`useMatch(pattern)` / `matchPath(pattern, pathname)`
|
|
45
|
-
pattern — or, with a trailing `/*`, anything strictly
|
|
46
|
-
showing, with its params, table-free, so a
|
|
47
|
-
open under the framework too
|
|
48
|
-
own
|
|
55
|
+
`useMatch(pattern, options?)` / `matchPath(pattern, pathname, options?)`
|
|
56
|
+
answer whether that pattern — or, with a trailing `/*`, anything strictly
|
|
57
|
+
below it — is the pathname showing, with its params, table-free, so a
|
|
58
|
+
sidebar can ask which section is open under the framework too, and
|
|
59
|
+
`{ inclusive: true }` on either counts a `/*` pattern's own index in;
|
|
60
|
+
`normalizePathname(pathname)` is the router's own trailing-slash rule;
|
|
61
|
+
under Vite's `base` (`import.meta.env.BASE_URL`, e.g. `/docs/`) `href` /
|
|
62
|
+
`navigateTo` put it in front of every link (so `href` returns a `string`
|
|
63
|
+
URL, not a table path) and `usePathname` / `<Router>` take it off, a URL
|
|
64
|
+
outside it being left to the browser — `withBase(pathname, base?)` /
|
|
65
|
+
`withoutBase(pathname, base?)` (`null` outside the base) are the two steps;
|
|
66
|
+
`usePendingPathname()` is where a page change in progress is going (`null`
|
|
67
|
+
when none is), for a pending indicator; a branch's `loading` component
|
|
68
|
+
shows while what is below it suspends (a `<Suspense>` inside its `error`
|
|
69
|
+
boundary); `bindParams(() => ({ locale }))` returns `{ href, navigateTo }` with those
|
|
70
|
+
params supplied by the source at each call (still overridable), for a
|
|
71
|
+
segment every link shares — a pattern that names a param still takes
|
|
72
|
+
`options` third, after an `undefined` params slot if the source supplies
|
|
73
|
+
them all. `PageProps<P>` / `LayoutProps<P>` type a framework route file's
|
|
74
|
+
props by its pattern (`PageProps`' `params` from the registered schemas,
|
|
75
|
+
`LayoutProps`' `params` always strings and its `P` only a pattern the table
|
|
76
|
+
has a page at; `request` when the generated `Register` says the mode has
|
|
77
|
+
one), and `RouteContext<P>` types a framework `route.ts` method export's
|
|
78
|
+
`{ request, params }`. `notFound()` says, from a framework page, that its pathname is not a
|
|
79
|
+
page after all — the framework answers with the nearest `not-found.tsx`
|
|
80
|
+
under a 404 — and `isNotFound(value)` recognises what it throws.
|
|
49
81
|
`<PathnameProvider pathname>` seeds it for a server render and hydration,
|
|
50
|
-
and is mounted by `<Router>` and by
|
|
51
|
-
application
|
|
82
|
+
and is mounted by `<Router>` and by the framework's runtime, never by an
|
|
83
|
+
application; `<BrowserPathname>` is the opposite seed — below it a server
|
|
84
|
+
render's `usePathname` (and `useMatch`) waits for the browser with
|
|
85
|
+
`use(browser())`, leaving the nearest `<Suspense>` to it — mounted by the
|
|
86
|
+
framework's runtime around a `fallback.tsx`, never by an application. Every page change renders in the background, outside any
|
|
87
|
+
pending async action (so awaiting `finished` inside one settles), tagged
|
|
88
|
+
`navigation` and `navigation-push` / `navigation-replace` /
|
|
89
|
+
`navigation-traverse` (`addTransitionType`), so a `<ViewTransition
|
|
90
|
+
update={{ navigation: 'auto', default: 'none' }}>` around the pages'
|
|
91
|
+
hole animates page changes and no other transition. `useInterceptedNavigation({claim, load, apply})` returns
|
|
52
92
|
`{ generation }` and is the
|
|
53
93
|
navigation primitive `<Router>` is built on, and the seam the framework
|
|
54
|
-
uses to render server-produced trees instead
|
|
94
|
+
uses to render server-produced trees instead; its host renders what
|
|
95
|
+
`apply` set through `useDeferredValue`; its optional `refresh(url)` says
|
|
96
|
+
whether a same-pathname navigation still has to load (the page showing reads
|
|
97
|
+
the search), which then loads in place — no scroll, focus reset or
|
|
98
|
+
transition types.
|
|
99
|
+
Exported types, by group — the table: `Routes` (`{ kind, record, match }`),
|
|
100
|
+
`RoutesRecord`, `RouteNode`, `RouteComponent`, `Match`, `ErrorComponent`,
|
|
101
|
+
`ErrorProps`; patterns: `PatternOf`, `NavigablePatternOf`, `NavigablePath`,
|
|
102
|
+
`MatchablePattern`; registration: `Register`, `RegisteredPattern`,
|
|
103
|
+
`RegisteredNavigablePattern`, `RegisteredParams` (what a link takes),
|
|
104
|
+
`RegisteredPageParams` (what a page receives), `PageProps`, `LayoutProps`;
|
|
105
|
+
paths and schemas: `ParamsOf`, `PathFor`, `ParamValue`,
|
|
106
|
+
`StandardSchemaLike`, `SchemaOutput`, `ParamsSchemaFor`, `ParsedParams`,
|
|
107
|
+
`ParsedParamsMap`; options and handlers: `NavigateToOptions`
|
|
108
|
+
(`{ history? }`), `MatchOptions` (`{ inclusive? }`), `BoundParams` /
|
|
109
|
+
`BoundLinks` (what `bindParams`'s source returns / what it returns),
|
|
110
|
+
`NavigationHandler` (`{ claim, load, apply }`).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k8ordo/router",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The pathname axis of the URL, owned. One route table derives the types, the matching, the links, and the navigation, over the Navigation API and URLPattern.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"navigation-api",
|
|
@@ -40,22 +40,25 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@arethetypeswrong/cli": "0.18.5",
|
|
43
|
-
"@types/react": "19.
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
43
|
+
"@types/react": "19.3.0",
|
|
44
|
+
"@types/react-dom": "19.3.0",
|
|
45
|
+
"@vitejs/plugin-react": "6.1.2",
|
|
46
|
+
"@vitest/browser-playwright": "5.0.5",
|
|
47
|
+
"playwright": "1.63.0",
|
|
48
|
+
"publint": "0.3.25",
|
|
49
|
+
"react": "19.3.1",
|
|
50
|
+
"react-dom": "19.3.1",
|
|
49
51
|
"typescript": "7.0.2",
|
|
50
|
-
"vite": "
|
|
51
|
-
"vite-plus": "
|
|
52
|
-
"vitest": "
|
|
53
|
-
"vitest-browser-react": "2.
|
|
52
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
|
|
53
|
+
"vite-plus": "1.3.0",
|
|
54
|
+
"vitest": "5.0.5",
|
|
55
|
+
"vitest-browser-react": "2.3.0"
|
|
54
56
|
},
|
|
55
57
|
"peerDependencies": {
|
|
56
|
-
"@types/react": ">=19.
|
|
57
|
-
"react": ">=19.
|
|
58
|
-
"
|
|
58
|
+
"@types/react": ">=19.3.0",
|
|
59
|
+
"react": ">=19.3.0",
|
|
60
|
+
"react-dom": ">=19.3.0",
|
|
61
|
+
"typescript": ">=7.0.0"
|
|
59
62
|
},
|
|
60
63
|
"peerDependenciesMeta": {
|
|
61
64
|
"@types/react": {
|