@solidjs/router 0.10.9 → 0.11.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 +8 -8
- package/dist/components.d.ts +1 -1
- package/dist/components.jsx +7 -7
- package/dist/data/action.d.ts +1 -1
- package/dist/data/action.js +4 -4
- package/dist/data/cache.d.ts +2 -4
- package/dist/data/cache.js +56 -52
- package/dist/data/events.d.ts +1 -1
- package/dist/data/events.js +7 -5
- package/dist/data/index.d.ts +4 -4
- package/dist/data/index.js +4 -4
- package/dist/data/response.d.ts +3 -2
- package/dist/data/response.js +13 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +147 -82
- package/dist/index.jsx +6 -6
- package/dist/lifecycle.d.ts +4 -1
- package/dist/lifecycle.js +37 -0
- package/dist/routers/HashRouter.d.ts +1 -1
- package/dist/routers/HashRouter.js +11 -6
- package/dist/routers/MemoryRouter.d.ts +2 -2
- package/dist/routers/MemoryRouter.js +1 -1
- package/dist/routers/Router.d.ts +1 -1
- package/dist/routers/Router.js +23 -10
- package/dist/routers/StaticRouter.d.ts +1 -1
- package/dist/routers/StaticRouter.js +1 -1
- package/dist/routers/components.d.ts +1 -1
- package/dist/routers/components.jsx +10 -9
- package/dist/routers/createRouter.d.ts +2 -2
- package/dist/routers/createRouter.js +1 -1
- package/dist/routers/index.d.ts +11 -11
- package/dist/routers/index.js +6 -6
- package/dist/routing.d.ts +2 -2
- package/dist/routing.js +12 -10
- package/dist/types.d.ts +13 -4
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +1 -0
- package/package.json +18 -21
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Component, JSX } from "solid-js";
|
|
2
|
-
import type { MatchFilters, RouteLoadFunc, RouteDefinition, RouterIntegration, RouteSectionProps } from "../types";
|
|
2
|
+
import type { MatchFilters, RouteLoadFunc, RouteDefinition, RouterIntegration, RouteSectionProps } from "../types.ts";
|
|
3
3
|
export type BaseRouterProps = {
|
|
4
4
|
base?: string;
|
|
5
5
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*@refresh skip*/
|
|
2
2
|
import { getRequestEvent, isServer } from "solid-js/web";
|
|
3
3
|
import { children, createMemo, createRoot, mergeProps, on, Show } from "solid-js";
|
|
4
|
-
import { createBranches, createRouteContext, createRouterContext, getRouteMatches, RouteContextObj, RouterContextObj } from "../routing";
|
|
5
|
-
import { createMemoObject } from "../utils";
|
|
4
|
+
import { createBranches, createRouteContext, createRouterContext, getRouteMatches, RouteContextObj, RouterContextObj } from "../routing.js";
|
|
5
|
+
import { createMemoObject } from "../utils.js";
|
|
6
6
|
export const createRouterComponent = (router) => (props) => {
|
|
7
7
|
const { base } = props;
|
|
8
8
|
const routeDefs = children(() => props.children);
|
|
@@ -18,13 +18,14 @@ function Routes(props) {
|
|
|
18
18
|
if (isServer) {
|
|
19
19
|
const e = getRequestEvent();
|
|
20
20
|
e &&
|
|
21
|
-
(e.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
((e.router || (e.router = {})).matches ||
|
|
22
|
+
(e.router.matches = matches().map(({ route, path, params }) => ({
|
|
23
|
+
path: route.originalPath,
|
|
24
|
+
pattern: route.pattern,
|
|
25
|
+
match: path,
|
|
26
|
+
params,
|
|
27
|
+
metadata: route.metadata
|
|
28
|
+
}))));
|
|
28
29
|
}
|
|
29
30
|
const params = createMemoObject(() => {
|
|
30
31
|
const m = matches();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { LocationChange, RouterContext, RouterUtils } from "../types";
|
|
1
|
+
import type { LocationChange, RouterContext, RouterUtils } from "../types.ts";
|
|
2
2
|
export declare function createRouter(config: {
|
|
3
3
|
get: () => string | LocationChange;
|
|
4
4
|
set: (next: LocationChange) => void;
|
|
5
5
|
init?: (notify: (value?: string | LocationChange) => void) => () => void;
|
|
6
6
|
create?: (router: RouterContext) => void;
|
|
7
7
|
utils?: Partial<RouterUtils>;
|
|
8
|
-
}): (props: import("./components").BaseRouterProps) => import("solid-js").JSX.Element;
|
|
8
|
+
}): (props: import("./components.jsx").BaseRouterProps) => import("solid-js").JSX.Element;
|
|
9
9
|
export declare function bindEvent(target: EventTarget, type: string, handler: EventListener): () => void;
|
|
10
10
|
export declare function scrollToHash(hash: string, fallbackTop?: boolean): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSignal, onCleanup } from "solid-js";
|
|
2
|
-
import { createRouterComponent } from "./components";
|
|
2
|
+
import { createRouterComponent } from "./components.jsx";
|
|
3
3
|
function intercept([value, setValue], get, set) {
|
|
4
4
|
return [get ? () => get(value()) : value, set ? (v) => setValue(set(v)) : setValue];
|
|
5
5
|
}
|
package/dist/routers/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { Route } from "./components";
|
|
2
|
-
export type { BaseRouterProps, RouteProps } from "./components";
|
|
3
|
-
export { createRouter } from "./createRouter";
|
|
4
|
-
export { Router } from "./Router";
|
|
5
|
-
export type { RouterProps } from "./Router";
|
|
6
|
-
export { HashRouter } from "./HashRouter";
|
|
7
|
-
export type { HashRouterProps } from "./HashRouter";
|
|
8
|
-
export { MemoryRouter, createMemoryHistory } from "./MemoryRouter";
|
|
9
|
-
export type { MemoryRouterProps, MemoryHistory } from "./MemoryRouter";
|
|
10
|
-
export { StaticRouter } from "./StaticRouter";
|
|
11
|
-
export type { StaticRouterProps } from "./StaticRouter";
|
|
1
|
+
export { Route } from "./components.jsx";
|
|
2
|
+
export type { BaseRouterProps, RouteProps } from "./components.jsx";
|
|
3
|
+
export { createRouter } from "./createRouter.js";
|
|
4
|
+
export { Router } from "./Router.js";
|
|
5
|
+
export type { RouterProps } from "./Router.js";
|
|
6
|
+
export { HashRouter } from "./HashRouter.js";
|
|
7
|
+
export type { HashRouterProps } from "./HashRouter.js";
|
|
8
|
+
export { MemoryRouter, createMemoryHistory } from "./MemoryRouter.js";
|
|
9
|
+
export type { MemoryRouterProps, MemoryHistory } from "./MemoryRouter.js";
|
|
10
|
+
export { StaticRouter } from "./StaticRouter.js";
|
|
11
|
+
export type { StaticRouterProps } from "./StaticRouter.js";
|
package/dist/routers/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { Route } from "./components";
|
|
2
|
-
export { createRouter } from "./createRouter";
|
|
3
|
-
export { Router } from "./Router";
|
|
4
|
-
export { HashRouter } from "./HashRouter";
|
|
5
|
-
export { MemoryRouter, createMemoryHistory } from "./MemoryRouter";
|
|
6
|
-
export { StaticRouter } from "./StaticRouter";
|
|
1
|
+
export { Route } from "./components.jsx";
|
|
2
|
+
export { createRouter } from "./createRouter.js";
|
|
3
|
+
export { Router } from "./Router.js";
|
|
4
|
+
export { HashRouter } from "./HashRouter.js";
|
|
5
|
+
export { MemoryRouter, createMemoryHistory } from "./MemoryRouter.js";
|
|
6
|
+
export { StaticRouter } from "./StaticRouter.js";
|
package/dist/routing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSX, Accessor } from "solid-js";
|
|
2
|
-
import type { BeforeLeaveEventArgs, Branch, Intent, Location, MatchFilters, NavigateOptions, Navigator, Params, Route, RouteContext, RouteDefinition, RouteMatch, RouterContext, RouterIntegration, SetParams } from "./types";
|
|
2
|
+
import type { BeforeLeaveEventArgs, Branch, Intent, Location, MatchFilters, NavigateOptions, Navigator, Params, Route, RouteContext, RouteDefinition, RouteMatch, RouterContext, RouterIntegration, SetParams } from "./types.js";
|
|
3
3
|
export declare const RouterContextObj: import("solid-js").Context<RouterContext | undefined>;
|
|
4
4
|
export declare const RouteContextObj: import("solid-js").Context<RouteContext | undefined>;
|
|
5
5
|
export declare const useRouter: () => RouterContext;
|
|
@@ -9,7 +9,7 @@ export declare const useHref: (to: () => string | undefined) => Accessor<string
|
|
|
9
9
|
export declare const useNavigate: () => Navigator;
|
|
10
10
|
export declare const useLocation: <S = unknown>() => Location<S>;
|
|
11
11
|
export declare const useIsRouting: () => () => boolean;
|
|
12
|
-
export declare const useMatch: <S extends string>(path: () => S, matchFilters?: MatchFilters<S> | undefined) => Accessor<import("./types").PathMatch | undefined>;
|
|
12
|
+
export declare const useMatch: <S extends string>(path: () => S, matchFilters?: MatchFilters<S> | undefined) => Accessor<import("./types.js").PathMatch | undefined>;
|
|
13
13
|
export declare const useParams: <T extends Params>() => T;
|
|
14
14
|
export declare const useSearchParams: <T extends Params>() => [Partial<T>, (params: SetParams, options?: Partial<NavigateOptions>) => void];
|
|
15
15
|
export declare const useBeforeLeave: (listener: (e: BeforeLeaveEventArgs) => void) => void;
|
package/dist/routing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createComponent, createContext, createMemo, createRenderEffect, createSignal, on, onCleanup, untrack, useContext, startTransition, resetErrorBoundaries } from "solid-js";
|
|
2
2
|
import { isServer, getRequestEvent } from "solid-js/web";
|
|
3
|
-
import { createBeforeLeave } from "./lifecycle";
|
|
4
|
-
import { createMemoObject, extractSearchParams, invariant, resolvePath, createMatcher, joinPaths, scoreRoute, mergeSearchString, expandOptionals } from "./utils";
|
|
3
|
+
import { createBeforeLeave } from "./lifecycle.js";
|
|
4
|
+
import { mockBase, createMemoObject, extractSearchParams, invariant, resolvePath, createMatcher, joinPaths, scoreRoute, mergeSearchString, expandOptionals } from "./utils.js";
|
|
5
5
|
const MAX_REDIRECTS = 100;
|
|
6
6
|
export const RouterContextObj = createContext();
|
|
7
7
|
export const RouteContextObj = createContext();
|
|
@@ -68,9 +68,12 @@ export function createRoutes(routeDef, base = "") {
|
|
|
68
68
|
for (const originalPath of expandOptionals(path)) {
|
|
69
69
|
const path = joinPaths(base, originalPath);
|
|
70
70
|
let pattern = isLeaf ? path : path.split("/*", 1)[0];
|
|
71
|
-
pattern = pattern
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
pattern = pattern
|
|
72
|
+
.split("/")
|
|
73
|
+
.map((s) => {
|
|
74
|
+
return s.startsWith(":") || s.startsWith("*") ? s : encodeURIComponent(s);
|
|
75
|
+
})
|
|
76
|
+
.join("/");
|
|
74
77
|
acc.push({
|
|
75
78
|
...shared,
|
|
76
79
|
originalPath,
|
|
@@ -140,7 +143,7 @@ export function getRouteMatches(branches, location) {
|
|
|
140
143
|
return [];
|
|
141
144
|
}
|
|
142
145
|
export function createLocation(path, state) {
|
|
143
|
-
const origin = new URL(
|
|
146
|
+
const origin = new URL(mockBase);
|
|
144
147
|
const url = createMemo(prev => {
|
|
145
148
|
const path_ = path();
|
|
146
149
|
try {
|
|
@@ -252,7 +255,7 @@ export function createRouterContext(integration, getBranches, options = {}) {
|
|
|
252
255
|
// A delta of 0 means stay at the current location, so it is ignored
|
|
253
256
|
}
|
|
254
257
|
else if (utils.go) {
|
|
255
|
-
|
|
258
|
+
utils.go(to);
|
|
256
259
|
}
|
|
257
260
|
else {
|
|
258
261
|
console.warn("Router integration does not support relative routing");
|
|
@@ -276,8 +279,7 @@ export function createRouterContext(integration, getBranches, options = {}) {
|
|
|
276
279
|
if (resolvedTo !== current || nextState !== state()) {
|
|
277
280
|
if (isServer) {
|
|
278
281
|
const e = getRequestEvent();
|
|
279
|
-
e &&
|
|
280
|
-
(e.response = new Response(null, { status: 302, headers: { Location: resolvedTo } }));
|
|
282
|
+
e && (e.response = { status: 302, headers: new Headers({ Location: resolvedTo }) });
|
|
281
283
|
setSource({ value: resolvedTo, replace, scroll, state: nextState });
|
|
282
284
|
}
|
|
283
285
|
else if (beforeLeave.confirm(resolvedTo, options)) {
|
|
@@ -347,7 +349,7 @@ export function createRouterContext(integration, getBranches, options = {}) {
|
|
|
347
349
|
}
|
|
348
350
|
function initFromFlash() {
|
|
349
351
|
const e = getRequestEvent();
|
|
350
|
-
return e && e.
|
|
352
|
+
return e && e.router && e.router.submission ? [e.router.submission] : [];
|
|
351
353
|
}
|
|
352
354
|
}
|
|
353
355
|
export function createRouteContext(router, parent, outlet, match, params) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import type { Component, JSX, Signal } from "solid-js";
|
|
2
2
|
declare module "solid-js/web" {
|
|
3
3
|
interface RequestEvent {
|
|
4
|
-
response?:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
response?: {
|
|
5
|
+
status?: number;
|
|
6
|
+
statusText?: string;
|
|
7
|
+
headers: Headers;
|
|
8
|
+
};
|
|
9
|
+
router?: {
|
|
10
|
+
matches?: OutputMatch[];
|
|
11
|
+
cache?: Map<string, CacheEntry>;
|
|
12
|
+
submission?: Submission<any, any>;
|
|
13
|
+
};
|
|
8
14
|
serverOnly?: boolean;
|
|
9
15
|
}
|
|
10
16
|
}
|
|
@@ -151,3 +157,6 @@ export type Submission<T, U> = {
|
|
|
151
157
|
export interface MaybePreloadableComponent extends Component {
|
|
152
158
|
preload?: () => void;
|
|
153
159
|
}
|
|
160
|
+
export type CacheEntry = [number, any, Intent | undefined, Signal<number> & {
|
|
161
|
+
count: number;
|
|
162
|
+
}];
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { MatchFilters, Params, PathMatch, Route, SetParams } from "./types";
|
|
1
|
+
import type { MatchFilters, Params, PathMatch, Route, SetParams } from "./types.ts";
|
|
2
|
+
export declare const mockBase = "http://sr";
|
|
2
3
|
export declare const redirectStatusCodes: Set<number>;
|
|
3
4
|
export declare function normalizePath(path: string, omitSlash?: boolean): string;
|
|
4
5
|
export declare function resolvePath(base: string, path: string, from?: string): string | undefined;
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createMemo, getOwner, runWithOwner } from "solid-js";
|
|
2
2
|
const hasSchemeRegex = /^(?:[a-z0-9]+:)?\/\//i;
|
|
3
3
|
const trimPathRegex = /^\/+|(\/)\/+$/g;
|
|
4
|
+
export const mockBase = "http://sr";
|
|
4
5
|
export const redirectStatusCodes = new Set([204, 301, 302, 303, 307, 308]);
|
|
5
6
|
export function normalizePath(path, omitSlash = false) {
|
|
6
7
|
const s = path.replace(trimPathRegex, "$1");
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"Ryan Turnquist"
|
|
7
7
|
],
|
|
8
8
|
"license": "MIT",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.11.0",
|
|
10
10
|
"homepage": "https://github.com/solidjs/solid-router#readme",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -29,34 +29,31 @@
|
|
|
29
29
|
],
|
|
30
30
|
"sideEffects": false,
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@babel/core": "^7.
|
|
33
|
-
"@babel/preset-typescript": "^7.
|
|
34
|
-
"@
|
|
35
|
-
"@rollup/plugin-
|
|
36
|
-
"@rollup/plugin-
|
|
37
|
-
"@
|
|
38
|
-
"@types/
|
|
39
|
-
"
|
|
32
|
+
"@babel/core": "^7.23.9",
|
|
33
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
34
|
+
"@changesets/cli": "^2.27.1",
|
|
35
|
+
"@rollup/plugin-babel": "6.0.4",
|
|
36
|
+
"@rollup/plugin-node-resolve": "15.2.3",
|
|
37
|
+
"@rollup/plugin-terser": "0.4.4",
|
|
38
|
+
"@types/jest": "^29.5.11",
|
|
39
|
+
"@types/node": "^20.11.14",
|
|
40
40
|
"babel-preset-solid": "^1.8.6",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"rollup": "^3.7.5",
|
|
45
|
-
"solid-jest": "^0.2.0",
|
|
41
|
+
"jsdom": "^24.0.0",
|
|
42
|
+
"prettier": "^2.7.0",
|
|
43
|
+
"rollup": "^4.9.6",
|
|
46
44
|
"solid-js": "^1.8.7",
|
|
47
|
-
"typescript": "^5.
|
|
45
|
+
"typescript": "^5.3.3",
|
|
46
|
+
"vite": "^5.0.12",
|
|
47
|
+
"vite-plugin-solid": "^2.9.1",
|
|
48
|
+
"vitest": "^1.2.2"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
51
|
"solid-js": "^1.8.6"
|
|
51
52
|
},
|
|
52
|
-
"jest": {
|
|
53
|
-
"preset": "solid-jest/preset/browser"
|
|
54
|
-
},
|
|
55
53
|
"scripts": {
|
|
56
54
|
"build": "tsc && rollup -c",
|
|
57
|
-
"test": "
|
|
58
|
-
"test:watch": "
|
|
59
|
-
"test:coverage": "jest --coverage && npm run test:types",
|
|
55
|
+
"test": "vitest run && npm run test:types",
|
|
56
|
+
"test:watch": "vitest",
|
|
60
57
|
"test:types": "tsc --project tsconfig.test.json",
|
|
61
58
|
"pretty": "prettier --write \"{src,test}/**/*.{ts,tsx}\""
|
|
62
59
|
}
|