@owlmeans/web-router 0.1.10 → 0.1.14
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/agent-meta/instructions/web-router.instructions.md +16 -7
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/web-router/SKILL.md +42 -9
- package/build/browser/chain.d.ts +16 -0
- package/build/browser/chain.d.ts.map +1 -0
- package/build/browser/chain.js +27 -0
- package/build/browser/chain.js.map +1 -0
- package/build/browser/context.d.ts +6 -0
- package/build/browser/context.d.ts.map +1 -0
- package/build/browser/context.js +4 -0
- package/build/browser/context.js.map +1 -0
- package/build/browser/history.d.ts +8 -0
- package/build/browser/history.d.ts.map +1 -0
- package/build/browser/history.js +49 -0
- package/build/browser/history.js.map +1 -0
- package/build/browser/hooks.d.ts +6 -0
- package/build/browser/hooks.d.ts.map +1 -0
- package/build/browser/hooks.js +29 -0
- package/build/browser/hooks.js.map +1 -0
- package/build/browser/outlet.d.ts +9 -0
- package/build/browser/outlet.d.ts.map +1 -0
- package/build/browser/outlet.js +14 -0
- package/build/browser/outlet.js.map +1 -0
- package/build/browser/plugin.d.ts +8 -0
- package/build/browser/plugin.d.ts.map +1 -0
- package/build/browser/plugin.js +27 -0
- package/build/browser/plugin.js.map +1 -0
- package/build/browser/provider.d.ts +11 -0
- package/build/browser/provider.d.ts.map +1 -0
- package/build/browser/provider.js +39 -0
- package/build/browser/provider.js.map +1 -0
- package/build/browser/types.d.ts +20 -0
- package/build/browser/types.d.ts.map +1 -0
- package/build/browser/types.js +2 -0
- package/build/browser/types.js.map +1 -0
- package/build/consts.d.ts +2 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +2 -0
- package/build/consts.js.map +1 -0
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/service.d.ts +13 -4
- package/build/service.d.ts.map +1 -1
- package/build/service.js +15 -19
- package/build/service.js.map +1 -1
- package/package.json +16 -9
- package/src/browser/chain.tsx +35 -0
- package/src/browser/context.ts +6 -0
- package/src/browser/history.ts +56 -0
- package/src/browser/hooks.ts +42 -0
- package/src/browser/outlet.tsx +16 -0
- package/src/browser/plugin.ts +29 -0
- package/src/browser/provider.tsx +53 -0
- package/src/browser/types.ts +22 -0
- package/src/consts.ts +2 -0
- package/src/index.ts +8 -0
- package/src/service.ts +20 -31
- package/tests/context.ts +33 -0
- package/tests/harness/index.html +11 -0
- package/tests/harness/mount.tsx +60 -0
- package/tests/routing.spec.ts +100 -0
- package/tsconfig.json +1 -1
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: "How to use @owlmeans/web-router —
|
|
2
|
+
description: "How to use @owlmeans/web-router — the DEFAULT OwlMeans in-browser routing plugin (History API + pure matcher + React provider/outlet/hooks). Use when wiring web routing."
|
|
3
3
|
applyTo: "**/*.ts, **/*.tsx"
|
|
4
4
|
---
|
|
5
5
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
6
6
|
|
|
7
7
|
# @owlmeans/web-router
|
|
8
8
|
|
|
9
|
-
**Layer:** Web (React)
|
|
10
|
-
**Install:** `"@owlmeans/web-router": "^0.1.
|
|
9
|
+
**Layer:** Web (React), L2
|
|
10
|
+
**Install:** `"@owlmeans/web-router": "^0.1.14"` in `dependencies`
|
|
11
|
+
|
|
12
|
+
The **default OwlMeans in-browser router** — react-router-free standard URL routing over the
|
|
13
|
+
History API, registered as a `RouterPlugin` on the `@owlmeans/router` host. (react-router now lives
|
|
14
|
+
in the opt-in `@owlmeans/web-router-react-router`.)
|
|
11
15
|
|
|
12
16
|
## Key Exports
|
|
13
17
|
|
|
14
18
|
| Export | Description |
|
|
15
19
|
|--------|-------------|
|
|
16
|
-
| `
|
|
20
|
+
| `appendWebRouter(ctx)` | Register the OwlMeans browser plugin (idempotent). Called transparently by `web-client`. |
|
|
21
|
+
| `makeBrowserRouterPlugin()` | The `RouterPlugin` (alias `owlmeans-browser-router`, priority 0). |
|
|
22
|
+
| `BrowserRouterProvider`, `Outlet`, hooks, `createBrowserHistory()` | React pieces + history wrapper. |
|
|
17
23
|
|
|
18
24
|
## Usage
|
|
19
25
|
|
|
20
26
|
```typescript
|
|
21
|
-
import {
|
|
22
|
-
context
|
|
27
|
+
import { appendWebRouter } from '@owlmeans/web-router'
|
|
28
|
+
appendWebRouter(context) // default OwlMeans routing
|
|
23
29
|
```
|
|
24
30
|
|
|
31
|
+
Supported route syntax: static, `:param`, nested, index. To use react-router instead, call
|
|
32
|
+
`appendReactRouter(ctx)` from `@owlmeans/web-router-react-router` (its higher priority wins).
|
|
33
|
+
|
|
25
34
|
## Depends On
|
|
26
35
|
|
|
27
|
-
- `@owlmeans/router`, `@owlmeans/
|
|
36
|
+
- `@owlmeans/router`, `@owlmeans/context`; peer `react` (no react-router)
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"package": "@owlmeans/web-router",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.14",
|
|
5
|
+
"generatedAt": "2026-08-05T16:56:53.389Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,31 +1,64 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: web-router
|
|
3
|
-
description: How to use @owlmeans/web-router —
|
|
3
|
+
description: How to use @owlmeans/web-router — the DEFAULT OwlMeans in-browser routing plugin (History API + pure matcher + React provider/outlet/hooks). Auto-invoked when wiring web routing or importing the browser plugin.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
7
7
|
|
|
8
8
|
# @owlmeans/web-router
|
|
9
9
|
|
|
10
|
-
**Layer:** Web (React)
|
|
11
|
-
**Install:** `"@owlmeans/web-router": "^0.1.
|
|
10
|
+
**Layer:** Web (React), build level L2
|
|
11
|
+
**Install:** `"@owlmeans/web-router": "^0.1.14"` in `dependencies`
|
|
12
|
+
|
|
13
|
+
As of the pluggable-routing rework this package **is the default OwlMeans in-browser router** — a
|
|
14
|
+
minimal, react-router-free implementation of standard URL routing over the browser History API. It
|
|
15
|
+
registers itself as a `RouterPlugin` on the `@owlmeans/router` host. (react-router now lives in the
|
|
16
|
+
separate opt-in `@owlmeans/web-router-react-router` package.)
|
|
12
17
|
|
|
13
18
|
## Key Exports
|
|
14
19
|
|
|
15
20
|
| Export | Description |
|
|
16
21
|
|--------|-------------|
|
|
17
|
-
| `
|
|
22
|
+
| `appendWebRouter(ctx)` | Register the OwlMeans browser plugin on a context's router host (idempotent via `ensureRouterService`). Called transparently by `@owlmeans/web-client`. |
|
|
23
|
+
| `makeBrowserRouterPlugin()` | The `RouterPlugin` itself (alias `owlmeans-browser-router`, priority 0). |
|
|
24
|
+
| `makeWebRouterService()` | Back-compat: a host pre-loaded with the browser plugin. |
|
|
25
|
+
| `BrowserRouterProvider`, `Outlet` | React provider/outlet components. |
|
|
26
|
+
| `RouteChain` | Renders the matched chain from a given depth, skipping `Component`-less matches (used by the provider and `Outlet`). |
|
|
27
|
+
| `useParams` / `useLocation` / `useNavigate` / `useSearchParams` | The plugin's hooks (usually reached via `context.router().…`). |
|
|
28
|
+
| `createBrowserHistory()` | History API wrapper (push/replace/go/popstate). |
|
|
29
|
+
|
|
30
|
+
## How it works
|
|
31
|
+
|
|
32
|
+
- `compile(routes)` flattens + ranks the neutral `RouteObject[]` into matchable branches (using the
|
|
33
|
+
`@owlmeans/router` matcher). No async, no react-router.
|
|
34
|
+
- `BrowserRouterProvider` subscribes to history, re-matches on navigation, and renders the match
|
|
35
|
+
chain via `RouteChain`; `<Outlet/>` renders the next-deeper match (depth tracked via context).
|
|
36
|
+
Composes unchanged with the `@owlmeans/client` route renderer (parent components emit `<Outlet/>`).
|
|
37
|
+
- **Component-less matches are pass-through** — exactly like react-router's implicit `<Outlet/>` for
|
|
38
|
+
element-less routes. `@owlmeans/client` emits `RouteObject`s with no `Component` for modules that
|
|
39
|
+
have no handler (grouping modules such as `client-authentication` →
|
|
40
|
+
`client-authentication:authentication`), so rendering only the exact node at a depth would blank
|
|
41
|
+
the whole subtree. `RouteChain` walks down to the first match that has a `Component`, and the
|
|
42
|
+
`OutletContext` depth it publishes is that match's depth, so nested outlets stay aligned.
|
|
43
|
+
- Supported route syntax: static segments, `:param`, nested (parent/child), index (`default:true`).
|
|
44
|
+
**No splat/optional yet** (a seam is reserved).
|
|
18
45
|
|
|
19
46
|
## Usage
|
|
20
47
|
|
|
21
|
-
|
|
48
|
+
Wired transparently by `@owlmeans/web-client` / `@owlmeans/web-panel`. To switch an app to
|
|
49
|
+
react-router instead, call `appendReactRouter(ctx)` from `@owlmeans/web-router-react-router` in
|
|
50
|
+
your `makeContext` — its higher priority wins the cascade.
|
|
22
51
|
|
|
23
52
|
```typescript
|
|
24
|
-
import {
|
|
25
|
-
context
|
|
53
|
+
import { appendWebRouter } from '@owlmeans/web-router'
|
|
54
|
+
appendWebRouter(context) // default; OwlMeans browser routing
|
|
26
55
|
```
|
|
27
56
|
|
|
28
57
|
## Depends On
|
|
29
58
|
|
|
30
|
-
- `@owlmeans/router
|
|
31
|
-
- `react
|
|
59
|
+
- `@owlmeans/router` (host + matcher), `@owlmeans/context`
|
|
60
|
+
- peer `react` (no react-router)
|
|
61
|
+
|
|
62
|
+
## Related
|
|
63
|
+
|
|
64
|
+
- [[router]] (host) · [[router-plugins]] (authoring) · `web-router-react-router` (opt-in RR plugin)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Renders the matched route chain starting at `depth`.
|
|
4
|
+
*
|
|
5
|
+
* A matched route that carries no `Component` is a **pass-through**: it renders
|
|
6
|
+
* the next-deeper match, exactly like react-router's implicit `<Outlet/>` for
|
|
7
|
+
* element-less routes. OwlMeans module trees depend on this — grouping modules
|
|
8
|
+
* (e.g. `client-authentication` → `client-authentication:authentication`) have
|
|
9
|
+
* no handler, so `@owlmeans/client` emits `RouteObject`s without a `Component`
|
|
10
|
+
* for them. Rendering only the exact node at `depth` would leave the whole
|
|
11
|
+
* subtree blank whenever a group sits above the screen module.
|
|
12
|
+
*/
|
|
13
|
+
export declare const RouteChain: FC<{
|
|
14
|
+
depth: number;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../src/browser/chain.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAI/B;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAmB5C,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createElement, useContext } from 'react';
|
|
2
|
+
import { RouterStateContext, OutletContext } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* Renders the matched route chain starting at `depth`.
|
|
5
|
+
*
|
|
6
|
+
* A matched route that carries no `Component` is a **pass-through**: it renders
|
|
7
|
+
* the next-deeper match, exactly like react-router's implicit `<Outlet/>` for
|
|
8
|
+
* element-less routes. OwlMeans module trees depend on this — grouping modules
|
|
9
|
+
* (e.g. `client-authentication` → `client-authentication:authentication`) have
|
|
10
|
+
* no handler, so `@owlmeans/client` emits `RouteObject`s without a `Component`
|
|
11
|
+
* for them. Rendering only the exact node at `depth` would leave the whole
|
|
12
|
+
* subtree blank whenever a group sits above the screen module.
|
|
13
|
+
*/
|
|
14
|
+
export const RouteChain = ({ depth }) => {
|
|
15
|
+
const state = useContext(RouterStateContext);
|
|
16
|
+
const matches = state?.matches ?? [];
|
|
17
|
+
let current = depth;
|
|
18
|
+
while (current < matches.length && matches[current].route.Component == null) {
|
|
19
|
+
current++;
|
|
20
|
+
}
|
|
21
|
+
const Component = matches[current]?.route.Component;
|
|
22
|
+
if (Component == null) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return createElement(OutletContext.Provider, { value: { depth: current } }, createElement(Component));
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/browser/chain.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEhE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAA0B,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC7D,MAAM,KAAK,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAA;IAC5C,MAAM,OAAO,GAAG,KAAK,EAAE,OAAO,IAAI,EAAE,CAAA;IAEpC,IAAI,OAAO,GAAG,KAAK,CAAA;IACnB,OAAO,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;QAC5E,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACnD,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QACtB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,aAAa,CAClB,aAAa,CAAC,QAAQ,EACtB,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAC7B,aAAa,CAAC,SAAS,CAAC,CACzB,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/browser/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,kBAAkB,6CAA0C,CAAA;AAEzE,eAAO,MAAM,aAAa;WAA0B,MAAM;EAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/browser/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAGrC,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAqB,IAAI,CAAC,CAAA;AAEzE,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BrowserHistory } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal history wrapping the browser `window.history` + `popstate`. When no
|
|
4
|
+
* `window` is present (SSR) it returns an inert stub — the browser plugin is only
|
|
5
|
+
* *selected* in the browser, so this is purely defensive.
|
|
6
|
+
*/
|
|
7
|
+
export declare const createBrowserHistory: () => BrowserHistory;
|
|
8
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/browser/history.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,QAAO,cA+CvC,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal history wrapping the browser `window.history` + `popstate`. When no
|
|
3
|
+
* `window` is present (SSR) it returns an inert stub — the browser plugin is only
|
|
4
|
+
* *selected* in the browser, so this is purely defensive.
|
|
5
|
+
*/
|
|
6
|
+
export const createBrowserHistory = () => {
|
|
7
|
+
if (typeof window === 'undefined') {
|
|
8
|
+
const stub = { pathname: '/', search: '', hash: '', state: null, key: '0' };
|
|
9
|
+
return {
|
|
10
|
+
get location() { return stub; },
|
|
11
|
+
push: () => { }, replace: () => { }, go: () => { }, listen: () => () => { }
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const listeners = new Set();
|
|
15
|
+
let counter = 0;
|
|
16
|
+
const currentLocation = () => ({
|
|
17
|
+
pathname: window.location.pathname,
|
|
18
|
+
search: window.location.search,
|
|
19
|
+
hash: window.location.hash,
|
|
20
|
+
state: window.history.state ?? null,
|
|
21
|
+
key: String(counter)
|
|
22
|
+
});
|
|
23
|
+
const notify = () => {
|
|
24
|
+
const location = currentLocation();
|
|
25
|
+
listeners.forEach(callback => callback(location));
|
|
26
|
+
};
|
|
27
|
+
window.addEventListener('popstate', () => {
|
|
28
|
+
counter++;
|
|
29
|
+
notify();
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
get location() { return currentLocation(); },
|
|
33
|
+
push: (to, state) => {
|
|
34
|
+
counter++;
|
|
35
|
+
window.history.pushState(state ?? null, '', to);
|
|
36
|
+
notify();
|
|
37
|
+
},
|
|
38
|
+
replace: (to, state) => {
|
|
39
|
+
window.history.replaceState(state ?? null, '', to);
|
|
40
|
+
notify();
|
|
41
|
+
},
|
|
42
|
+
go: delta => { window.history.go(delta); },
|
|
43
|
+
listen: callback => {
|
|
44
|
+
listeners.add(callback);
|
|
45
|
+
return () => { listeners.delete(callback); };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/browser/history.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAmB,EAAE;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Q,KAAK,OAAO,eAAe,EAAE,CAAA,CAAC,CAAC;QAC3C,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YAClB,OAAO,EAAE,CAAA;YACT,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,IAAI,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;YAC/C,MAAM,EAAE,CAAA;QACV,CAAC;QACD,OAAO,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YACrB,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;YAClD,MAAM,EAAE,CAAA;QACV,CAAC;QACD,EAAE,EAAE,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA,CAAC,CAAC;QACzC,MAAM,EAAE,QAAQ,CAAC,EAAE;YACjB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvB,OAAO,GAAG,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA,CAAC,CAAC,CAAA;QAC7C,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Location, NavigateFunction, RouteParams, UseSearchParamsHook } from '@owlmeans/router';
|
|
2
|
+
export declare const useParams: <T extends RouteParams = RouteParams>() => T;
|
|
3
|
+
export declare const useLocation: () => Location;
|
|
4
|
+
export declare const useNavigate: () => NavigateFunction;
|
|
5
|
+
export declare const useSearchParams: UseSearchParamsHook;
|
|
6
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/browser/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAAmB,mBAAmB,EAC9E,MAAM,kBAAkB,CAAA;AAWzB,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,WAAW,GAAG,WAAW,OAAK,CAGjE,CAAA;AAED,eAAO,MAAM,WAAW,QAAO,QAAqC,CAAA;AAEpE,eAAO,MAAM,WAAW,QAAO,gBAA6C,CAAA;AAE5E,eAAO,MAAM,eAAe,EAAE,mBAkB7B,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { RouterStateContext } from './context.js';
|
|
3
|
+
const useRouterState = () => {
|
|
4
|
+
const state = useContext(RouterStateContext);
|
|
5
|
+
if (state == null) {
|
|
6
|
+
throw new Error('owlmeans-browser-router: router hook used outside of the router provider');
|
|
7
|
+
}
|
|
8
|
+
return state;
|
|
9
|
+
};
|
|
10
|
+
export const useParams = () => {
|
|
11
|
+
const { matches } = useRouterState();
|
|
12
|
+
return (matches[matches.length - 1]?.params ?? {});
|
|
13
|
+
};
|
|
14
|
+
export const useLocation = () => useRouterState().location;
|
|
15
|
+
export const useNavigate = () => useRouterState().navigate;
|
|
16
|
+
export const useSearchParams = init => {
|
|
17
|
+
const { location, navigate } = useRouterState();
|
|
18
|
+
const search = useMemo(() => new URLSearchParams(location.search !== '' ? location.search : (init ?? '')), [location.search]);
|
|
19
|
+
const setSearch = (next, options) => {
|
|
20
|
+
const resolved = typeof next === 'function'
|
|
21
|
+
? next(new URLSearchParams(location.search))
|
|
22
|
+
: next instanceof URLSearchParams ? next : new URLSearchParams(next);
|
|
23
|
+
const query = resolved.toString();
|
|
24
|
+
const path = `${location.pathname}${query !== '' ? `?${query}` : ''}${location.hash ?? ''}`;
|
|
25
|
+
navigate(path, { replace: options?.replace, state: options?.state });
|
|
26
|
+
};
|
|
27
|
+
return [search, setSearch];
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","s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,GAAG,OAAO,IAAI,KAAK,UAAU;YACzC,CAAC,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC5C,CAAC,CAAC,IAAI,YAAY,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,CAAA;QACtE,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAA;QACjC,MAAM,IAAI,GAAG,GAAG,QAAQ,CAAC,QAAQ,GAAG,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,IAAI,IAAI,EAAE,EAAE,CAAA;QAC3F,QAAQ,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;IACtE,CAAC,CAAA;IAED,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAC5B,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Renders the next-deeper matched route. Depth is tracked via `OutletContext`, so
|
|
4
|
+
* nested `<Outlet/>`s walk down the match chain — composing with the renderer in
|
|
5
|
+
* `@owlmeans/client` (parent components emit `<Outlet/>`). Component-less matches
|
|
6
|
+
* in between are skipped by `RouteChain` (implicit pass-through).
|
|
7
|
+
*/
|
|
8
|
+
export declare const Outlet: FC;
|
|
9
|
+
//# sourceMappingURL=outlet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outlet.d.ts","sourceRoot":"","sources":["../../src/browser/outlet.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAK/B;;;;;GAKG;AACH,eAAO,MAAM,MAAM,EAAE,EAIpB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createElement, useContext } from 'react';
|
|
2
|
+
import { OutletContext } from './context.js';
|
|
3
|
+
import { RouteChain } from './chain.js';
|
|
4
|
+
/**
|
|
5
|
+
* Renders the next-deeper matched route. Depth is tracked via `OutletContext`, so
|
|
6
|
+
* nested `<Outlet/>`s walk down the match chain — composing with the renderer in
|
|
7
|
+
* `@owlmeans/client` (parent components emit `<Outlet/>`). Component-less matches
|
|
8
|
+
* in between are skipped by `RouteChain` (implicit pass-through).
|
|
9
|
+
*/
|
|
10
|
+
export const Outlet = () => {
|
|
11
|
+
const { depth } = useContext(OutletContext);
|
|
12
|
+
return createElement(RouteChain, { depth: depth + 1 });
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=outlet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outlet.js","sourceRoot":"","sources":["../../src/browser/outlet.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAO,GAAG,EAAE;IAC7B,MAAM,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC,aAAa,CAAC,CAAA;IAE3C,OAAO,aAAa,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAA;AACxD,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RouterPlugin } from '@owlmeans/router';
|
|
2
|
+
/**
|
|
3
|
+
* The default OwlMeans in-browser routing plugin. Standard URL routing over the
|
|
4
|
+
* browser History API. Matches always (priority 0), so it is the universal
|
|
5
|
+
* fallback in the browser; a higher-priority SSR plugin can outrank it later.
|
|
6
|
+
*/
|
|
7
|
+
export declare const makeBrowserRouterPlugin: () => RouterPlugin;
|
|
8
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/browser/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAQnE;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAAO,YAezC,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { flattenRoutes, rankRouteBranches } from '@owlmeans/router';
|
|
2
|
+
import { BROWSER_ROUTER } from '../consts.js';
|
|
3
|
+
import { BrowserRouterProvider } from './provider.js';
|
|
4
|
+
import { Outlet } from './outlet.js';
|
|
5
|
+
import { useLocation, useNavigate, useParams, useSearchParams } from './hooks.js';
|
|
6
|
+
/**
|
|
7
|
+
* The default OwlMeans in-browser routing plugin. Standard URL routing over the
|
|
8
|
+
* browser History API. Matches always (priority 0), so it is the universal
|
|
9
|
+
* fallback in the browser; a higher-priority SSR plugin can outrank it later.
|
|
10
|
+
*/
|
|
11
|
+
export const makeBrowserRouterPlugin = () => ({
|
|
12
|
+
alias: BROWSER_ROUTER,
|
|
13
|
+
priority: 0,
|
|
14
|
+
mode: 'browser',
|
|
15
|
+
match: () => true,
|
|
16
|
+
compile: routes => ({
|
|
17
|
+
routes,
|
|
18
|
+
branches: rankRouteBranches(flattenRoutes(routes))
|
|
19
|
+
}),
|
|
20
|
+
provider: () => BrowserRouterProvider,
|
|
21
|
+
outlet: () => Outlet,
|
|
22
|
+
useParams,
|
|
23
|
+
useLocation,
|
|
24
|
+
useNavigate,
|
|
25
|
+
useSearchParams
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/browser/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAGjF;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAiB,EAAE,CAAC,CAAC;IAC1D,KAAK,EAAE,cAAc;IACrB,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;IACjB,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAClB,MAAM;QACN,QAAQ,EAAE,iBAAiB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;KACN,CAAA;IAC9C,QAAQ,EAAE,GAAG,EAAE,CAAC,qBAAqB;IACrC,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,eAAe;CAChB,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import type { LibraryRouter } from '@owlmeans/router';
|
|
3
|
+
/**
|
|
4
|
+
* Renders the OwlMeans library router. Subscribes to history, recomputes the
|
|
5
|
+
* matched route chain on navigation, and renders the top match. Initial render
|
|
6
|
+
* matches synchronously from `window.location` to avoid a first-paint flash.
|
|
7
|
+
*/
|
|
8
|
+
export declare const BrowserRouterProvider: FC<{
|
|
9
|
+
router: LibraryRouter;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/browser/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,KAAK,EAAE,aAAa,EAA8B,MAAM,kBAAkB,CAAA;AAOjF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,EAAE,CAAC;IAAE,MAAM,EAAE,aAAa,CAAA;CAAE,CAsC/D,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createElement, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { matchRoutes } from '@owlmeans/router';
|
|
3
|
+
import { createBrowserHistory } from './history.js';
|
|
4
|
+
import { RouterStateContext } from './context.js';
|
|
5
|
+
import { RouteChain } from './chain.js';
|
|
6
|
+
/**
|
|
7
|
+
* Renders the OwlMeans library router. Subscribes to history, recomputes the
|
|
8
|
+
* matched route chain on navigation, and renders the top match. Initial render
|
|
9
|
+
* matches synchronously from `window.location` to avoid a first-paint flash.
|
|
10
|
+
*/
|
|
11
|
+
export const BrowserRouterProvider = ({ router }) => {
|
|
12
|
+
const lib = router;
|
|
13
|
+
const historyRef = useRef(createBrowserHistory());
|
|
14
|
+
const history = historyRef.current;
|
|
15
|
+
const [location, setLocation] = useState(() => history.location);
|
|
16
|
+
useEffect(() => history.listen(setLocation), []);
|
|
17
|
+
const matches = useMemo(() => matchRoutes(lib.branches, location.pathname) ?? [], [lib, location.pathname]);
|
|
18
|
+
const navigate = useMemo(() => ((to, options) => {
|
|
19
|
+
if (typeof to === 'number') {
|
|
20
|
+
history.go(to);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (typeof to === 'string' && to.startsWith('http')) {
|
|
24
|
+
window.location.href = to;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const path = typeof to === 'string'
|
|
28
|
+
? to
|
|
29
|
+
: `${to.pathname ?? ''}${to.search ?? ''}${to.hash ?? ''}`;
|
|
30
|
+
if (options?.replace) {
|
|
31
|
+
history.replace(path, options.state);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
history.push(path, options?.state);
|
|
35
|
+
}
|
|
36
|
+
}), [history]);
|
|
37
|
+
return createElement(RouterStateContext.Provider, { value: { location, matches, navigate } }, createElement(RouteChain, { depth: 0 }));
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/browser/provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAkC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;IACjF,MAAM,GAAG,GAAG,MAA0B,CAAA;IACtC,MAAM,UAAU,GAAG,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAA;IACjD,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;IAElC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAW,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAE1E,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,CAAA;IAEhD,MAAM,OAAO,GAAG,OAAO,CACrB,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,EACxD,CAAC,GAAG,EAAE,QAAQ,C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+
/** The compiled library router produced by the browser plugin's `compile`. */
|
|
3
|
+
export interface OwlLibraryRouter {
|
|
4
|
+
routes: RouteObject[];
|
|
5
|
+
branches: RouteBranch[];
|
|
6
|
+
}
|
|
7
|
+
/** Value carried by the router state React context. */
|
|
8
|
+
export interface RouterState {
|
|
9
|
+
location: Location;
|
|
10
|
+
matches: RouteMatch[];
|
|
11
|
+
navigate: NavigateFunction;
|
|
12
|
+
}
|
|
13
|
+
export interface BrowserHistory {
|
|
14
|
+
readonly location: Location;
|
|
15
|
+
push: (to: string, state?: any) => void;
|
|
16
|
+
replace: (to: string, state?: any) => void;
|
|
17
|
+
go: (delta: number) => void;
|
|
18
|
+
listen: (callback: (location: Location) => void) => () => void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/browser/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAExG,8EAA8E;AAC9E,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,QAAQ,EAAE,WAAW,EAAE,CAAA;CACxB;AAED,uDAAuD;AACvD,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE,UAAU,EAAE,CAAA;IACrB,QAAQ,EAAE,gBAAgB,CAAA;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;IACvC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;IAC1C,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3B,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,KAAK,MAAM,IAAI,CAAA;CAC/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/browser/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,4BAA4B,CAAA"}
|
package/build/consts.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,cAAc,GAAG,yBAAyB,CAAA"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
export * from './consts.js';
|
|
1
2
|
export * from './service.js';
|
|
3
|
+
export * from './browser/plugin.js';
|
|
4
|
+
export type * from './browser/types.js';
|
|
5
|
+
export { BrowserRouterProvider } from './browser/provider.js';
|
|
6
|
+
export { Outlet } from './browser/outlet.js';
|
|
7
|
+
export { RouteChain } from './browser/chain.js';
|
|
8
|
+
export { createBrowserHistory } from './browser/history.js';
|
|
9
|
+
export { useParams, useLocation, useNavigate, useSearchParams } from './browser/hooks.js';
|
|
2
10
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AACnC,mBAAmB,oBAAoB,CAAA;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
export * from './consts.js';
|
|
1
2
|
export * from './service.js';
|
|
3
|
+
export * from './browser/plugin.js';
|
|
4
|
+
export { BrowserRouterProvider } from './browser/provider.js';
|
|
5
|
+
export { Outlet } from './browser/outlet.js';
|
|
6
|
+
export { RouteChain } from './browser/chain.js';
|
|
7
|
+
export { createBrowserHistory } from './browser/history.js';
|
|
8
|
+
export { useParams, useLocation, useNavigate, useSearchParams } from './browser/hooks.js';
|
|
2
9
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AAEnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA"}
|
package/build/service.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { BasicConfig, BasicContext } from "@owlmeans/context";
|
|
2
|
+
import type { RouterService } from "@owlmeans/router";
|
|
3
|
+
/**
|
|
4
|
+
* Build a router service pre-loaded with the OwlMeans browser plugin. Kept for
|
|
5
|
+
* back-compat; prefer `appendWebRouter` which reuses an existing host.
|
|
6
|
+
*/
|
|
7
|
+
export declare const makeWebRouterService: () => RouterService;
|
|
8
|
+
/**
|
|
9
|
+
* Register the OwlMeans in-browser routing plugin as the default on a context.
|
|
10
|
+
* Idempotent w.r.t. the router host — if another plugin (e.g. react-router) is
|
|
11
|
+
* already registered, this one is added alongside and selected by the cascade.
|
|
12
|
+
*/
|
|
13
|
+
export declare const appendWebRouter: <C extends BasicConfig, T extends BasicContext<C>>(ctx: T) => T;
|
|
5
14
|
//# sourceMappingURL=service.d.ts.map
|
package/build/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAIrD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,QAAO,aAIvC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,KAAG,CAI1F,CAAA"}
|
package/build/service.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
import { makeRouterService } from "@owlmeans/router";
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ensureRouterService, makeRouterService } from "@owlmeans/router";
|
|
2
|
+
import { makeBrowserRouterPlugin } from "./browser/plugin.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build a router service pre-loaded with the OwlMeans browser plugin. Kept for
|
|
5
|
+
* back-compat; prefer `appendWebRouter` which reuses an existing host.
|
|
6
|
+
*/
|
|
4
7
|
export const makeWebRouterService = () => {
|
|
5
8
|
const service = makeRouterService();
|
|
6
|
-
service.
|
|
7
|
-
return Outlet;
|
|
8
|
-
};
|
|
9
|
-
service.provider = () => {
|
|
10
|
-
return RouterProvider;
|
|
11
|
-
};
|
|
12
|
-
service.useParams = () => {
|
|
13
|
-
return useParams();
|
|
14
|
-
};
|
|
15
|
-
service.useLocation = () => {
|
|
16
|
-
return useLocation();
|
|
17
|
-
};
|
|
18
|
-
service.useNavigate = () => {
|
|
19
|
-
return useNavigate();
|
|
20
|
-
};
|
|
9
|
+
service.registerPlugin(makeBrowserRouterPlugin());
|
|
21
10
|
return service;
|
|
22
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Register the OwlMeans in-browser routing plugin as the default on a context.
|
|
14
|
+
* Idempotent w.r.t. the router host — if another plugin (e.g. react-router) is
|
|
15
|
+
* already registered, this one is added alongside and selected by the cascade.
|
|
16
|
+
*/
|
|
23
17
|
export const appendWebRouter = (ctx) => {
|
|
24
|
-
ctx
|
|
18
|
+
const service = ensureRouterService(ctx);
|
|
19
|
+
service.registerPlugin(makeBrowserRouterPlugin());
|
|
20
|
+
return ctx;
|
|
25
21
|
};
|
|
26
22
|
//# sourceMappingURL=service.js.map
|