@effectweb/tanstack-router 0.5.1 → 0.7.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 CHANGED
@@ -7,5 +7,16 @@ EffectWeb adapter for TanStack Router Core.
7
7
  - `mountRouter(router)` owns the history subscription in an Effect scope and returns an EffectWeb `Source` of router state.
8
8
  - The store adapter batches publications and copies plain state before EffectWeb freezes it. It never freezes TanStack's internal match records.
9
9
  - The host program subscribes to that Source and renders its own matching views. Scope cleanup releases the Source, subscriptions and owned history.
10
+ - `createLink(router)` returns a typed `<Link>`: `to`, `params` and `search` are checked against the route tree. It renders a real `<a href>` (middle-click, copy link and screen readers keep working) and navigates in place on plain left clicks. Pass `active` from your route model to set `aria-current="page"`.
10
11
 
11
- Currently there is no JSX Link/Outlet API, route-level view/error boundary system, SSR adapter or file-route generator. Those can build on this binding without introducing a second route matcher.
12
+ ```tsx
13
+ const Link = createLink(router);
14
+
15
+ <Link to="/files/$name" params={{ name: file.name }} active={route.name === file.name}>
16
+ {file.name}
17
+ </Link>;
18
+ ```
19
+
20
+ Prefer `<Link>` to buttons that call `navigate(path: string)`: string paths lose route typing, and buttons are not links for keyboard, assistive technology or new-tab navigation.
21
+
22
+ Currently there is no JSX Outlet API, route-level view/error boundary system, SSR adapter or file-route generator. Those can build on this binding without introducing a second route matcher.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Effect, type Scope } from 'effect';
2
- import { type Source } from 'effectweb';
2
+ import type { Source } from 'effectweb';
3
3
  import { type AnyRouter, type CreateRouterFn, type RouterState } from '@tanstack/router-core';
4
4
  export { BaseRoute as Route, BaseRootRoute as RootRoute, redirect, notFound, } from '@tanstack/router-core';
5
5
  export { createBrowserHistory, createMemoryHistory } from '@tanstack/history';
@@ -7,3 +7,4 @@ export { createBrowserHistory, createMemoryHistory } from '@tanstack/history';
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
9
  export declare const mountRouter: <Router extends AnyRouter>(router: Router) => Effect.Effect<Source<RouterState<Router["routeTree"]>>, Error, Scope.Scope>;
10
+ export { createLink, linkTarget, type LinkProps } from './link.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Effect } from 'effect';
2
- import { projectionSource } from 'effectweb';
2
+ import { projectionSource } from 'effectweb/advanced';
3
3
  import { RouterCore, createNonReactiveMutableStore, createNonReactiveReadonlyStore, } from '@tanstack/router-core';
4
4
  export { BaseRoute as Route, BaseRootRoute as RootRoute, redirect, notFound, } from '@tanstack/router-core';
5
5
  export { createBrowserHistory, createMemoryHistory } from '@tanstack/history';
@@ -103,3 +103,4 @@ export const mountRouter = (router) => Effect.gen(function* () {
103
103
  });
104
104
  return source.source;
105
105
  });
106
+ export { createLink, linkTarget } from './link.js';
package/dist/link.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { type AnyRouter, type LinkOptions } from '@tanstack/router-core';
2
+ import type { JSX } from 'effectweb';
3
+ import { jsxComponent } from 'effectweb/jsx';
4
+ type Anchor = Omit<JSX.IntrinsicElements['a'], 'href' | 'onClick' | 'target' | 'children'>;
5
+ export type LinkProps<Router extends AnyRouter, From extends string = string, To extends string | undefined = '.'> = LinkOptions<Router, From, To> & Anchor & {
6
+ /** Mark the link as the current page (`aria-current="page"`). Derive it from your route model. */
7
+ readonly active?: boolean;
8
+ readonly children?: JSX.Element;
9
+ };
10
+ type ClickEvent = Pick<MouseEvent, 'button' | 'metaKey' | 'altKey' | 'ctrlKey' | 'shiftKey' | 'defaultPrevented' | 'preventDefault'>;
11
+ /** Resolve a typed destination to an href and a click handler that navigates in place. */
12
+ export declare function linkTarget(router: AnyRouter, props: LinkOptions<AnyRouter, string, string> & Pick<Anchor, 'download'>): {
13
+ href: string | undefined;
14
+ onClick: (event: ClickEvent) => void;
15
+ };
16
+ /**
17
+ * Create a typed `<Link>` for one router. It renders a real `<a href>` (middle-click,
18
+ * copy link and accessibility keep working) and navigates in place on plain clicks.
19
+ */
20
+ export declare function createLink<Router extends AnyRouter>(router: Router): (<const From extends string = string, const To extends string | undefined = ".">(this: never, props: LinkProps<Router, From, To>) => JSX.Element) & {
21
+ [jsxComponent]: true;
22
+ };
23
+ export {};
package/dist/link.js ADDED
@@ -0,0 +1,79 @@
1
+ import * as _ew_dom from "effectweb/dom";
2
+ const _ew_jsx0 = /*@__PURE__*/ _ew_dom.markup("a");
3
+ import { getUrlScheme, isDangerousProtocol } from "@tanstack/router-core";
4
+ import { jsxComponent } from "effectweb/jsx";
5
+ const options = [
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
+ ];
28
+ /** Resolve a typed destination to an href and a click handler that navigates in place. */
29
+ export function linkTarget(router, props) {
30
+ const explicitHref = props.href;
31
+ const blocked = explicitHref !== undefined && isDangerousProtocol(explicitHref, router.protocolAllowlist);
32
+ const absoluteHref = explicitHref !== undefined && getUrlScheme(explicitHref) ? explicitHref : undefined;
33
+ const location = absoluteHref || blocked ? undefined : router.buildLocation(props);
34
+ const external = absoluteHref !== undefined || location?.external === true;
35
+ const publicHref = absoluteHref ?? location?.publicHref;
36
+ const history = router.history;
37
+ const href = props.disabled || blocked ? undefined : props.reloadDocument || external ? publicHref : history.createHref(publicHref);
38
+ const onClick = (event) => {
39
+ const plain = event.button === 0 && !event.metaKey && !event.altKey && !event.ctrlKey && !event.shiftKey && !event.defaultPrevented;
40
+ if (props.disabled || blocked) {
41
+ event.preventDefault();
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
+ });
77
+ }
78
+ return Object.assign(Link, { [jsxComponent]: true });
79
+ }
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@effectweb/tanstack-router",
3
- "version": "0.5.1",
3
+ "version": "0.7.0",
4
4
  "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/DerpyCrabs/EffectWeb.git",
8
+ "directory": "packages/tanstack-router"
9
+ },
5
10
  "files": [
6
11
  "dist",
7
12
  "README.md",
@@ -24,6 +29,6 @@
24
29
  },
25
30
  "peerDependencies": {
26
31
  "effect": "4.0.0-rc.112",
27
- "effectweb": "^0.5.1"
32
+ "effectweb": "^0.7.0"
28
33
  }
29
34
  }