preact-hashish-router 0.1.7 → 0.1.8
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 -0
- package/dist/A.d.ts +1 -1
- package/dist/NotFound.d.ts +1 -1
- package/dist/Route.d.ts +1 -1
- package/dist/Router.d.ts +1 -1
- package/dist/RouterErrorBoundary.d.ts +2 -2
- package/dist/context.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/router/matcher.d.ts +3 -3
- package/package.json +10 -10
package/README.md
CHANGED
package/dist/A.d.ts
CHANGED
package/dist/NotFound.d.ts
CHANGED
package/dist/Route.d.ts
CHANGED
package/dist/Router.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Component, VNode } from "preact";
|
|
2
|
-
import { PropsWithChildren } from "preact/compat";
|
|
1
|
+
import { Component, type VNode } from "preact";
|
|
2
|
+
import type { PropsWithChildren } from "preact/compat";
|
|
3
3
|
export declare class RouterErrorBoundary extends Component<PropsWithChildren & {
|
|
4
4
|
fallback?: VNode<any>;
|
|
5
5
|
}> {
|
package/dist/context.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{forwardRef as
|
|
1
|
+
import{forwardRef as k}from"preact/compat";import{createContext as S}from"preact";import{useContext as p}from"preact/hooks";var s=S({active_path:"",active_route_data:null,params:void 0,searchParams:new URLSearchParams,go(){}}),c=()=>{let e=p(s);if(!e)throw new Error("useHashisherContext should be inside a HashisherContext provider");return e};function M(){let e=p(s);if(!e)throw new Error("useParams should be inside a HashisherContext provider");return e.params}function N(){let e=p(s);if(!e)throw new Error("useSearchParams should be inside a HashisherContext provider");return e.searchParams}var L=()=>{let e=p(s);if(!e)throw new Error("useRouter should be inside a HashisherContext provider");return{path:e.active_path,params:e.params,searchParams:e.searchParams,go:e.go}};import{jsx as U}from"preact/jsx-runtime";var E=k(({href:e,...r},h)=>{let{go:m}=c();if(!e)throw new Error("A: href must be defined");return U("a",{ref:h,href:e,onClick:o=>{o&&o.type==="click"&&(o.ctrlKey||o.metaKey||o.altKey||o.shiftKey||o.button!==0)||(o.preventDefault(),m(e))},...r})});import{Fragment as W,jsx as w}from"preact/jsx-runtime";var A=e=>(z(e.element),w(W,{})),P=w("div",{children:"404 Not Found"}),z=e=>{P=e},l=()=>P;import{addRoute as F,createRouter as K}from"rou3";var f=K(),R=(e,r)=>{F(f,void 0,e,{component:r.element,fallback:r.fallback||null,lazy:!!r.lazy})};import{Fragment as D,jsx as O}from"preact/jsx-runtime";function T(e){return R(e.path,e),O(D,{})}import{useCallback as G,useLayoutEffect as g,useState as u}from"preact/hooks";import{findRoute as I}from"rou3";import{parseURL as v}from"ufo";import{Suspense as B}from"preact/compat";import{jsx as q}from"preact/jsx-runtime";var C=()=>{let{active_route_data:e}=c();return e?e.component===null?l():e.lazy?q(B,{fallback:e.fallback,children:e.component}):e.component:l()};import{jsx as Q,jsxs as X}from"preact/jsx-runtime";var J=e=>{let[r,h]=u("/"),[m,o]=u(void 0),[b,x]=u(new URLSearchParams),[H,_]=u(null),i=G(t=>{let n=v(window.location.href),a=t||"";t===null&&(e.type==="hash"?a=n.hash:a=n.pathname);let d=I(f,void 0,a);if(!d){h(a),x(new URLSearchParams(n.search)),_(null),o(void 0),e.type==="browser"&&window.history.pushState(null,"",a),e.type==="hash"&&(window.location.hash=a);return}h(a),x(new URLSearchParams(n.search)),o({...d.params}),_({...d.data}),e.type==="browser"&&window.history.pushState(null,"",a),e.type==="hash"&&(window.location.hash=a)},[e.type]);g(()=>{if(e.type!=="browser")return;let t=()=>{i(null)};return window.addEventListener("popstate",t),t(),()=>{window.removeEventListener("popstate",t)}},[i,e.type]),g(()=>{if(e.type!=="hash")return;let t=()=>{i(null)};return window.addEventListener("hashchange",t),t(),()=>{window.removeEventListener("hashchange",t)}},[i,e.type]);let V=t=>{let n=v(t).pathname;i(n)};return X(s.Provider,{value:{active_path:r,searchParams:b,params:m,active_route_data:H,go:V},children:[e.children,Q(C,{})]})};import{Component as Y}from"preact";import{jsxs as Z}from"preact/jsx-runtime";var y=class extends Y{state={error:null};static getDerivedStateFromError(r){return{error:r.message}}componentDidCatch(r){this.setState({error:r.message})}render(){return this.state.error?this.props.fallback?this.props.fallback:Z("p",{children:["Oh no! We ran into an error: ",this.state.error]}):this.props.children}};export{E as A,A as NotFound,T as Route,J as Router,y as RouterErrorBoundary,M as useParams,L as useRouter,N as useSearchParams};
|
package/dist/router/matcher.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { VNode } from "preact";
|
|
2
|
-
import { MatchedRoute } from "rou3";
|
|
3
|
-
import { RouteProps } from "../Route";
|
|
1
|
+
import type { VNode } from "preact";
|
|
2
|
+
import { type MatchedRoute } from "rou3";
|
|
3
|
+
import type { RouteProps } from "../Route";
|
|
4
4
|
export type MatcherPayload = {
|
|
5
5
|
component: VNode<any>;
|
|
6
6
|
lazy: boolean;
|
package/package.json
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-hashish-router",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A simple router for preact",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"types": "tsc -p ./tsconfig.json",
|
|
8
|
+
"build": "rm -rf ./dist && bun run types && bun run bundle",
|
|
8
9
|
"bundle": "esbuild ./src/index.ts --bundle --minify --platform=browser --packages=external --outfile=./dist/index.js --format=esm",
|
|
9
10
|
"bundle:watch": "esbuild --watch ./src/index.ts --bundle --minify --platform=browser --packages=external --outfile=./dist/index.js --format=esm",
|
|
10
11
|
"format": "prettier --write ./src --ignore-unknown --cache",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"prepublishOnly": "bun run
|
|
14
|
-
"
|
|
15
|
-
"minor": "bun pm version minor && git push",
|
|
16
|
-
"major": "bun pm version major && git push",
|
|
17
|
-
"release": "changelogen --release --push && bun publish"
|
|
12
|
+
"lint": "biome lint . --fix --unsafe",
|
|
13
|
+
"code:style": "bun run format && bun run lint",
|
|
14
|
+
"prepublishOnly": "bun run build",
|
|
15
|
+
"release": "bun run build && changelogen --release --publish && git push --follow-tags"
|
|
18
16
|
},
|
|
19
17
|
"workspaces": [
|
|
20
18
|
"./examples/*"
|
|
@@ -28,7 +26,8 @@
|
|
|
28
26
|
"simple",
|
|
29
27
|
"routing",
|
|
30
28
|
"browser",
|
|
31
|
-
"hash"
|
|
29
|
+
"hash",
|
|
30
|
+
"radix tree"
|
|
32
31
|
],
|
|
33
32
|
"author": {
|
|
34
33
|
"name": "LiasCode",
|
|
@@ -52,7 +51,8 @@
|
|
|
52
51
|
"preact": "^10.27.0"
|
|
53
52
|
},
|
|
54
53
|
"devDependencies": {
|
|
55
|
-
"@
|
|
54
|
+
"@biomejs/biome": "1.8.3",
|
|
55
|
+
"@types/node": "^22.18.0",
|
|
56
56
|
"changelogen": "^0.6.2",
|
|
57
57
|
"esbuild": "^0.25.9",
|
|
58
58
|
"prettier": "^3.6.2",
|