@effectweb/tanstack-router 0.8.0 → 0.8.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/dist/index.d.ts +1 -1
- package/dist/index.js +116 -103
- package/dist/link.js +67 -72
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export { createBrowserHistory, createMemoryHistory } from '@tanstack/history';
|
|
|
6
6
|
/** TanStack supplies matching, loaders, search validation and typed navigation; EffectWeb owns publications. */
|
|
7
7
|
export declare const createRouter: CreateRouterFn;
|
|
8
8
|
/** Mount once per router in an Effect scope. The returned Source can drive an EffectWeb program or view. */
|
|
9
|
-
export declare const mountRouter: <Router extends AnyRouter>(router: Router) => Effect.Effect<Source<RouterState<Router[
|
|
9
|
+
export declare const mountRouter: <Router extends AnyRouter>(router: Router) => Effect.Effect<Source<RouterState<Router['routeTree']>>, Error, Scope.Scope>;
|
|
10
10
|
export { createLink, linkTarget, type LinkProps } from './link.js';
|
package/dist/index.js
CHANGED
|
@@ -1,106 +1,119 @@
|
|
|
1
|
-
import { Effect } from
|
|
2
|
-
import { projectionSource } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { projectionSource } from "effectweb/advanced";
|
|
3
|
+
import {
|
|
4
|
+
RouterCore,
|
|
5
|
+
createNonReactiveMutableStore,
|
|
6
|
+
createNonReactiveReadonlyStore
|
|
7
|
+
} from "@tanstack/router-core";
|
|
8
|
+
import {
|
|
9
|
+
BaseRoute,
|
|
10
|
+
BaseRootRoute,
|
|
11
|
+
redirect,
|
|
12
|
+
notFound
|
|
13
|
+
} from "@tanstack/router-core";
|
|
14
|
+
import { createBrowserHistory, createMemoryHistory } from "@tanstack/history";
|
|
15
|
+
const snapshotCopy = (value, seen = /* @__PURE__ */ new WeakMap()) => {
|
|
16
|
+
if (value === null || typeof value !== "object") return value;
|
|
17
|
+
const prototype = Object.getPrototypeOf(value);
|
|
18
|
+
if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return value;
|
|
19
|
+
if (seen.has(value)) return seen.get(value);
|
|
20
|
+
const copy = Array.isArray(value) ? [] : {};
|
|
21
|
+
seen.set(value, copy);
|
|
22
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
23
|
+
if (key === "length" && Array.isArray(value)) continue;
|
|
24
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
25
|
+
if ("value" in descriptor)
|
|
26
|
+
Object.defineProperty(copy, key, {
|
|
27
|
+
value: snapshotCopy(descriptor.value, seen),
|
|
28
|
+
writable: true,
|
|
29
|
+
enumerable: descriptor.enumerable ?? false,
|
|
30
|
+
configurable: true
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return copy;
|
|
30
34
|
};
|
|
31
|
-
const publications = new WeakMap();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}));
|
|
69
|
-
publications.set(instance, listeners);
|
|
70
|
-
return instance;
|
|
35
|
+
const publications = /* @__PURE__ */ new WeakMap();
|
|
36
|
+
const createRouter = (options) => {
|
|
37
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
38
|
+
let batchDepth = 0;
|
|
39
|
+
let dirty = false;
|
|
40
|
+
const publish = () => {
|
|
41
|
+
dirty = true;
|
|
42
|
+
if (batchDepth) return;
|
|
43
|
+
dirty = false;
|
|
44
|
+
for (const listener of listeners) listener();
|
|
45
|
+
};
|
|
46
|
+
const instance = new RouterCore(options, () => ({
|
|
47
|
+
createMutableStore: (initial) => {
|
|
48
|
+
const store = createNonReactiveMutableStore(initial);
|
|
49
|
+
return {
|
|
50
|
+
get: store.get,
|
|
51
|
+
set: (next) => {
|
|
52
|
+
store.set(
|
|
53
|
+
(previous) => typeof next === "function" ? next(previous) : next
|
|
54
|
+
);
|
|
55
|
+
publish();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
createReadonlyStore: createNonReactiveReadonlyStore,
|
|
60
|
+
batch: (run) => {
|
|
61
|
+
batchDepth++;
|
|
62
|
+
try {
|
|
63
|
+
run();
|
|
64
|
+
} finally {
|
|
65
|
+
batchDepth--;
|
|
66
|
+
if (!batchDepth && dirty) publish();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
publications.set(instance, listeners);
|
|
71
|
+
return instance;
|
|
71
72
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
73
|
+
const mountRouter = (router) => Effect.gen(function* () {
|
|
74
|
+
const source = yield* Effect.acquireRelease(
|
|
75
|
+
Effect.sync(() => {
|
|
76
|
+
const listeners = publications.get(router);
|
|
77
|
+
const history = router.history;
|
|
78
|
+
if (!listeners)
|
|
79
|
+
throw new Error("Use @effectweb/tanstack-router.createRouter before mountRouter");
|
|
80
|
+
const source2 = projectionSource({
|
|
81
|
+
project: () => snapshotCopy(router.state)
|
|
82
|
+
});
|
|
83
|
+
listeners.add(source2.changed);
|
|
84
|
+
source2.start();
|
|
85
|
+
const unsubscribe = history.subscribe(() => {
|
|
86
|
+
void router.load().catch((error) => console.error("Router navigation failed", error));
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
source: source2,
|
|
90
|
+
dispose: () => {
|
|
91
|
+
unsubscribe();
|
|
92
|
+
listeners.delete(source2.changed);
|
|
93
|
+
source2.dispose();
|
|
94
|
+
history.flush();
|
|
95
|
+
history.destroy();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}),
|
|
99
|
+
(mounted) => Effect.sync(() => mounted.dispose())
|
|
100
|
+
);
|
|
101
|
+
yield* Effect.tryPromise({
|
|
102
|
+
try: () => router.load(),
|
|
103
|
+
catch: (cause) => cause instanceof Error ? cause : new Error(String(cause))
|
|
104
|
+
});
|
|
105
|
+
return source.source;
|
|
105
106
|
});
|
|
106
|
-
|
|
107
|
+
import { createLink, linkTarget } from "./link.js";
|
|
108
|
+
export {
|
|
109
|
+
BaseRootRoute as RootRoute,
|
|
110
|
+
BaseRoute as Route,
|
|
111
|
+
createBrowserHistory,
|
|
112
|
+
createLink,
|
|
113
|
+
createMemoryHistory,
|
|
114
|
+
createRouter,
|
|
115
|
+
linkTarget,
|
|
116
|
+
mountRouter,
|
|
117
|
+
notFound,
|
|
118
|
+
redirect
|
|
119
|
+
};
|
package/dist/link.js
CHANGED
|
@@ -1,79 +1,74 @@
|
|
|
1
1
|
import * as _ew_dom from "effectweb/dom";
|
|
2
|
-
const _ew_jsx0 =
|
|
2
|
+
const _ew_jsx0 = /* @__PURE__ */ _ew_dom.markup("a");
|
|
3
3
|
import { getUrlScheme, isDangerousProtocol } from "@tanstack/router-core";
|
|
4
4
|
import { jsxComponent } from "effectweb/jsx";
|
|
5
5
|
const options = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
"to",
|
|
7
|
+
"from",
|
|
8
|
+
"params",
|
|
9
|
+
"search",
|
|
10
|
+
"hash",
|
|
11
|
+
"state",
|
|
12
|
+
"mask",
|
|
13
|
+
"replace",
|
|
14
|
+
"resetScroll",
|
|
15
|
+
"hashScrollIntoView",
|
|
16
|
+
"viewTransition",
|
|
17
|
+
"ignoreBlocker",
|
|
18
|
+
"reloadDocument",
|
|
19
|
+
"href",
|
|
20
|
+
"activeOptions",
|
|
21
|
+
"preload",
|
|
22
|
+
"preloadDelay",
|
|
23
|
+
"preloadIntentProximity",
|
|
24
|
+
"disabled",
|
|
25
|
+
"active",
|
|
26
|
+
"children"
|
|
27
27
|
];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
// Let the browser handle new tabs, downloads and full reloads.
|
|
45
|
-
const download = props.download !== undefined && props.download !== false;
|
|
46
|
-
if (!plain || external || download || props.reloadDocument || props.target && props.target !== "_self")
|
|
47
|
-
return;
|
|
48
|
-
event.preventDefault();
|
|
49
|
-
router.navigate(props).catch((error) => {
|
|
50
|
-
console.error("Router navigation failed", error);
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
href,
|
|
55
|
-
onClick
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Create a typed `<Link>` for one router. It renders a real `<a href>` (middle-click,
|
|
60
|
-
* copy link and accessibility keep working) and navigates in place on plain clicks.
|
|
61
|
-
*/
|
|
62
|
-
export function createLink(router) {
|
|
63
|
-
function Link(props) {
|
|
64
|
-
const target = linkTarget(router, props);
|
|
65
|
-
const attributes = { ...props };
|
|
66
|
-
for (const name of options)
|
|
67
|
-
delete attributes[name];
|
|
68
|
-
return _ew_jsx0({
|
|
69
|
-
...attributes,
|
|
70
|
-
"href": target.href,
|
|
71
|
-
"target": props.target,
|
|
72
|
-
"aria-current": props.active ? "page" : undefined,
|
|
73
|
-
"aria-disabled": props.disabled ? "true" : undefined,
|
|
74
|
-
"onClick": target.onClick,
|
|
75
|
-
children: props.children
|
|
76
|
-
});
|
|
28
|
+
function linkTarget(router, props) {
|
|
29
|
+
const explicitHref = props.href;
|
|
30
|
+
const blocked = explicitHref !== void 0 && isDangerousProtocol(explicitHref, router.protocolAllowlist);
|
|
31
|
+
const absoluteHref = explicitHref !== void 0 && getUrlScheme(explicitHref) ? explicitHref : void 0;
|
|
32
|
+
const location = absoluteHref || blocked ? void 0 : router.buildLocation(props);
|
|
33
|
+
const external = absoluteHref !== void 0 || location?.external === true;
|
|
34
|
+
const publicHref = absoluteHref ?? location?.publicHref;
|
|
35
|
+
const history = router.history;
|
|
36
|
+
const href = props.disabled || blocked ? void 0 : props.reloadDocument || external ? publicHref : history.createHref(publicHref);
|
|
37
|
+
const onClick = (event) => {
|
|
38
|
+
const plain = event.button === 0 && !event.metaKey && !event.altKey && !event.ctrlKey && !event.shiftKey && !event.defaultPrevented;
|
|
39
|
+
if (props.disabled || blocked) {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
return;
|
|
77
42
|
}
|
|
78
|
-
|
|
43
|
+
const download = props.download !== void 0 && props.download !== false;
|
|
44
|
+
if (!plain || external || download || props.reloadDocument || props.target && props.target !== "_self") return;
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
router.navigate(props).catch((error) => {
|
|
47
|
+
console.error("Router navigation failed", error);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
href,
|
|
52
|
+
onClick
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function createLink(router) {
|
|
56
|
+
function Link(props) {
|
|
57
|
+
const target = linkTarget(router, props);
|
|
58
|
+
const attributes = { ...props };
|
|
59
|
+
for (const name of options) delete attributes[name];
|
|
60
|
+
return _ew_jsx0({
|
|
61
|
+
...attributes,
|
|
62
|
+
"href": target.href,
|
|
63
|
+
"target": props.target,
|
|
64
|
+
"aria-current": props.active ? "page" : void 0,
|
|
65
|
+
"aria-disabled": props.disabled ? "true" : void 0,
|
|
66
|
+
"onClick": target.onClick
|
|
67
|
+
}, props.children);
|
|
68
|
+
}
|
|
69
|
+
return Object.assign(Link, { [jsxComponent]: true });
|
|
79
70
|
}
|
|
71
|
+
export {
|
|
72
|
+
createLink,
|
|
73
|
+
linkTarget
|
|
74
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectweb/tanstack-router",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@tanstack/history": "1.162.4",
|
|
28
|
-
"@tanstack/router-core": "1.171.
|
|
28
|
+
"@tanstack/router-core": "1.171.34"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"effect": "4.0.0-rc.
|
|
32
|
-
"effectweb": "^0.8.
|
|
31
|
+
"effect": "4.0.0-rc.118",
|
|
32
|
+
"effectweb": "^0.8.1"
|
|
33
33
|
}
|
|
34
34
|
}
|