waku-navigation 0.0.0 → 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Daishi Kato
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # waku-navigation
2
+
3
+ Experimental Waku Router implementation with Navigation API
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install waku-navigation
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Create this file as `./src/waku.client.tsx`:
14
+
15
+ ```tsx
16
+ import { StrictMode } from 'react';
17
+ import { createRoot, hydrateRoot } from 'react-dom/client';
18
+ import { Router } from 'waku-navigation';
19
+
20
+ const rootElement = (
21
+ <StrictMode>
22
+ <Router />
23
+ </StrictMode>
24
+ );
25
+
26
+ if ((globalThis as any).__WAKU_HYDRATE__) {
27
+ hydrateRoot(document, rootElement);
28
+ } else {
29
+ createRoot(document as any).render(rootElement);
30
+ }
31
+ ```
@@ -0,0 +1 @@
1
+ export declare function Router(): import("react/jsx-runtime").JSX.Element;
package/dist/client.js ADDED
@@ -0,0 +1,30 @@
1
+ /// <reference types="dom-navigation" />
2
+ 'use client';
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
+ import { useEffect, useState } from 'react';
5
+ import { Root, Slot, useRefetch } from 'waku/minimal/client';
6
+ import { unstable_encodeRoutePath as encodeRoutePath, unstable_getHttpStatusFromMeta as getHttpStatusFromMeta, unstable_parseRoute as parseRoute, unstable_getRouteSlotId as getRouteSlotId, } from 'waku/router/client';
7
+ function InnerRouter({ initialRoute, httpStatus, }) {
8
+ const refetch = useRefetch();
9
+ const [routePath, setRoutePath] = useState(initialRoute.path);
10
+ useEffect(() => {
11
+ const callback = (event) => {
12
+ // TODO: check if it's an external navigation
13
+ event.intercept();
14
+ const route = parseRoute(new URL(event.destination.url));
15
+ const rscPath = encodeRoutePath(route.path);
16
+ refetch(rscPath);
17
+ setRoutePath(route.path);
18
+ };
19
+ window.navigation.addEventListener('navigate', callback);
20
+ return () => {
21
+ window.navigation.removeEventListener('navigate', callback);
22
+ };
23
+ }, [refetch]);
24
+ return (_jsxs(Slot, { id: "root", children: [_jsx("meta", { name: "httpstatus", content: httpStatus }), _jsx(Slot, { id: getRouteSlotId(routePath) })] }));
25
+ }
26
+ export function Router() {
27
+ const initialRoute = parseRoute(new URL(window.navigation.currentEntry.url));
28
+ const httpStatus = getHttpStatusFromMeta();
29
+ return (_jsx(Root, { initialRscPath: encodeRoutePath(initialRoute.path), children: _jsx(InnerRouter, { initialRoute: initialRoute, httpStatus: httpStatus }) }));
30
+ }
@@ -0,0 +1 @@
1
+ export { Router } from './client.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { Router } from './client.js';
package/package.json CHANGED
@@ -1,4 +1,74 @@
1
1
  {
2
2
  "name": "waku-navigation",
3
- "version": "0.0.0"
3
+ "description": "Waku Router implementation with Navigation API",
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "packageManager": "pnpm@10.28.0",
7
+ "author": "Daishi Kato",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/wakujs/waku-navigation.git"
11
+ },
12
+ "exports": {
13
+ "./package.json": "./package.json",
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "sideEffects": false,
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "compile": "rm -rf dist && tsc -p .",
25
+ "test": "pnpm run '/^test:.*/'",
26
+ "test:format": "prettier -c .",
27
+ "test:lint": "eslint .",
28
+ "test:types": "tsc -p . --noEmit",
29
+ "test:types:examples": "tsc -p examples --noEmit",
30
+ "test:spec": "vitest run",
31
+ "examples:01_minimal": "(cd examples/01_minimal; waku dev)"
32
+ },
33
+ "keywords": [
34
+ "react",
35
+ "waku",
36
+ "navigation"
37
+ ],
38
+ "license": "MIT",
39
+ "prettier": {
40
+ "singleQuote": true
41
+ },
42
+ "devDependencies": {
43
+ "@eslint/js": "^9.39.2",
44
+ "@testing-library/jest-dom": "^6.9.1",
45
+ "@testing-library/react": "^16.3.1",
46
+ "@testing-library/user-event": "^14.6.1",
47
+ "@types/dom-navigation": "^1.0.6",
48
+ "@types/node": "^25.0.6",
49
+ "@types/react": "^19.2.8",
50
+ "@types/react-dom": "^19.2.3",
51
+ "eslint": "^9.39.2",
52
+ "eslint-import-resolver-typescript": "^4.4.4",
53
+ "eslint-plugin-import": "^2.32.0",
54
+ "eslint-plugin-jsx-a11y": "^6.10.2",
55
+ "eslint-plugin-react": "^7.37.5",
56
+ "eslint-plugin-react-hooks": "^7.0.1",
57
+ "happy-dom": "^20.1.0",
58
+ "prettier": "^3.7.4",
59
+ "react": "^19.2.3",
60
+ "react-dom": "^19.2.3",
61
+ "react-server-dom-webpack": "^19.2.3",
62
+ "ts-expect": "^1.3.0",
63
+ "typescript": "^5.9.3",
64
+ "typescript-eslint": "^8.52.0",
65
+ "vite": "^7.3.1",
66
+ "vitest": "^4.0.16",
67
+ "waku": "https://pkg.pr.new/wakujs/waku@fc78f84",
68
+ "waku-navigation": "link:"
69
+ },
70
+ "peerDependencies": {
71
+ "react": ">=19.0.0",
72
+ "waku": ">=1.0.0-alpha.1"
73
+ }
4
74
  }