@farbenmeer/router 0.6.0 → 0.6.2
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 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/mock-history.d.ts +1 -0
- package/dist/mock-history.d.ts.map +1 -1
- package/dist/mock-history.js +10 -0
- package/dist/path.js +2 -2
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +12 -1
- package/dist/switch.js +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/mock-history.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export declare function mockHistory(pathname?: string): {
|
|
|
4
4
|
pushState: import("vitest").Mock<(_state: any, _unused: string, url: string) => void>;
|
|
5
5
|
replaceState: import("vitest").Mock<(_state: any, _unused: string, url: string) => void>;
|
|
6
6
|
};
|
|
7
|
+
back(): void;
|
|
7
8
|
};
|
|
8
9
|
//# sourceMappingURL=mock-history.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-history.d.ts","sourceRoot":"","sources":["../src/mock-history.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,QAAQ,SAAM;;;
|
|
1
|
+
{"version":3,"file":"mock-history.d.ts","sourceRoot":"","sources":["../src/mock-history.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,QAAQ,SAAM;;;kDAOV,GAAG,WAAW,MAAM,OAAO,MAAM;qDAI9B,GAAG,WAAW,MAAM,OAAO,MAAM;;;EAanE"}
|
package/dist/mock-history.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { vi } from "vitest";
|
|
2
2
|
export function mockHistory(pathname = "/") {
|
|
3
3
|
const location = new URL(pathname, "http://localhost:3000");
|
|
4
|
+
const stack = [location.href];
|
|
4
5
|
return {
|
|
5
6
|
location,
|
|
6
7
|
history: {
|
|
7
8
|
pushState: vi.fn((_state, _unused, url) => {
|
|
8
9
|
location.href = new URL(url, location.href).href;
|
|
10
|
+
stack.push(location.href);
|
|
9
11
|
}),
|
|
10
12
|
replaceState: vi.fn((_state, _unused, url) => {
|
|
11
13
|
location.href = new URL(url, location.href).href;
|
|
14
|
+
stack[stack.length - 1] = location.href;
|
|
12
15
|
}),
|
|
13
16
|
},
|
|
17
|
+
back() {
|
|
18
|
+
if (stack.length > 1) {
|
|
19
|
+
stack.pop();
|
|
20
|
+
location.href = stack[stack.length - 1];
|
|
21
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
22
|
+
}
|
|
23
|
+
},
|
|
14
24
|
};
|
|
15
25
|
}
|
package/dist/path.js
CHANGED
|
@@ -27,7 +27,7 @@ export function compilePathRegex(path) {
|
|
|
27
27
|
const pattern = path
|
|
28
28
|
.replaceAll(/\*(\w+)/g, "(?<$1>.+)") // *name -> named capture group
|
|
29
29
|
.replaceAll(/\*/g, ".+") // * -> match everything including /
|
|
30
|
-
.replaceAll(/:(\w+)/g, "(?<$1>[
|
|
30
|
+
.replaceAll(/:(\w+)/g, "(?<$1>[^\\/]+)"); // :param -> named capture group
|
|
31
31
|
// If pattern contains a wildcard, it already matches everything - use exact match
|
|
32
32
|
if (path.includes("*")) {
|
|
33
33
|
return new RegExp(`^(${pattern})$`);
|
|
@@ -43,7 +43,7 @@ export function compileExactPathRegex(path) {
|
|
|
43
43
|
const pattern = path
|
|
44
44
|
.replaceAll(/\*(\w+)/g, "(?<$1>.+)") // *name -> named capture group
|
|
45
45
|
.replaceAll(/\*/g, ".+") // * -> match everything including /
|
|
46
|
-
.replaceAll(/:(\w+)/g, "(?<$1>[
|
|
46
|
+
.replaceAll(/:(\w+)/g, "(?<$1>[^\\/]+)"); // :param -> named capture group
|
|
47
47
|
return new RegExp(`^(${pattern})$`);
|
|
48
48
|
}
|
|
49
49
|
export function buildFullPath(parentPath, path) {
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAUtF,UAAU,KAAK;IACb,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,OAAO,CAAC,EAAE;QACR,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;QAC5D,YAAY,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;KAChE,CAAC;CACH;AAED,wBAAgB,MAAM,CAAC,EACrB,OAAwB,EACxB,QAA0B,EAC1B,QAAQ,GACT,EAAE,KAAK,2CAoDP"}
|
package/dist/router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { startTransition, useMemo, useState } from "react";
|
|
2
|
+
import { startTransition, useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { HashContext, PathnameContext, RouterContext, SearchParamsContext, } from "./context";
|
|
4
4
|
import { ImmutableSearchParams } from "./immutable-search-params";
|
|
5
5
|
import { removeTrailingSlash } from "./path";
|
|
@@ -7,6 +7,17 @@ export function Router({ history = window.history, location = window.location, c
|
|
|
7
7
|
const [pathname, setPathname] = useState(removeTrailingSlash(location.pathname));
|
|
8
8
|
const [searchParams, setSearchParams] = useState(new ImmutableSearchParams(location.search));
|
|
9
9
|
const [hash, setHash] = useState(location.hash);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const handlePopstate = () => {
|
|
12
|
+
startTransition(() => {
|
|
13
|
+
setPathname(removeTrailingSlash(location.pathname));
|
|
14
|
+
setSearchParams(new ImmutableSearchParams(location.search));
|
|
15
|
+
setHash(location.hash);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
window.addEventListener("popstate", handlePopstate);
|
|
19
|
+
return () => window.removeEventListener("popstate", handlePopstate);
|
|
20
|
+
}, [location]);
|
|
10
21
|
const routerContextValue = useMemo(() => ({
|
|
11
22
|
push: (url) => {
|
|
12
23
|
history.pushState(null, "", url);
|
package/dist/switch.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farbenmeer/router",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Michel Smola",
|
|
6
6
|
"email": "michel.smola@farbenmeer.de"
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"@vitest/browser-playwright": "^4.0.16",
|
|
26
26
|
"react": "^19.1.1",
|
|
27
27
|
"vitest": "^4.0.16",
|
|
28
|
+
"playwright": "^1.58.1",
|
|
28
29
|
"vitest-browser-react": "^2.0.2"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
@@ -34,6 +35,7 @@
|
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build": "tsc -p tsconfig.build.json",
|
|
36
37
|
"release": "pnpm run build && pnpm publish",
|
|
37
|
-
"test": "vitest"
|
|
38
|
+
"test": "vitest",
|
|
39
|
+
"ci-setup": "playwright install --with-deps"
|
|
38
40
|
}
|
|
39
41
|
}
|