@solidjs/router
Advanced tools
Comparing version 0.14.7 to 0.14.8
@@ -22,3 +22,3 @@ import { createMemo, mergeProps, splitProps } from "solid-js"; | ||
const path = normalizePath(to_.split(/[?#]/, 1)[0]).toLowerCase(); | ||
const loc = normalizePath(location.pathname).toLowerCase(); | ||
const loc = decodeURI(normalizePath(location.pathname).toLowerCase()); | ||
return [props.end ? path === loc : loc.startsWith(path + "/") || loc === path, path === loc]; | ||
@@ -25,0 +25,0 @@ }); |
@@ -9,3 +9,4 @@ import { delegateEvents } from "solid-js/web"; | ||
const navigateFromRoute = router.navigatorFactory(router.base); | ||
let preloadTimeout = {}; | ||
let preloadTimeout; | ||
let lastElement; | ||
function isSvg(el) { | ||
@@ -61,36 +62,19 @@ return el.namespaceURI === "http://www.w3.org/2000/svg"; | ||
const [a, url] = res; | ||
if (typeof transformUrl === "function") { | ||
url.pathname = transformUrl(url.pathname); | ||
} | ||
if (!preloadTimeout[url.pathname]) | ||
router.preloadRoute(url, { preloadData: a.getAttribute("preload") !== "false" }); | ||
transformUrl && (url.pathname = transformUrl(url.pathname)); | ||
router.preloadRoute(url, { preloadData: a.getAttribute("preload") !== "false" }); | ||
} | ||
function handleAnchorIn(evt) { | ||
function handleAnchorMove(evt) { | ||
clearTimeout(preloadTimeout); | ||
const res = handleAnchor(evt); | ||
if (!res) | ||
return; | ||
return lastElement = null; | ||
const [a, url] = res; | ||
if (typeof transformUrl === "function") { | ||
url.pathname = transformUrl(url.pathname); | ||
} | ||
if (preloadTimeout[url.pathname]) | ||
if (lastElement === a) | ||
return; | ||
preloadTimeout[url.pathname] = setTimeout(() => { | ||
transformUrl && (url.pathname = transformUrl(url.pathname)); | ||
preloadTimeout = setTimeout(() => { | ||
router.preloadRoute(url, { preloadData: a.getAttribute("preload") !== "false" }); | ||
delete preloadTimeout[url.pathname]; | ||
}, 200); | ||
lastElement = a; | ||
}, 20); | ||
} | ||
function handleAnchorOut(evt) { | ||
const res = handleAnchor(evt); | ||
if (!res) | ||
return; | ||
const [, url] = res; | ||
if (typeof transformUrl === "function") { | ||
url.pathname = transformUrl(url.pathname); | ||
} | ||
if (preloadTimeout[url.pathname]) { | ||
clearTimeout(preloadTimeout[url.pathname]); | ||
delete preloadTimeout[url.pathname]; | ||
} | ||
} | ||
function handleFormSubmit(evt) { | ||
@@ -126,6 +110,5 @@ if (evt.defaultPrevented) | ||
if (preload) { | ||
document.addEventListener("mouseover", handleAnchorIn); | ||
document.addEventListener("mouseout", handleAnchorOut); | ||
document.addEventListener("focusin", handleAnchorPreload); | ||
document.addEventListener("touchstart", handleAnchorPreload); | ||
document.addEventListener("mousemove", handleAnchorMove, { passive: true }); | ||
document.addEventListener("focusin", handleAnchorPreload, { passive: true }); | ||
document.addEventListener("touchstart", handleAnchorPreload, { passive: true }); | ||
} | ||
@@ -136,4 +119,3 @@ document.addEventListener("submit", handleFormSubmit); | ||
if (preload) { | ||
document.removeEventListener("mouseover", handleAnchorIn); | ||
document.removeEventListener("mouseout", handleAnchorOut); | ||
document.removeEventListener("mousemove", handleAnchorMove); | ||
document.removeEventListener("focusin", handleAnchorPreload); | ||
@@ -140,0 +122,0 @@ document.removeEventListener("touchstart", handleAnchorPreload); |
@@ -370,3 +370,3 @@ import { isServer, getRequestEvent, createComponent as createComponent$1, memo, delegateEvents, spread, mergeProps as mergeProps$1, template } from 'solid-js/web'; | ||
} | ||
function createLocation(path, state) { | ||
function createLocation(path, state, queryWrapper) { | ||
const origin = new URL(mockBase); | ||
@@ -388,2 +388,3 @@ const url = createMemo(prev => { | ||
const key = () => ""; | ||
const queryFn = on(search, () => extractSearchParams(url())); | ||
return { | ||
@@ -405,3 +406,3 @@ get pathname() { | ||
}, | ||
query: createMemoObject(on(search, () => extractSearchParams(url()))) | ||
query: queryWrapper ? queryWrapper(queryFn) : createMemoObject(queryFn) | ||
}; | ||
@@ -469,3 +470,3 @@ } | ||
const [state, setState] = createSignal(source().state); | ||
const location = createLocation(reference, state); | ||
const location = createLocation(reference, state, utils.queryWrapper); | ||
const referrers = []; | ||
@@ -479,3 +480,3 @@ const submissions = createSignal(isServer ? initFromFlash() : []); | ||
}); | ||
const params = createMemoObject(() => { | ||
const buildParams = () => { | ||
const m = matches(); | ||
@@ -487,3 +488,4 @@ const params = {}; | ||
return params; | ||
}); | ||
}; | ||
const params = utils.paramsWrapper ? utils.paramsWrapper(buildParams, branches) : createMemoObject(buildParams); | ||
const baseRoute = { | ||
@@ -1195,3 +1197,4 @@ pattern: basePath, | ||
const navigateFromRoute = router.navigatorFactory(router.base); | ||
let preloadTimeout = {}; | ||
let preloadTimeout; | ||
let lastElement; | ||
function isSvg(el) { | ||
@@ -1232,36 +1235,21 @@ return el.namespaceURI === "http://www.w3.org/2000/svg"; | ||
const [a, url] = res; | ||
if (typeof transformUrl === "function") { | ||
url.pathname = transformUrl(url.pathname); | ||
} | ||
if (!preloadTimeout[url.pathname]) router.preloadRoute(url, { | ||
transformUrl && (url.pathname = transformUrl(url.pathname)); | ||
router.preloadRoute(url, { | ||
preloadData: a.getAttribute("preload") !== "false" | ||
}); | ||
} | ||
function handleAnchorIn(evt) { | ||
function handleAnchorMove(evt) { | ||
clearTimeout(preloadTimeout); | ||
const res = handleAnchor(evt); | ||
if (!res) return; | ||
if (!res) return lastElement = null; | ||
const [a, url] = res; | ||
if (typeof transformUrl === "function") { | ||
url.pathname = transformUrl(url.pathname); | ||
} | ||
if (preloadTimeout[url.pathname]) return; | ||
preloadTimeout[url.pathname] = setTimeout(() => { | ||
if (lastElement === a) return; | ||
transformUrl && (url.pathname = transformUrl(url.pathname)); | ||
preloadTimeout = setTimeout(() => { | ||
router.preloadRoute(url, { | ||
preloadData: a.getAttribute("preload") !== "false" | ||
}); | ||
delete preloadTimeout[url.pathname]; | ||
}, 200); | ||
lastElement = a; | ||
}, 20); | ||
} | ||
function handleAnchorOut(evt) { | ||
const res = handleAnchor(evt); | ||
if (!res) return; | ||
const [, url] = res; | ||
if (typeof transformUrl === "function") { | ||
url.pathname = transformUrl(url.pathname); | ||
} | ||
if (preloadTimeout[url.pathname]) { | ||
clearTimeout(preloadTimeout[url.pathname]); | ||
delete preloadTimeout[url.pathname]; | ||
} | ||
} | ||
function handleFormSubmit(evt) { | ||
@@ -1293,6 +1281,11 @@ if (evt.defaultPrevented) return; | ||
if (preload) { | ||
document.addEventListener("mouseover", handleAnchorIn); | ||
document.addEventListener("mouseout", handleAnchorOut); | ||
document.addEventListener("focusin", handleAnchorPreload); | ||
document.addEventListener("touchstart", handleAnchorPreload); | ||
document.addEventListener("mousemove", handleAnchorMove, { | ||
passive: true | ||
}); | ||
document.addEventListener("focusin", handleAnchorPreload, { | ||
passive: true | ||
}); | ||
document.addEventListener("touchstart", handleAnchorPreload, { | ||
passive: true | ||
}); | ||
} | ||
@@ -1303,4 +1296,3 @@ document.addEventListener("submit", handleFormSubmit); | ||
if (preload) { | ||
document.removeEventListener("mouseover", handleAnchorIn); | ||
document.removeEventListener("mouseout", handleAnchorOut); | ||
document.removeEventListener("mousemove", handleAnchorMove); | ||
document.removeEventListener("focusin", handleAnchorPreload); | ||
@@ -1461,3 +1453,3 @@ document.removeEventListener("touchstart", handleAnchorPreload); | ||
const _tmpl$ = /*#__PURE__*/template(`<a>`); | ||
var _tmpl$ = /*#__PURE__*/template(`<a>`); | ||
function A(props) { | ||
@@ -1476,7 +1468,7 @@ props = mergeProps({ | ||
const path = normalizePath(to_.split(/[?#]/, 1)[0]).toLowerCase(); | ||
const loc = normalizePath(location.pathname).toLowerCase(); | ||
const loc = decodeURI(normalizePath(location.pathname).toLowerCase()); | ||
return [props.end ? path === loc : loc.startsWith(path + "/") || loc === path, path === loc]; | ||
}); | ||
return (() => { | ||
const _el$ = _tmpl$(); | ||
var _el$ = _tmpl$(); | ||
spread(_el$, mergeProps$1(rest, { | ||
@@ -1483,0 +1475,0 @@ get href() { |
@@ -24,3 +24,2 @@ import { JSX, Accessor } from "solid-js"; | ||
export declare function getRouteMatches(branches: Branch[], location: string): RouteMatch[]; | ||
export declare function createLocation(path: Accessor<string>, state: Accessor<any>): Location; | ||
export declare function getIntent(): Intent | undefined; | ||
@@ -27,0 +26,0 @@ export declare function getInPreloadFn(): boolean; |
@@ -148,3 +148,3 @@ import { runWithOwner, batch } from "solid-js"; | ||
} | ||
export function createLocation(path, state) { | ||
function createLocation(path, state, queryWrapper) { | ||
const origin = new URL(mockBase); | ||
@@ -167,2 +167,3 @@ const url = createMemo(prev => { | ||
const key = () => ""; | ||
const queryFn = on(search, () => extractSearchParams(url())); | ||
return { | ||
@@ -184,3 +185,3 @@ get pathname() { | ||
}, | ||
query: createMemoObject(on(search, () => extractSearchParams(url()))) | ||
query: queryWrapper ? queryWrapper(queryFn) : createMemoObject(queryFn) | ||
}; | ||
@@ -245,3 +246,3 @@ } | ||
const [state, setState] = createSignal(source().state); | ||
const location = createLocation(reference, state); | ||
const location = createLocation(reference, state, utils.queryWrapper); | ||
const referrers = []; | ||
@@ -255,3 +256,3 @@ const submissions = createSignal(isServer ? initFromFlash() : []); | ||
}); | ||
const params = createMemoObject(() => { | ||
const buildParams = () => { | ||
const m = matches(); | ||
@@ -263,3 +264,6 @@ const params = {}; | ||
return params; | ||
}); | ||
}; | ||
const params = utils.paramsWrapper | ||
? utils.paramsWrapper(buildParams, branches) | ||
: createMemoObject(buildParams); | ||
const baseRoute = { | ||
@@ -311,3 +315,2 @@ pattern: basePath, | ||
}; | ||
let s; | ||
const resolvedTo = resolve | ||
@@ -314,0 +317,0 @@ ? route.resolvePath(to) |
@@ -129,2 +129,4 @@ import type { Component, JSX, Signal } from "solid-js"; | ||
beforeLeave: BeforeLeaveLifecycle; | ||
paramsWrapper: (getParams: () => Params, branches: () => Branch[]) => Params; | ||
queryWrapper: (getQuery: () => Params) => Params; | ||
} | ||
@@ -131,0 +133,0 @@ export interface RouterContext { |
@@ -9,3 +9,3 @@ { | ||
"license": "MIT", | ||
"version": "0.14.7", | ||
"version": "0.14.8", | ||
"homepage": "https://github.com/solidjs/solid-router#readme", | ||
@@ -41,11 +41,11 @@ "repository": { | ||
"@types/node": "^20.11.14", | ||
"babel-preset-solid": "^1.8.6", | ||
"babel-preset-solid": "^1.9.2", | ||
"jsdom": "^24.0.0", | ||
"prettier": "^2.7.0", | ||
"rollup": "^4.9.6", | ||
"solid-js": "^1.8.7", | ||
"solid-js": "^1.9.2", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.12", | ||
"vite": "^5.4.8", | ||
"vite-plugin-solid": "^2.9.1", | ||
"vitest": "^1.2.2" | ||
"vitest": "^2.1.2" | ||
}, | ||
@@ -52,0 +52,0 @@ "peerDependencies": { |
@@ -859,3 +859,3 @@ <p> | ||
<div classList={{ "grey-out": isRouting() }}> | ||
<MyAwesomeConent /> | ||
<MyAwesomeContent /> | ||
</div> | ||
@@ -862,0 +862,0 @@ ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
171450
3800