@solidjs/router 2.0.0-next.36 → 2.0.0-next.38

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/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Component, Signal } from "solid-js";
1
+ import type { Component, Owner, Signal } from "solid-js";
2
2
  import type { JSX, ResponseEnvelope } from "@solidjs/web";
3
3
  declare module "@solidjs/web" {
4
4
  interface RequestEvent {
@@ -118,13 +118,13 @@ export interface LocationWrite<S = unknown> extends Omit<LocationChange<S>, "val
118
118
  export interface RouterIntegration {
119
119
  signal: [get: () => LocationChange, set: (next: LocationWrite) => void];
120
120
  /**
121
- * The navigation written but not yet committed to history — the window
122
- * between its location write and the settle that pushes it. A destination
123
- * in that window was never shown, so a `navigate()` issued inside it (a
124
- * guard redirecting as the held route lands) is a hop of that navigation
125
- * rather than a new one, exactly as one issued while it is still pending.
121
+ * Whether a navigation write's settle has run: Solid's `onSettled`,
122
+ * registered beside the write, fired for the transition that carried it.
123
+ * Until then the write is in flight: its destination was never shown, so a
124
+ * `navigate()` issued meanwhile (a guard redirecting as the held route
125
+ * lands) is a hop of that navigation rather than a new one.
126
126
  */
127
- inflight?: () => LocationChange | undefined;
127
+ settled?: (write: LocationChange) => boolean;
128
128
  utils?: Partial<RouterUtils>;
129
129
  }
130
130
  export type Intent = "initial" | "native" | "navigate" | "preload";
@@ -330,19 +330,54 @@ export interface RouterContext {
330
330
  params: Params;
331
331
  wrapParams: (getParams: () => Params) => Params;
332
332
  navigatorFactory: NavigatorFactory;
333
- isRouting: () => boolean;
334
333
  /** @internal Intent of the in-flight canonical location transition. */
335
334
  intent?: () => Intent | undefined;
336
- /** The target of the in-flight navigation transition, if any. Not reactive. */
337
- readonly pendingTarget?: LocationChange;
335
+ /** @internal The integration's location signal: the last flushed write. */
336
+ _source: () => LocationChange;
337
+ /** @internal The owner the router's own computations live under. */
338
+ _owner: Owner | null;
339
+ /** @internal The owner route components and their `preload` functions run under. */
340
+ _routeOwner: () => Owner;
341
+ /** @internal Route matches for a pathname, after `transformUrl`. */
342
+ _match: (pathname: string) => RouteMatch[];
338
343
  matches: () => RouteMatch[];
339
344
  renderPath(path: string): string;
340
345
  parsePath(str: string): string;
341
346
  beforeLeave: BeforeLeaveSlot;
342
- preloadRoute: (url: URL, preloadData?: boolean) => void;
343
347
  singleFlight: boolean;
344
348
  submissions: Signal<Submission<any, any>[]>;
345
349
  }
350
+ /**
351
+ * A plugin for the router's `links` option that extends the state it writes
352
+ * onto claimed anchors. Built once per router with its base path. The router
353
+ * ships `pendingLinks`, which adds `data-pending`.
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * const Router = createRouter({ routes, links: pendingLinks });
358
+ * ```
359
+ */
360
+ export type LinksPlugin = (router: RouterContext, base: string) => {
361
+ /** The reactive read the claims sweep re-runs on. */
362
+ track(): unknown;
363
+ /** Whether an anchor resolving to `target` is the in-flight destination; read when `track()` is truthy. */
364
+ pending(target: string | undefined): boolean;
365
+ };
366
+ /** @internal What the router hands a link preload strategy. */
367
+ export interface LinkPreloadContext {
368
+ /** The router-managed anchor on an event's composed path, with its URL. */
369
+ anchor(evt: Event): readonly [HTMLAnchorElement | SVGAElement, URL] | undefined;
370
+ /** An anchor's URL, resolved now, when the router manages it. */
371
+ url(a: HTMLAnchorElement | SVGAElement): URL | undefined;
372
+ /** Warm `url`: route code always, `preload` functions too when `data` is true. */
373
+ preload(url: URL, data: boolean): void;
374
+ }
375
+ /**
376
+ * A link preload strategy for the router's `preloadLinks` option, such as
377
+ * `intentPreload()`. Client-only: runs once under the router's owner and
378
+ * cleans up with it.
379
+ */
380
+ export type LinkPreload = (ctx: LinkPreloadContext) => void;
346
381
  export interface BeforeLeaveEventArgs {
347
382
  from: Location;
348
383
  to: string | number;
package/dist/utils.d.ts CHANGED
@@ -15,19 +15,20 @@ export declare const comparablePath: (path: string) => string;
15
15
  */
16
16
  export declare function isUnderBase(pathname: string, base: string): boolean;
17
17
  /**
18
- * The link-state rule shared by claimed anchors and `useLinkState`, given
19
- * the location and a link's already-resolved target (path, optional query
20
- * and hash):
18
+ * The link-state rule shared by claimed anchors and `useLinkState`, bound to
19
+ * a location so links matched against the same one share its parse. The
20
+ * returned matcher takes a link's already-resolved target (path, optional
21
+ * query and hash):
21
22
  *
22
23
  * - `current` — same pathname and same query (parameter order and hash aside)
23
24
  * - `active` — same pathname or one under it; the router's root (`base`, or
24
25
  * `/` without one) only matches exactly, since it is a prefix of every
25
26
  * page. `end` makes every link exact-only.
26
27
  */
27
- export declare function matchLink(location: {
28
+ export declare function linkMatcher({ pathname, search }: {
28
29
  pathname: string;
29
30
  search: string;
30
- }, target: string | undefined, base: string, end?: boolean): {
31
+ }, base: string, end?: boolean): (target: string | undefined) => {
31
32
  active: boolean;
32
33
  current: boolean;
33
34
  };
package/dist/utils.js CHANGED
@@ -32,26 +32,30 @@ const comparableQuery = (search) => {
32
32
  return params.toString();
33
33
  };
34
34
  /**
35
- * The link-state rule shared by claimed anchors and `useLinkState`, given
36
- * the location and a link's already-resolved target (path, optional query
37
- * and hash):
35
+ * The link-state rule shared by claimed anchors and `useLinkState`, bound to
36
+ * a location so links matched against the same one share its parse. The
37
+ * returned matcher takes a link's already-resolved target (path, optional
38
+ * query and hash):
38
39
  *
39
40
  * - `current` — same pathname and same query (parameter order and hash aside)
40
41
  * - `active` — same pathname or one under it; the router's root (`base`, or
41
42
  * `/` without one) only matches exactly, since it is a prefix of every
42
43
  * page. `end` makes every link exact-only.
43
44
  */
44
- export function matchLink(location, target, base, end) {
45
- if (target === undefined)
46
- return { active: false, current: false };
47
- const loc = comparablePath(location.pathname);
48
- const path = comparablePath(target);
49
- const exact = loc === path;
50
- const hashless = target.split("#", 1)[0];
51
- const q = hashless.indexOf("?");
52
- return {
53
- active: exact || (!end && path !== "" && path !== comparablePath(base) && loc.startsWith(path + "/")),
54
- current: exact && comparableQuery(location.search) === comparableQuery(q < 0 ? "" : hashless.slice(q))
45
+ export function linkMatcher({ pathname, search }, base, end) {
46
+ const loc = comparablePath(pathname);
47
+ const root = comparablePath(base);
48
+ return (target) => {
49
+ if (target === undefined)
50
+ return { active: false, current: false };
51
+ const path = comparablePath(target);
52
+ const exact = loc === path;
53
+ const hashless = target.split("#", 1)[0];
54
+ const q = hashless.indexOf("?");
55
+ return {
56
+ active: exact || (!end && path !== "" && path !== root && loc.startsWith(path + "/")),
57
+ current: exact && comparableQuery(search) === comparableQuery(q < 0 ? "" : hashless.slice(q))
58
+ };
55
59
  };
56
60
  }
57
61
  export function resolvePath(base, path, from) {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "Ryan Turnquist"
7
7
  ],
8
8
  "license": "MIT",
9
- "version": "2.0.0-next.36",
9
+ "version": "2.0.0-next.38",
10
10
  "homepage": "https://github.com/solidjs/solid-router#readme",
11
11
  "repository": {
12
12
  "type": "git",
@@ -37,23 +37,23 @@
37
37
  "@rollup/plugin-babel": "6.0.4",
38
38
  "@rollup/plugin-node-resolve": "15.3.0",
39
39
  "@rollup/plugin-terser": "0.4.4",
40
- "@solidjs/vite-plugin": "3.0.0-next.35",
41
- "@solidjs/web": "^2.0.0-rc.13",
40
+ "@solidjs/vite-plugin": "3.0.0-next.47",
41
+ "@solidjs/web": "^2.0.0-rc.14",
42
42
  "@types/jest": "^29.5.14",
43
43
  "@types/node": "^22.10.0",
44
44
  "babel-preset-solid": "^2.0.0-rc.2",
45
45
  "jsdom": "^25.0.1",
46
46
  "prettier": "^3.4.1",
47
47
  "rollup": "^4.27.4",
48
- "solid-js": "^2.0.0-rc.13",
48
+ "solid-js": "^2.0.0-rc.14",
49
49
  "typescript": "^5.7.2",
50
50
  "vite": "^8.2.2",
51
51
  "vitest": "^4.1.11"
52
52
  },
53
53
  "peerDependencies": {
54
- "@solidjs/web": "^2.0.0-rc.13",
54
+ "@solidjs/web": "^2.0.0-rc.14",
55
55
  "filesystem-routing": ">=0.4.0",
56
- "solid-js": "^2.0.0-rc.13"
56
+ "solid-js": "^2.0.0-rc.14"
57
57
  },
58
58
  "peerDependenciesMeta": {
59
59
  "filesystem-routing": {