preact-hashish-router 0.0.16 → 0.0.18
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 +1 -1
- package/dist/A.d.ts +1 -1
- package/dist/A.js +3 -1
- package/dist/ErrorRoute.js +1 -1
- package/dist/Redirect.js +1 -1
- package/dist/Route.js +3 -3
- package/dist/Router.js +1 -1
- package/dist/RouterErrorBoundary.d.ts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/match.js +0 -2
- package/package.json +13 -13
- /package/dist/{useInternalRouter .d.ts → useInternalRouter.d.ts} +0 -0
- /package/dist/{useInternalRouter .js → useInternalRouter.js} +0 -0
package/README.md
CHANGED
package/dist/A.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnchorHTMLAttributes, PropsWithChildren } from "preact/compat";
|
|
2
2
|
export type AProps = PropsWithChildren & AnchorHTMLAttributes;
|
|
3
3
|
export declare const A: import("preact").FunctionalComponent<import("preact/compat").PropsWithoutRef<AProps> & {
|
|
4
|
-
ref?: import("preact").Ref<HTMLAnchorElement
|
|
4
|
+
ref?: import("preact").Ref<HTMLAnchorElement> | undefined;
|
|
5
5
|
}>;
|
package/dist/A.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "preact/compat";
|
|
3
3
|
import { useMemo } from "preact/hooks";
|
|
4
|
-
import { useInternalRouter } from "./useInternalRouter
|
|
4
|
+
import { useInternalRouter } from "./useInternalRouter";
|
|
5
5
|
export const A = forwardRef(({ href, className, ...props }) => {
|
|
6
6
|
const router = useInternalRouter();
|
|
7
7
|
const isActive = useMemo(() => router.path === href?.split("?")[0], [router.path, href]);
|
|
8
8
|
const browserRouterClickAnchorHandler = (e) => {
|
|
9
9
|
e.preventDefault();
|
|
10
10
|
e.stopPropagation();
|
|
11
|
+
if (!href)
|
|
12
|
+
return;
|
|
11
13
|
router.go(href.toString());
|
|
12
14
|
};
|
|
13
15
|
return (_jsx("a", { href: router.type === "browser" ? href : `#${href}`, className: className, "data-route-active": isActive, ...props, onClick: router.type === "browser" ? browserRouterClickAnchorHandler : undefined }));
|
package/dist/ErrorRoute.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
2
|
import { Suspense } from "preact/compat";
|
|
3
|
-
import { useInternalRouter } from "./useInternalRouter
|
|
3
|
+
import { useInternalRouter } from "./useInternalRouter";
|
|
4
4
|
export function ErrorRoute(props) {
|
|
5
5
|
const router = useInternalRouter();
|
|
6
6
|
if (router.itMatch)
|
package/dist/Redirect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
2
|
import { Fragment, useLayoutEffect } from "preact/compat";
|
|
3
|
-
import { useInternalRouter } from "./useInternalRouter
|
|
3
|
+
import { useInternalRouter } from "./useInternalRouter";
|
|
4
4
|
export const Redirect = (props) => {
|
|
5
5
|
const router = useInternalRouter();
|
|
6
6
|
useLayoutEffect(() => {
|
package/dist/Route.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
2
|
import { Suspense, useLayoutEffect, useState } from "preact/compat";
|
|
3
3
|
import { matchRoute } from "./match";
|
|
4
|
-
import { useInternalRouter } from "./useInternalRouter
|
|
4
|
+
import { useInternalRouter } from "./useInternalRouter";
|
|
5
5
|
export function Route(props) {
|
|
6
6
|
const router = useInternalRouter();
|
|
7
7
|
const [render, setRender] = useState(false);
|
|
@@ -17,8 +17,8 @@ export function Route(props) {
|
|
|
17
17
|
if (props.exact === false && matches === undefined) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
router.setParams(matches
|
|
21
|
-
router.setRest(matches
|
|
20
|
+
router.setParams(matches?.params || {});
|
|
21
|
+
router.setRest(matches?.rest);
|
|
22
22
|
router.setItMatch(true);
|
|
23
23
|
setRender(true);
|
|
24
24
|
}, [router.path]);
|
package/dist/Router.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useLayoutEffect, useMemo, useState } from "preact/hooks";
|
|
|
3
3
|
import { router_context } from "./context";
|
|
4
4
|
const get_hash_route = () => location.hash.slice(1) || "/";
|
|
5
5
|
export const Router = (props) => {
|
|
6
|
-
const [path, setPath] = useState();
|
|
6
|
+
const [path, setPath] = useState("");
|
|
7
7
|
const [query, setQuery] = useState("");
|
|
8
8
|
const [params, setParams] = useState({});
|
|
9
9
|
const [rest, setRest] = useState("");
|
package/dist/context.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ export type RouterContext = {
|
|
|
11
11
|
rest: Matches["rest"];
|
|
12
12
|
setRest: (r: Matches["rest"]) => void;
|
|
13
13
|
};
|
|
14
|
-
export declare const router_context: import("preact").Context<RouterContext>;
|
|
14
|
+
export declare const router_context: import("preact").Context<RouterContext | null>;
|
package/dist/match.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* @returns Un objeto Matches si la URL coincide con el patrón; de lo contrario, undefined.
|
|
7
7
|
*/
|
|
8
8
|
export const matchRoute = (url, route, matches = { params: {} }) => {
|
|
9
|
-
// Separa la URL y el patrón en segmentos, eliminando elementos vacíos para facilitar la comparación.
|
|
10
9
|
const urlSegments = url.split("/").filter(Boolean);
|
|
11
10
|
const routeSegments = route.split("/").filter(Boolean);
|
|
12
11
|
// Se itera hasta el máximo número de segmentos entre la URL y el patrón para cubrir ambos casos.
|
|
@@ -39,6 +38,5 @@ export const matchRoute = (url, route, matches = { params: {} }) => {
|
|
|
39
38
|
if (isRest)
|
|
40
39
|
break;
|
|
41
40
|
}
|
|
42
|
-
// Retorna el objeto con los parámetros y/o resto capturados.
|
|
43
41
|
return matches;
|
|
44
42
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-hashish-router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"description": "A simple router for preact",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p ./tsconfig.lib.json",
|
|
9
|
-
"format": "prettier --write src app --ignore-unknown",
|
|
9
|
+
"format": "prettier --write src app --ignore-unknown --cache",
|
|
10
10
|
"app:dev": "vite",
|
|
11
|
-
"prepublishOnly": "npm run build
|
|
11
|
+
"prepublishOnly": "npm run build",
|
|
12
12
|
"push": "npm version patch && git push",
|
|
13
13
|
"push-minor": "npm version minor && git push",
|
|
14
14
|
"push-major": "npm version major && git push"
|
|
@@ -16,9 +16,6 @@
|
|
|
16
16
|
"exports": {
|
|
17
17
|
".": "./dist/index.js"
|
|
18
18
|
},
|
|
19
|
-
"peerDependencies": {
|
|
20
|
-
"preact": "^10.26.2"
|
|
21
|
-
},
|
|
22
19
|
"keywords": [
|
|
23
20
|
"preact",
|
|
24
21
|
"router",
|
|
@@ -37,17 +34,20 @@
|
|
|
37
34
|
"url": "https://github.com/LiasCode/preact-hashish-router"
|
|
38
35
|
},
|
|
39
36
|
"devDependencies": {
|
|
40
|
-
"@preact/preset-vite": "^2.10.
|
|
41
|
-
"@types/node": "^22.
|
|
42
|
-
"prettier": "^3.
|
|
43
|
-
"prettier-plugin-organize-imports": "^4.
|
|
44
|
-
"typescript": "^5.
|
|
45
|
-
"vite": "^6.
|
|
37
|
+
"@preact/preset-vite": "^2.10.2",
|
|
38
|
+
"@types/node": "^22.17.1",
|
|
39
|
+
"prettier": "^3.6.2",
|
|
40
|
+
"prettier-plugin-organize-imports": "^4.2.0",
|
|
41
|
+
"typescript": "^5.9.2",
|
|
42
|
+
"vite": "^6.3.5"
|
|
46
43
|
},
|
|
47
44
|
"files": [
|
|
48
45
|
"dist",
|
|
49
46
|
"LICENSE",
|
|
50
47
|
"package.json",
|
|
51
48
|
"README.md"
|
|
52
|
-
]
|
|
49
|
+
],
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"preact": "^10.27.0"
|
|
52
|
+
}
|
|
53
53
|
}
|
|
File without changes
|
|
File without changes
|