@tanstack/solid-router 1.132.0-alpha.12 → 1.132.0-alpha.15
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/cjs/index.cjs +8 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +3 -1
- package/dist/cjs/link.cjs +43 -30
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/useNavigate.cjs +1 -8
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +3 -2
- package/dist/esm/link.js +43 -30
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/useNavigate.js +1 -8
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/source/index.d.ts +3 -1
- package/dist/source/index.jsx +2 -1
- package/dist/source/index.jsx.map +1 -1
- package/dist/source/link.jsx +43 -35
- package/dist/source/link.jsx.map +1 -1
- package/dist/source/useNavigate.jsx +1 -5
- package/dist/source/useNavigate.jsx.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +5 -1
- package/src/link.tsx +41 -40
- package/src/useNavigate.tsx +1 -9
- package/dist/cjs/useActiveLocation.cjs +0 -40
- package/dist/cjs/useActiveLocation.cjs.map +0 -1
- package/dist/cjs/useActiveLocation.d.cts +0 -8
- package/dist/esm/useActiveLocation.d.ts +0 -8
- package/dist/esm/useActiveLocation.js +0 -40
- package/dist/esm/useActiveLocation.js.map +0 -1
- package/dist/source/useActiveLocation.d.ts +0 -8
- package/dist/source/useActiveLocation.js +0 -33
- package/dist/source/useActiveLocation.js.map +0 -1
- package/src/useActiveLocation.ts +0 -61
package/dist/cjs/index.cjs
CHANGED
|
@@ -54,6 +54,10 @@ Object.defineProperty(exports, "componentTypes", {
|
|
|
54
54
|
enumerable: true,
|
|
55
55
|
get: () => routerCore.componentTypes
|
|
56
56
|
});
|
|
57
|
+
Object.defineProperty(exports, "composeRewrites", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: () => routerCore.composeRewrites
|
|
60
|
+
});
|
|
57
61
|
Object.defineProperty(exports, "createControlledPromise", {
|
|
58
62
|
enumerable: true,
|
|
59
63
|
get: () => routerCore.createControlledPromise
|
|
@@ -146,10 +150,6 @@ Object.defineProperty(exports, "redirect", {
|
|
|
146
150
|
enumerable: true,
|
|
147
151
|
get: () => routerCore.redirect
|
|
148
152
|
});
|
|
149
|
-
Object.defineProperty(exports, "removeBasepath", {
|
|
150
|
-
enumerable: true,
|
|
151
|
-
get: () => routerCore.removeBasepath
|
|
152
|
-
});
|
|
153
153
|
Object.defineProperty(exports, "replaceEqualDeep", {
|
|
154
154
|
enumerable: true,
|
|
155
155
|
get: () => routerCore.replaceEqualDeep
|
|
@@ -162,6 +162,10 @@ Object.defineProperty(exports, "retainSearchParams", {
|
|
|
162
162
|
enumerable: true,
|
|
163
163
|
get: () => routerCore.retainSearchParams
|
|
164
164
|
});
|
|
165
|
+
Object.defineProperty(exports, "rewriteBasepath", {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
get: () => routerCore.rewriteBasepath
|
|
168
|
+
});
|
|
165
169
|
Object.defineProperty(exports, "rootRouteId", {
|
|
166
170
|
enumerable: true,
|
|
167
171
|
get: () => routerCore.rootRouteId
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { defer, TSR_DEFERRED_PROMISE, isMatch, joinPaths, cleanPath, trimPathLeft, trimPathRight, trimPath, resolvePath, parsePathname, interpolatePath, matchPathname,
|
|
1
|
+
export { defer, TSR_DEFERRED_PROMISE, isMatch, joinPaths, cleanPath, trimPathLeft, trimPathRight, trimPath, resolvePath, parsePathname, interpolatePath, matchPathname, matchByPath, rootRouteId, defaultSerializeError, defaultParseSearch, defaultStringifySearch, parseSearchWith, stringifySearchWith, functionalUpdate, replaceEqualDeep, isPlainObject, isPlainArray, deepEqual, createControlledPromise, retainSearchParams, stripSearchParams, createSerializationAdapter, } from '@tanstack/router-core';
|
|
2
2
|
export type { DeferredPromiseState, DeferredPromise, ParsedLocation, RemoveTrailingSlashes, RemoveLeadingSlashes, ActiveOptions, Segment, ResolveRelativePath, RootRouteId, AnyPathParams, ResolveParams, ResolveOptionalParams, ResolveRequiredParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, UpdatableStaticRouteOption, MetaDescriptor, RouteLinkEntry, ParseParamsFn, SearchFilter, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, TrimPath, TrimPathLeft, TrimPathRight, StringifyParamsFn, ParamsOptions, InferAllParams, InferAllContext, LooseReturnType, LooseAsyncReturnType, ContextReturnType, ContextAsyncReturnType, ResolveLoaderData, ResolveRouteContext, SearchSerializer, SearchParser, TrailingSlashOption, Manifest, RouterManagedTag, ControlledPromise, Constrain, Expand, MergeAll, Assign, IntersectAssign, ResolveValidatorInput, ResolveValidatorOutput, AnyValidator, DefaultValidator, ValidatorFn, AnySchema, AnyValidatorAdapter, AnyValidatorFn, AnyValidatorObj, ResolveValidatorInputFn, ResolveValidatorOutputFn, ResolveSearchValidatorInput, ResolveSearchValidatorInputFn, Validator, ValidatorAdapter, ValidatorObj, NavigateFn, BuildLocationFn, InferDescendantToPaths, RelativeToPath, RelativeToParentPath, RelativeToCurrentPath, Register, AbsoluteToPath, RelativeToPathAutoComplete, NavigateOptions, ToOptions, ToMaskOptions, ToSubOptions, ResolveRoute, SearchParamOptions, PathParamOptions, ToPathOption, LinkOptions, MakeOptionalPathParams, AnyRouterWithContext, ParseRoute, RoutesById, RouteById, RouteIds, RoutesByPath, RouteByPath, RoutePaths, FullSearchSchema, AllParams, AllLoaderData, FullSearchSchemaInput, AllContext, CommitLocationOptions, MatchLocation, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, ResolveAllParamsFromParent, RouteContextParameter, BeforeLoadContextParameter, ResolveAllContext, FullSearchSchemaOption, MakeRemountDepsOptionsUnion, RemountDepsOptions, FileRouteTypes, FileRoutesByPath, UseNavigateResult, AnyRedirect, Redirect, RedirectOptions, ResolvedRedirect, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, RouteLoaderFn, LoaderFnContext, MakeRouteMatch, MakeRouteMatchUnion, RouteMatch, AnyRouteMatch, RouteContextFn, RouteContextOptions, BeforeLoadFn, BeforeLoadContextOptions, ContextOptions, RootRouteOptions, AnyRouteWithContext, LazyRouteOptions, AnyRoute, ResolveFullPath, RouteConstraints, RouterState, ListenerFn, BuildNextOptions, AnyRouter, RegisteredRouter, RouterEvents, RouterEvent, RouterListener, MatchRouteOptions, RouteMask, RouterContextOptions, RouterOptions, RouterConstructorOptions, ControllablePromise, InjectedHtmlEntry, CreateFileRoute, CreateLazyFileRoute, AnySerializationAdapter, SerializationAdapter, } from '@tanstack/router-core';
|
|
3
3
|
export { createHistory, createBrowserHistory, createHashHistory, createMemoryHistory, } from '@tanstack/history';
|
|
4
4
|
export type { BlockerFn, HistoryLocation, RouterHistory, ParsedPath, HistoryState, } from '@tanstack/history';
|
|
@@ -47,3 +47,5 @@ export { ScriptOnce } from './ScriptOnce.cjs';
|
|
|
47
47
|
export { Asset } from './Asset.cjs';
|
|
48
48
|
export { HeadContent, useTags } from './HeadContent.cjs';
|
|
49
49
|
export { Scripts } from './Scripts.cjs';
|
|
50
|
+
export { rewriteBasepath, composeRewrites } from '@tanstack/router-core';
|
|
51
|
+
export type { LocationRewrite, LocationRewriteFunction, } from '@tanstack/router-core';
|
package/dist/cjs/link.cjs
CHANGED
|
@@ -7,7 +7,6 @@ const routerCore = require("@tanstack/router-core");
|
|
|
7
7
|
const useRouterState = require("./useRouterState.cjs");
|
|
8
8
|
const useRouter = require("./useRouter.cjs");
|
|
9
9
|
const utils = require("./utils.cjs");
|
|
10
|
-
const useActiveLocation = require("./useActiveLocation.cjs");
|
|
11
10
|
function _interopNamespaceDefault(e) {
|
|
12
11
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
13
12
|
if (e) {
|
|
@@ -36,35 +35,58 @@ function useLinkProps(options) {
|
|
|
36
35
|
inactiveProps: () => ({})
|
|
37
36
|
}, options), ["activeProps", "inactiveProps", "activeOptions", "to", "preload", "preloadDelay", "hashScrollIntoView", "replace", "startTransition", "resetScroll", "viewTransition", "target", "disabled", "style", "class", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onMouseOver", "onMouseOut", "onTouchStart", "ignoreBlocker"]);
|
|
38
37
|
const [_, propsSafeToSpread] = Solid__namespace.splitProps(rest, ["params", "search", "hash", "state", "mask", "reloadDocument", "unsafeRelative"]);
|
|
39
|
-
const type = () => {
|
|
40
|
-
try {
|
|
41
|
-
new URL(`${local.to}`);
|
|
42
|
-
return "external";
|
|
43
|
-
} catch {
|
|
44
|
-
}
|
|
45
|
-
return "internal";
|
|
46
|
-
};
|
|
47
38
|
const currentSearch = useRouterState.useRouterState({
|
|
48
39
|
select: (s) => s.location.searchStr
|
|
49
40
|
});
|
|
50
|
-
const
|
|
51
|
-
getFromPath,
|
|
52
|
-
activeLocation
|
|
53
|
-
} = useActiveLocation.useActiveLocation();
|
|
54
|
-
const from = getFromPath(options.from);
|
|
41
|
+
const from = options.from;
|
|
55
42
|
const _options = () => {
|
|
56
43
|
return {
|
|
57
44
|
...options,
|
|
58
|
-
from
|
|
45
|
+
from
|
|
59
46
|
};
|
|
60
47
|
};
|
|
61
48
|
const next = Solid__namespace.createMemo(() => {
|
|
62
49
|
currentSearch();
|
|
63
|
-
activeLocation();
|
|
64
50
|
return router.buildLocation(_options());
|
|
65
51
|
});
|
|
52
|
+
const hrefOption = Solid__namespace.createMemo(() => {
|
|
53
|
+
if (_options().disabled) {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
let href;
|
|
57
|
+
const maskedLocation = next().maskedLocation;
|
|
58
|
+
if (maskedLocation) {
|
|
59
|
+
href = maskedLocation.url;
|
|
60
|
+
} else {
|
|
61
|
+
href = next().url;
|
|
62
|
+
}
|
|
63
|
+
let external = false;
|
|
64
|
+
if (router.origin) {
|
|
65
|
+
if (href.startsWith(router.origin)) {
|
|
66
|
+
href = href.replace(router.origin, "");
|
|
67
|
+
} else {
|
|
68
|
+
external = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
href,
|
|
73
|
+
external
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
const externalLink = Solid__namespace.createMemo(() => {
|
|
77
|
+
const _href = hrefOption();
|
|
78
|
+
if (_href?.external) {
|
|
79
|
+
return _href.href;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
new URL(_options().to);
|
|
83
|
+
return _options().to;
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
return void 0;
|
|
87
|
+
});
|
|
66
88
|
const preload = Solid__namespace.createMemo(() => {
|
|
67
|
-
if (_options().reloadDocument) {
|
|
89
|
+
if (_options().reloadDocument || externalLink()) {
|
|
68
90
|
return false;
|
|
69
91
|
}
|
|
70
92
|
return local.preload ?? router.options.defaultPreload;
|
|
@@ -72,6 +94,7 @@ function useLinkProps(options) {
|
|
|
72
94
|
const preloadDelay = () => local.preloadDelay ?? router.options.defaultPreloadDelay ?? 0;
|
|
73
95
|
const isActive = useRouterState.useRouterState({
|
|
74
96
|
select: (s) => {
|
|
97
|
+
if (externalLink()) return false;
|
|
75
98
|
if (local.activeOptions?.exact) {
|
|
76
99
|
const testExact = routerCore.exactPathTest(s.location.pathname, next().pathname, router.basepath);
|
|
77
100
|
if (!testExact) {
|
|
@@ -124,15 +147,10 @@ function useLinkProps(options) {
|
|
|
124
147
|
hasRenderFetched = true;
|
|
125
148
|
}
|
|
126
149
|
});
|
|
127
|
-
if (
|
|
150
|
+
if (externalLink()) {
|
|
128
151
|
return Solid__namespace.mergeProps(propsSafeToSpread, {
|
|
129
152
|
ref,
|
|
130
|
-
|
|
131
|
-
return type();
|
|
132
|
-
},
|
|
133
|
-
get href() {
|
|
134
|
-
return local.to;
|
|
135
|
-
}
|
|
153
|
+
href: externalLink
|
|
136
154
|
}, Solid__namespace.splitProps(local, ["target", "disabled", "style", "class", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onMouseOut", "onMouseOver", "onTouchStart"])[0]);
|
|
137
155
|
}
|
|
138
156
|
const handleClick = (e) => {
|
|
@@ -207,14 +225,9 @@ function useLinkProps(options) {
|
|
|
207
225
|
...resolvedActiveProps().style,
|
|
208
226
|
...resolvedInactiveProps().style
|
|
209
227
|
});
|
|
210
|
-
const href = Solid__namespace.createMemo(() => {
|
|
211
|
-
const nextLocation = next();
|
|
212
|
-
const maskedLocation = nextLocation?.maskedLocation;
|
|
213
|
-
return _options().disabled ? void 0 : maskedLocation ? router.history.createHref(maskedLocation.href) : router.history.createHref(nextLocation?.href);
|
|
214
|
-
});
|
|
215
228
|
return Solid__namespace.mergeProps(propsSafeToSpread, resolvedActiveProps, resolvedInactiveProps, () => {
|
|
216
229
|
return {
|
|
217
|
-
href:
|
|
230
|
+
href: hrefOption()?.href,
|
|
218
231
|
ref: refs.mergeRefs(setRef, _options().ref),
|
|
219
232
|
onClick: composeEventHandlers([local.onClick, handleClick]),
|
|
220
233
|
onFocus: composeEventHandlers([local.onFocus, handleFocus]),
|
package/dist/cjs/link.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.cjs","sources":["../../src/link.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\n\nimport { mergeRefs } from '@solid-primitives/refs'\n\nimport {\n deepEqual,\n exactPathTest,\n functionalUpdate,\n preloadWarning,\n removeTrailingSlash,\n} from '@tanstack/router-core'\nimport { Dynamic } from 'solid-js/web'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\n\nimport { useIntersectionObserver } from './utils'\n\nimport { useActiveLocation } from './useActiveLocation'\nimport type {\n AnyRouter,\n Constrain,\n LinkCurrentTargetElement,\n LinkOptions,\n RegisteredRouter,\n RoutePaths,\n} from '@tanstack/router-core'\nimport type {\n ValidateLinkOptions,\n ValidateLinkOptionsArray,\n} from './typePrimitives'\n\nexport function useLinkProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n>(\n options: UseLinkPropsOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Solid.ComponentProps<'a'> {\n const router = useRouter()\n const [isTransitioning, setIsTransitioning] = Solid.createSignal(false)\n let hasRenderFetched = false\n\n const [local, rest] = Solid.splitProps(\n Solid.mergeProps(\n {\n activeProps: () => ({ class: 'active' }),\n inactiveProps: () => ({}),\n },\n options,\n ),\n [\n 'activeProps',\n 'inactiveProps',\n 'activeOptions',\n 'to',\n 'preload',\n 'preloadDelay',\n 'hashScrollIntoView',\n 'replace',\n 'startTransition',\n 'resetScroll',\n 'viewTransition',\n 'target',\n 'disabled',\n 'style',\n 'class',\n 'onClick',\n 'onFocus',\n 'onMouseEnter',\n 'onMouseLeave',\n 'onMouseOver',\n 'onMouseOut',\n 'onTouchStart',\n 'ignoreBlocker',\n ],\n )\n\n // const {\n // // custom props\n // activeProps = () => ({ class: 'active' }),\n // inactiveProps = () => ({}),\n // activeOptions,\n // to,\n // preload: userPreload,\n // preloadDelay: userPreloadDelay,\n // hashScrollIntoView,\n // replace,\n // startTransition,\n // resetScroll,\n // viewTransition,\n // // element props\n // children,\n // target,\n // disabled,\n // style,\n // class,\n // onClick,\n // onFocus,\n // onMouseEnter,\n // onMouseLeave,\n // onTouchStart,\n // ignoreBlocker,\n // ...rest\n // } = options\n\n const [_, propsSafeToSpread] = Solid.splitProps(rest, [\n 'params',\n 'search',\n 'hash',\n 'state',\n 'mask',\n 'reloadDocument',\n 'unsafeRelative',\n ])\n\n // If this link simply reloads the current route,\n // make sure it has a new key so it will trigger a data refresh\n\n // If this `to` is a valid external URL, return\n // null for LinkUtils\n\n const type: Solid.Accessor<'internal' | 'external'> = () => {\n try {\n new URL(`${local.to}`)\n return 'external'\n } catch {}\n return 'internal'\n }\n\n const currentSearch = useRouterState({\n select: (s) => s.location.searchStr,\n })\n\n const { getFromPath, activeLocation } = useActiveLocation()\n\n const from = getFromPath(options.from)\n\n const _options = () => {\n return {\n ...options,\n from: from(),\n }\n }\n\n const next = Solid.createMemo(() => {\n currentSearch()\n activeLocation()\n return router.buildLocation(_options() as any)\n })\n\n const preload = Solid.createMemo(() => {\n if (_options().reloadDocument) {\n return false\n }\n return local.preload ?? router.options.defaultPreload\n })\n const preloadDelay = () =>\n local.preloadDelay ?? router.options.defaultPreloadDelay ?? 0\n\n const isActive = useRouterState({\n select: (s) => {\n if (local.activeOptions?.exact) {\n const testExact = exactPathTest(\n s.location.pathname,\n next().pathname,\n router.basepath,\n )\n if (!testExact) {\n return false\n }\n } else {\n const currentPathSplit = removeTrailingSlash(\n s.location.pathname,\n router.basepath,\n ).split('/')\n const nextPathSplit = removeTrailingSlash(\n next()?.pathname,\n router.basepath,\n )?.split('/')\n\n const pathIsFuzzyEqual = nextPathSplit?.every(\n (d, i) => d === currentPathSplit[i],\n )\n if (!pathIsFuzzyEqual) {\n return false\n }\n }\n\n if (local.activeOptions?.includeSearch ?? true) {\n const searchTest = deepEqual(s.location.search, next().search, {\n partial: !local.activeOptions?.exact,\n ignoreUndefined: !local.activeOptions?.explicitUndefined,\n })\n if (!searchTest) {\n return false\n }\n }\n\n if (local.activeOptions?.includeHash) {\n return s.location.hash === next().hash\n }\n return true\n },\n })\n\n const doPreload = () =>\n router.preloadRoute(_options() as any).catch((err: any) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n\n const preloadViewportIoCallback = (\n entry: IntersectionObserverEntry | undefined,\n ) => {\n if (entry?.isIntersecting) {\n doPreload()\n }\n }\n\n const [ref, setRef] = Solid.createSignal<Element | null>(null)\n\n useIntersectionObserver(\n ref,\n preloadViewportIoCallback,\n { rootMargin: '100px' },\n { disabled: !!local.disabled || !(preload() === 'viewport') },\n )\n\n Solid.createEffect(() => {\n if (hasRenderFetched) {\n return\n }\n if (!local.disabled && preload() === 'render') {\n doPreload()\n hasRenderFetched = true\n }\n })\n\n if (type() === 'external') {\n return Solid.mergeProps(\n propsSafeToSpread,\n {\n ref,\n get type() {\n return type()\n },\n get href() {\n return local.to\n },\n },\n Solid.splitProps(local, [\n 'target',\n 'disabled',\n 'style',\n 'class',\n 'onClick',\n 'onFocus',\n 'onMouseEnter',\n 'onMouseLeave',\n 'onMouseOut',\n 'onMouseOver',\n 'onTouchStart',\n ])[0],\n ) as any\n }\n\n // The click handler\n const handleClick = (e: MouseEvent) => {\n if (\n !local.disabled &&\n !isCtrlEvent(e) &&\n !e.defaultPrevented &&\n (!local.target || local.target === '_self') &&\n e.button === 0\n ) {\n e.preventDefault()\n\n setIsTransitioning(true)\n\n const unsub = router.subscribe('onResolved', () => {\n unsub()\n setIsTransitioning(false)\n })\n\n // All is well? Navigate!\n // N.B. we don't call `router.commitLocation(next) here because we want to run `validateSearch` before committing\n router.navigate({\n ..._options(),\n replace: local.replace,\n resetScroll: local.resetScroll,\n hashScrollIntoView: local.hashScrollIntoView,\n startTransition: local.startTransition,\n viewTransition: local.viewTransition,\n ignoreBlocker: local.ignoreBlocker,\n })\n }\n }\n\n // The click handler\n const handleFocus = (_: MouseEvent) => {\n if (local.disabled) return\n if (preload()) {\n doPreload()\n }\n }\n\n const handleTouchStart = handleFocus\n\n const handleEnter = (e: MouseEvent) => {\n if (local.disabled) return\n const eventTarget = (e.target || {}) as LinkCurrentTargetElement\n\n if (preload()) {\n if (eventTarget.preloadTimeout) {\n return\n }\n\n eventTarget.preloadTimeout = setTimeout(() => {\n eventTarget.preloadTimeout = null\n doPreload()\n }, preloadDelay())\n }\n }\n\n const handleLeave = (e: MouseEvent) => {\n if (local.disabled) return\n const eventTarget = (e.target || {}) as LinkCurrentTargetElement\n\n if (eventTarget.preloadTimeout) {\n clearTimeout(eventTarget.preloadTimeout)\n eventTarget.preloadTimeout = null\n }\n }\n\n /** Call a JSX.EventHandlerUnion with the event. */\n function callHandler<T, TEvent extends Event>(\n event: TEvent & { currentTarget: T; target: Element },\n handler: Solid.JSX.EventHandlerUnion<T, TEvent> | undefined,\n ) {\n if (handler) {\n if (typeof handler === 'function') {\n handler(event)\n } else {\n handler[0](handler[1], event)\n }\n }\n\n return event.defaultPrevented\n }\n\n function composeEventHandlers<T>(\n handlers: Array<Solid.JSX.EventHandlerUnion<T, any> | undefined>,\n ) {\n return (event: any) => {\n for (const handler of handlers) {\n callHandler(event, handler)\n }\n }\n }\n\n // Get the active props\n const resolvedActiveProps: () => Omit<Solid.ComponentProps<'a'>, 'style'> & {\n style?: Solid.JSX.CSSProperties\n } = () =>\n isActive() ? (functionalUpdate(local.activeProps as any, {}) ?? {}) : {}\n\n // Get the inactive props\n const resolvedInactiveProps: () => Omit<\n Solid.ComponentProps<'a'>,\n 'style'\n > & { style?: Solid.JSX.CSSProperties } = () =>\n isActive() ? {} : functionalUpdate(local.inactiveProps, {})\n\n const resolvedClassName = () =>\n [local.class, resolvedActiveProps().class, resolvedInactiveProps().class]\n .filter(Boolean)\n .join(' ')\n\n const resolvedStyle = () => ({\n ...local.style,\n ...resolvedActiveProps().style,\n ...resolvedInactiveProps().style,\n })\n\n const href = Solid.createMemo(() => {\n const nextLocation = next()\n const maskedLocation = nextLocation?.maskedLocation\n\n return _options().disabled\n ? undefined\n : maskedLocation\n ? router.history.createHref(maskedLocation.href)\n : router.history.createHref(nextLocation?.href)\n })\n\n return Solid.mergeProps(\n propsSafeToSpread,\n resolvedActiveProps,\n resolvedInactiveProps,\n () => {\n return {\n href: href(),\n ref: mergeRefs(setRef, _options().ref),\n onClick: composeEventHandlers([local.onClick, handleClick]),\n onFocus: composeEventHandlers([local.onFocus, handleFocus]),\n onMouseEnter: composeEventHandlers([local.onMouseEnter, handleEnter]),\n onMouseOver: composeEventHandlers([local.onMouseOver, handleEnter]),\n onMouseLeave: composeEventHandlers([local.onMouseLeave, handleLeave]),\n onMouseOut: composeEventHandlers([local.onMouseOut, handleLeave]),\n onTouchStart: composeEventHandlers([\n local.onTouchStart,\n handleTouchStart,\n ]),\n disabled: !!local.disabled,\n target: local.target,\n ...(Object.keys(resolvedStyle).length && { style: resolvedStyle }),\n ...(resolvedClassName() && { class: resolvedClassName() }),\n ...(local.disabled && {\n role: 'link',\n 'aria-disabled': true,\n }),\n ...(isActive() && { 'data-status': 'active', 'aria-current': 'page' }),\n ...(isTransitioning() && { 'data-transitioning': 'transitioning' }),\n }\n },\n ) as any\n}\n\nexport type UseLinkPropsOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '.',\n> = ActiveLinkOptions<'a', TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n Omit<Solid.ComponentProps<'a'>, 'style'> & { style?: Solid.JSX.CSSProperties }\n\nexport type ActiveLinkOptions<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = LinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n ActiveLinkOptionProps<TComp>\n\ntype ActiveLinkProps<TComp> = Partial<\n LinkComponentSolidProps<TComp> & {\n [key: `data-${string}`]: unknown\n }\n>\n\nexport interface ActiveLinkOptionProps<TComp = 'a'> {\n /**\n * A function that returns additional props for the `active` state of this link.\n * These props override other props passed to the link (`style`'s are merged, `class`'s are concatenated)\n */\n activeProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>)\n /**\n * A function that returns additional props for the `inactive` state of this link.\n * These props override other props passed to the link (`style`'s are merged, `class`'s are concatenated)\n */\n inactiveProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>)\n}\n\nexport type LinkProps<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ActiveLinkOptions<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n LinkPropsChildren\n\nexport interface LinkPropsChildren {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | Solid.JSX.Element\n | ((state: {\n isActive: boolean\n isTransitioning: boolean\n }) => Solid.JSX.Element)\n}\n\ntype LinkComponentSolidProps<TComp> = TComp extends Solid.ValidComponent\n ? Omit<Solid.ComponentProps<TComp>, keyof CreateLinkProps>\n : never\n\nexport type LinkComponentProps<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = LinkComponentSolidProps<TComp> &\n LinkProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type CreateLinkProps = LinkProps<\n any,\n any,\n string,\n string,\n string,\n string\n>\n\nexport type LinkComponent<\n in out TComp,\n in out TDefaultFrom extends string = string,\n> = <\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = TDefaultFrom,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n props: LinkComponentProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n) => Solid.JSX.Element\n\nexport interface LinkComponentRoute<\n in out TDefaultFrom extends string = string,\n> {\n defaultFrom: TDefaultFrom\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n props: LinkComponentProps<\n 'a',\n TRouter,\n this['defaultFrom'],\n TTo,\n this['defaultFrom'],\n TMaskTo\n >,\n ): Solid.JSX.Element\n}\n\nexport function createLink<const TComp>(\n Comp: Constrain<TComp, any, (props: CreateLinkProps) => Solid.JSX.Element>,\n): LinkComponent<TComp> {\n return (props) => <Link {...props} _asChild={Comp} />\n}\n\nexport const Link: LinkComponent<'a'> = (props) => {\n const [local, rest] = Solid.splitProps(\n props as typeof props & { _asChild: any },\n ['_asChild', 'children'],\n )\n\n const [_, linkProps] = Solid.splitProps(\n useLinkProps(rest as unknown as any),\n ['type'],\n )\n\n const children = Solid.createMemo(() => {\n const ch = local.children\n if (typeof ch === 'function') {\n return ch({\n get isActive() {\n return (linkProps as any)['data-status'] === 'active'\n },\n isTransitioning: false,\n })\n }\n\n return ch satisfies Solid.JSX.Element\n })\n\n return (\n <Dynamic component={local._asChild ? local._asChild : 'a'} {...linkProps}>\n {children()}\n </Dynamic>\n )\n}\n\nfunction isCtrlEvent(e: MouseEvent) {\n return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)\n}\n\nexport type LinkOptionsFnOptions<\n TOptions,\n TComp,\n TRouter extends AnyRouter = RegisteredRouter,\n> =\n TOptions extends ReadonlyArray<any>\n ? ValidateLinkOptionsArray<TRouter, TOptions, string, TComp>\n : ValidateLinkOptions<TRouter, TOptions, string, TComp>\n\nexport type LinkOptionsFn<TComp> = <\n const TOptions,\n TRouter extends AnyRouter = RegisteredRouter,\n>(\n options: LinkOptionsFnOptions<TOptions, TComp, TRouter>,\n) => TOptions\n\nexport const linkOptions: LinkOptionsFn<'a'> = (options) => {\n return options as any\n}\n"],"names":["useLinkProps","options","router","useRouter","isTransitioning","setIsTransitioning","Solid","createSignal","hasRenderFetched","local","rest","splitProps","mergeProps","activeProps","class","inactiveProps","_","propsSafeToSpread","type","URL","to","currentSearch","useRouterState","select","s","location","searchStr","getFromPath","activeLocation","useActiveLocation","from","_options","next","createMemo","buildLocation","preload","reloadDocument","defaultPreload","preloadDelay","defaultPreloadDelay","isActive","activeOptions","exact","testExact","exactPathTest","pathname","basepath","currentPathSplit","removeTrailingSlash","split","nextPathSplit","pathIsFuzzyEqual","every","d","i","includeSearch","searchTest","deepEqual","search","partial","ignoreUndefined","explicitUndefined","includeHash","hash","doPreload","preloadRoute","catch","err","console","warn","preloadWarning","preloadViewportIoCallback","entry","isIntersecting","ref","setRef","useIntersectionObserver","rootMargin","disabled","createEffect","href","handleClick","e","isCtrlEvent","defaultPrevented","target","button","preventDefault","unsub","subscribe","navigate","replace","resetScroll","hashScrollIntoView","startTransition","viewTransition","ignoreBlocker","handleFocus","handleTouchStart","handleEnter","eventTarget","preloadTimeout","setTimeout","handleLeave","clearTimeout","callHandler","event","handler","composeEventHandlers","handlers","resolvedActiveProps","functionalUpdate","resolvedInactiveProps","resolvedClassName","filter","Boolean","join","resolvedStyle","style","nextLocation","maskedLocation","undefined","history","createHref","mergeRefs","onClick","onFocus","onMouseEnter","onMouseOver","onMouseLeave","onMouseOut","onTouchStart","Object","keys","length","role","createLink","Comp","props","_$createComponent","Link","_$mergeProps","_asChild","linkProps","children","ch","Dynamic","component","metaKey","altKey","ctrlKey","shiftKey","linkOptions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BO,SAASA,aAOdC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,aAAOA,GAAG;AAAA,QACR,IAAIzG,WAAW;AACb,iBAAQuG,UAAkB,aAAa,MAAM;AAAA,QAC/C;AAAA,QACA3I,iBAAiB;AAAA,MAAA,CAClB;AAAA,IACH;AAEA,WAAO6I;AAAAA,EACT,CAAC;AAED,SAAAN,QAAAA,gBACGO,QAAAA,SAAOL,mBAAA;AAAA,IAAA,IAACM,YAAS;AAAA,aAAE1I,MAAMqI,WAAWrI,MAAMqI,WAAW;AAAA,IAAG;AAAA,EAAA,GAAMC,WAAS;AAAA,IAAA,IAAAC,WAAA;AAAA,aACrEA,SAAAA;AAAAA,IAAU;AAAA,EAAA,CAAA,CAAA;AAGjB;AAEA,SAAS7D,YAAYD,GAAe;AAClC,SAAO,CAAC,EAAEA,EAAEkE,WAAWlE,EAAEmE,UAAUnE,EAAEoE,WAAWpE,EAAEqE;AACpD;AAkBO,MAAMC,cAAmCvJ,CAAAA,YAAY;AAC1D,SAAOA;AACT;;;;;"}
|
|
1
|
+
{"version":3,"file":"link.cjs","sources":["../../src/link.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\n\nimport { mergeRefs } from '@solid-primitives/refs'\n\nimport {\n deepEqual,\n exactPathTest,\n functionalUpdate,\n preloadWarning,\n removeTrailingSlash,\n} from '@tanstack/router-core'\nimport { Dynamic } from 'solid-js/web'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\n\nimport { useIntersectionObserver } from './utils'\n\nimport type {\n AnyRouter,\n Constrain,\n LinkCurrentTargetElement,\n LinkOptions,\n RegisteredRouter,\n RoutePaths,\n} from '@tanstack/router-core'\nimport type {\n ValidateLinkOptions,\n ValidateLinkOptionsArray,\n} from './typePrimitives'\n\nexport function useLinkProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n>(\n options: UseLinkPropsOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Solid.ComponentProps<'a'> {\n const router = useRouter()\n const [isTransitioning, setIsTransitioning] = Solid.createSignal(false)\n let hasRenderFetched = false\n\n const [local, rest] = Solid.splitProps(\n Solid.mergeProps(\n {\n activeProps: () => ({ class: 'active' }),\n inactiveProps: () => ({}),\n },\n options,\n ),\n [\n 'activeProps',\n 'inactiveProps',\n 'activeOptions',\n 'to',\n 'preload',\n 'preloadDelay',\n 'hashScrollIntoView',\n 'replace',\n 'startTransition',\n 'resetScroll',\n 'viewTransition',\n 'target',\n 'disabled',\n 'style',\n 'class',\n 'onClick',\n 'onFocus',\n 'onMouseEnter',\n 'onMouseLeave',\n 'onMouseOver',\n 'onMouseOut',\n 'onTouchStart',\n 'ignoreBlocker',\n ],\n )\n\n // const {\n // // custom props\n // activeProps = () => ({ class: 'active' }),\n // inactiveProps = () => ({}),\n // activeOptions,\n // to,\n // preload: userPreload,\n // preloadDelay: userPreloadDelay,\n // hashScrollIntoView,\n // replace,\n // startTransition,\n // resetScroll,\n // viewTransition,\n // // element props\n // children,\n // target,\n // disabled,\n // style,\n // class,\n // onClick,\n // onFocus,\n // onMouseEnter,\n // onMouseLeave,\n // onTouchStart,\n // ignoreBlocker,\n // ...rest\n // } = options\n\n const [_, propsSafeToSpread] = Solid.splitProps(rest, [\n 'params',\n 'search',\n 'hash',\n 'state',\n 'mask',\n 'reloadDocument',\n 'unsafeRelative',\n ])\n\n const currentSearch = useRouterState({\n select: (s) => s.location.searchStr,\n })\n\n const from = options.from\n\n const _options = () => {\n return {\n ...options,\n from,\n }\n }\n\n const next = Solid.createMemo(() => {\n currentSearch()\n return router.buildLocation(_options() as any)\n })\n\n const hrefOption = Solid.createMemo(() => {\n if (_options().disabled) {\n return undefined\n }\n let href\n const maskedLocation = next().maskedLocation\n if (maskedLocation) {\n href = maskedLocation.url\n } else {\n href = next().url\n }\n let external = false\n if (router.origin) {\n if (href.startsWith(router.origin)) {\n href = href.replace(router.origin, '')\n } else {\n external = true\n }\n }\n return { href, external }\n })\n\n const externalLink = Solid.createMemo(() => {\n const _href = hrefOption()\n if (_href?.external) {\n return _href.href\n }\n try {\n new URL(_options().to as any)\n return _options().to\n } catch {}\n return undefined\n })\n\n const preload = Solid.createMemo(() => {\n if (_options().reloadDocument || externalLink()) {\n return false\n }\n return local.preload ?? router.options.defaultPreload\n })\n const preloadDelay = () =>\n local.preloadDelay ?? router.options.defaultPreloadDelay ?? 0\n\n const isActive = useRouterState({\n select: (s) => {\n if (externalLink()) return false\n if (local.activeOptions?.exact) {\n const testExact = exactPathTest(\n s.location.pathname,\n next().pathname,\n router.basepath,\n )\n if (!testExact) {\n return false\n }\n } else {\n const currentPathSplit = removeTrailingSlash(\n s.location.pathname,\n router.basepath,\n ).split('/')\n const nextPathSplit = removeTrailingSlash(\n next()?.pathname,\n router.basepath,\n )?.split('/')\n\n const pathIsFuzzyEqual = nextPathSplit?.every(\n (d, i) => d === currentPathSplit[i],\n )\n if (!pathIsFuzzyEqual) {\n return false\n }\n }\n\n if (local.activeOptions?.includeSearch ?? true) {\n const searchTest = deepEqual(s.location.search, next().search, {\n partial: !local.activeOptions?.exact,\n ignoreUndefined: !local.activeOptions?.explicitUndefined,\n })\n if (!searchTest) {\n return false\n }\n }\n\n if (local.activeOptions?.includeHash) {\n return s.location.hash === next().hash\n }\n return true\n },\n })\n\n const doPreload = () =>\n router.preloadRoute(_options() as any).catch((err: any) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n\n const preloadViewportIoCallback = (\n entry: IntersectionObserverEntry | undefined,\n ) => {\n if (entry?.isIntersecting) {\n doPreload()\n }\n }\n\n const [ref, setRef] = Solid.createSignal<Element | null>(null)\n\n useIntersectionObserver(\n ref,\n preloadViewportIoCallback,\n { rootMargin: '100px' },\n { disabled: !!local.disabled || !(preload() === 'viewport') },\n )\n\n Solid.createEffect(() => {\n if (hasRenderFetched) {\n return\n }\n if (!local.disabled && preload() === 'render') {\n doPreload()\n hasRenderFetched = true\n }\n })\n\n if (externalLink()) {\n return Solid.mergeProps(\n propsSafeToSpread,\n {\n ref,\n href: externalLink,\n },\n Solid.splitProps(local, [\n 'target',\n 'disabled',\n 'style',\n 'class',\n 'onClick',\n 'onFocus',\n 'onMouseEnter',\n 'onMouseLeave',\n 'onMouseOut',\n 'onMouseOver',\n 'onTouchStart',\n ])[0],\n ) as any\n }\n\n // The click handler\n const handleClick = (e: MouseEvent) => {\n if (\n !local.disabled &&\n !isCtrlEvent(e) &&\n !e.defaultPrevented &&\n (!local.target || local.target === '_self') &&\n e.button === 0\n ) {\n e.preventDefault()\n\n setIsTransitioning(true)\n\n const unsub = router.subscribe('onResolved', () => {\n unsub()\n setIsTransitioning(false)\n })\n\n // All is well? Navigate!\n // N.B. we don't call `router.commitLocation(next) here because we want to run `validateSearch` before committing\n router.navigate({\n ..._options(),\n replace: local.replace,\n resetScroll: local.resetScroll,\n hashScrollIntoView: local.hashScrollIntoView,\n startTransition: local.startTransition,\n viewTransition: local.viewTransition,\n ignoreBlocker: local.ignoreBlocker,\n })\n }\n }\n\n // The click handler\n const handleFocus = (_: MouseEvent) => {\n if (local.disabled) return\n if (preload()) {\n doPreload()\n }\n }\n\n const handleTouchStart = handleFocus\n\n const handleEnter = (e: MouseEvent) => {\n if (local.disabled) return\n const eventTarget = (e.target || {}) as LinkCurrentTargetElement\n\n if (preload()) {\n if (eventTarget.preloadTimeout) {\n return\n }\n\n eventTarget.preloadTimeout = setTimeout(() => {\n eventTarget.preloadTimeout = null\n doPreload()\n }, preloadDelay())\n }\n }\n\n const handleLeave = (e: MouseEvent) => {\n if (local.disabled) return\n const eventTarget = (e.target || {}) as LinkCurrentTargetElement\n\n if (eventTarget.preloadTimeout) {\n clearTimeout(eventTarget.preloadTimeout)\n eventTarget.preloadTimeout = null\n }\n }\n\n /** Call a JSX.EventHandlerUnion with the event. */\n function callHandler<T, TEvent extends Event>(\n event: TEvent & { currentTarget: T; target: Element },\n handler: Solid.JSX.EventHandlerUnion<T, TEvent> | undefined,\n ) {\n if (handler) {\n if (typeof handler === 'function') {\n handler(event)\n } else {\n handler[0](handler[1], event)\n }\n }\n\n return event.defaultPrevented\n }\n\n function composeEventHandlers<T>(\n handlers: Array<Solid.JSX.EventHandlerUnion<T, any> | undefined>,\n ) {\n return (event: any) => {\n for (const handler of handlers) {\n callHandler(event, handler)\n }\n }\n }\n\n // Get the active props\n const resolvedActiveProps: () => Omit<Solid.ComponentProps<'a'>, 'style'> & {\n style?: Solid.JSX.CSSProperties\n } = () =>\n isActive() ? (functionalUpdate(local.activeProps as any, {}) ?? {}) : {}\n\n // Get the inactive props\n const resolvedInactiveProps: () => Omit<\n Solid.ComponentProps<'a'>,\n 'style'\n > & { style?: Solid.JSX.CSSProperties } = () =>\n isActive() ? {} : functionalUpdate(local.inactiveProps, {})\n\n const resolvedClassName = () =>\n [local.class, resolvedActiveProps().class, resolvedInactiveProps().class]\n .filter(Boolean)\n .join(' ')\n\n const resolvedStyle = () => ({\n ...local.style,\n ...resolvedActiveProps().style,\n ...resolvedInactiveProps().style,\n })\n\n return Solid.mergeProps(\n propsSafeToSpread,\n resolvedActiveProps,\n resolvedInactiveProps,\n () => {\n return {\n href: hrefOption()?.href,\n ref: mergeRefs(setRef, _options().ref),\n onClick: composeEventHandlers([local.onClick, handleClick]),\n onFocus: composeEventHandlers([local.onFocus, handleFocus]),\n onMouseEnter: composeEventHandlers([local.onMouseEnter, handleEnter]),\n onMouseOver: composeEventHandlers([local.onMouseOver, handleEnter]),\n onMouseLeave: composeEventHandlers([local.onMouseLeave, handleLeave]),\n onMouseOut: composeEventHandlers([local.onMouseOut, handleLeave]),\n onTouchStart: composeEventHandlers([\n local.onTouchStart,\n handleTouchStart,\n ]),\n disabled: !!local.disabled,\n target: local.target,\n ...(Object.keys(resolvedStyle).length && { style: resolvedStyle }),\n ...(resolvedClassName() && { class: resolvedClassName() }),\n ...(local.disabled && {\n role: 'link',\n 'aria-disabled': true,\n }),\n ...(isActive() && { 'data-status': 'active', 'aria-current': 'page' }),\n ...(isTransitioning() && { 'data-transitioning': 'transitioning' }),\n }\n },\n ) as any\n}\n\nexport type UseLinkPropsOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '.',\n> = ActiveLinkOptions<'a', TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n Omit<Solid.ComponentProps<'a'>, 'style'> & { style?: Solid.JSX.CSSProperties }\n\nexport type ActiveLinkOptions<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = LinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n ActiveLinkOptionProps<TComp>\n\ntype ActiveLinkProps<TComp> = Partial<\n LinkComponentSolidProps<TComp> & {\n [key: `data-${string}`]: unknown\n }\n>\n\nexport interface ActiveLinkOptionProps<TComp = 'a'> {\n /**\n * A function that returns additional props for the `active` state of this link.\n * These props override other props passed to the link (`style`'s are merged, `class`'s are concatenated)\n */\n activeProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>)\n /**\n * A function that returns additional props for the `inactive` state of this link.\n * These props override other props passed to the link (`style`'s are merged, `class`'s are concatenated)\n */\n inactiveProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>)\n}\n\nexport type LinkProps<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ActiveLinkOptions<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n LinkPropsChildren\n\nexport interface LinkPropsChildren {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | Solid.JSX.Element\n | ((state: {\n isActive: boolean\n isTransitioning: boolean\n }) => Solid.JSX.Element)\n}\n\ntype LinkComponentSolidProps<TComp> = TComp extends Solid.ValidComponent\n ? Omit<Solid.ComponentProps<TComp>, keyof CreateLinkProps>\n : never\n\nexport type LinkComponentProps<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = LinkComponentSolidProps<TComp> &\n LinkProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type CreateLinkProps = LinkProps<\n any,\n any,\n string,\n string,\n string,\n string\n>\n\nexport type LinkComponent<\n in out TComp,\n in out TDefaultFrom extends string = string,\n> = <\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = TDefaultFrom,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n props: LinkComponentProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n) => Solid.JSX.Element\n\nexport interface LinkComponentRoute<\n in out TDefaultFrom extends string = string,\n> {\n defaultFrom: TDefaultFrom\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n props: LinkComponentProps<\n 'a',\n TRouter,\n this['defaultFrom'],\n TTo,\n this['defaultFrom'],\n TMaskTo\n >,\n ): Solid.JSX.Element\n}\n\nexport function createLink<const TComp>(\n Comp: Constrain<TComp, any, (props: CreateLinkProps) => Solid.JSX.Element>,\n): LinkComponent<TComp> {\n return (props) => <Link {...props} _asChild={Comp} />\n}\n\nexport const Link: LinkComponent<'a'> = (props) => {\n const [local, rest] = Solid.splitProps(\n props as typeof props & { _asChild: any },\n ['_asChild', 'children'],\n )\n\n const [_, linkProps] = Solid.splitProps(\n useLinkProps(rest as unknown as any),\n ['type'],\n )\n\n const children = Solid.createMemo(() => {\n const ch = local.children\n if (typeof ch === 'function') {\n return ch({\n get isActive() {\n return (linkProps as any)['data-status'] === 'active'\n },\n isTransitioning: false,\n })\n }\n\n return ch satisfies Solid.JSX.Element\n })\n\n return (\n <Dynamic component={local._asChild ? local._asChild : 'a'} {...linkProps}>\n {children()}\n </Dynamic>\n )\n}\n\nfunction isCtrlEvent(e: MouseEvent) {\n return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)\n}\n\nexport type LinkOptionsFnOptions<\n TOptions,\n TComp,\n TRouter extends AnyRouter = RegisteredRouter,\n> =\n TOptions extends ReadonlyArray<any>\n ? ValidateLinkOptionsArray<TRouter, TOptions, string, TComp>\n : ValidateLinkOptions<TRouter, TOptions, string, TComp>\n\nexport type LinkOptionsFn<TComp> = <\n const TOptions,\n TRouter extends AnyRouter = RegisteredRouter,\n>(\n options: LinkOptionsFnOptions<TOptions, TComp, TRouter>,\n) => TOptions\n\nexport const linkOptions: LinkOptionsFn<'a'> = (options) => {\n return options as any\n}\n"],"names":["useLinkProps","options","router","useRouter","isTransitioning","setIsTransitioning","Solid","createSignal","hasRenderFetched","local","rest","splitProps","mergeProps","activeProps","class","inactiveProps","_","propsSafeToSpread","currentSearch","useRouterState","select","s","location","searchStr","from","_options","next","createMemo","buildLocation","hrefOption","disabled","undefined","href","maskedLocation","url","external","origin","startsWith","replace","externalLink","_href","URL","to","preload","reloadDocument","defaultPreload","preloadDelay","defaultPreloadDelay","isActive","activeOptions","exact","testExact","exactPathTest","pathname","basepath","currentPathSplit","removeTrailingSlash","split","nextPathSplit","pathIsFuzzyEqual","every","d","i","includeSearch","searchTest","deepEqual","search","partial","ignoreUndefined","explicitUndefined","includeHash","hash","doPreload","preloadRoute","catch","err","console","warn","preloadWarning","preloadViewportIoCallback","entry","isIntersecting","ref","setRef","useIntersectionObserver","rootMargin","createEffect","handleClick","e","isCtrlEvent","defaultPrevented","target","button","preventDefault","unsub","subscribe","navigate","resetScroll","hashScrollIntoView","startTransition","viewTransition","ignoreBlocker","handleFocus","handleTouchStart","handleEnter","eventTarget","preloadTimeout","setTimeout","handleLeave","clearTimeout","callHandler","event","handler","composeEventHandlers","handlers","resolvedActiveProps","functionalUpdate","resolvedInactiveProps","resolvedClassName","filter","Boolean","join","resolvedStyle","style","mergeRefs","onClick","onFocus","onMouseEnter","onMouseOver","onMouseLeave","onMouseOut","onTouchStart","Object","keys","length","role","createLink","Comp","props","_$createComponent","Link","_$mergeProps","_asChild","linkProps","children","ch","Dynamic","component","metaKey","altKey","ctrlKey","shiftKey","linkOptions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8BO,SAASA,aAOdC,SAC2B;AAC3B,QAAMC,SAASC,UAAAA,UAAAA;AACf,QAAM,CAACC,iBAAiBC,kBAAkB,IAAIC,iBAAMC,aAAa,KAAK;AACtE,MAAIC,mBAAmB;AAEvB,QAAM,CAACC,OAAOC,IAAI,IAAIJ,iBAAMK,WAC1BL,iBAAMM,WACJ;AAAA,IACEC,aAAaA,OAAO;AAAA,MAAEC,OAAO;AAAA,IAAA;AAAA,IAC7BC,eAAeA,OAAO,CAAA;AAAA,EAAC,GAEzBd,OACF,GACA,CACE,eACA,iBACA,iBACA,MACA,WACA,gBACA,sBACA,WACA,mBACA,eACA,kBACA,UACA,YACA,SACA,SACA,WACA,WACA,gBACA,gBACA,eACA,cACA,gBACA,eAAe,CAEnB;AA8BA,QAAM,CAACe,GAAGC,iBAAiB,IAAIX,iBAAMK,WAAWD,MAAM,CACpD,UACA,UACA,QACA,SACA,QACA,kBACA,gBAAgB,CACjB;AAED,QAAMQ,gBAAgBC,eAAAA,eAAe;AAAA,IACnCC,QAASC,CAAAA,MAAMA,EAAEC,SAASC;AAAAA,EAAAA,CAC3B;AAED,QAAMC,OAAOvB,QAAQuB;AAErB,QAAMC,WAAWA,MAAM;AACrB,WAAO;AAAA,MACL,GAAGxB;AAAAA,MACHuB;AAAAA,IAAAA;AAAAA,EAEJ;AAEA,QAAME,OAAOpB,iBAAMqB,WAAW,MAAM;AA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|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const Solid = require("solid-js");
|
|
4
4
|
const useRouter = require("./useRouter.cjs");
|
|
5
|
-
const useActiveLocation = require("./useActiveLocation.cjs");
|
|
6
5
|
function _interopNamespaceDefault(e) {
|
|
7
6
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
7
|
if (e) {
|
|
@@ -22,16 +21,10 @@ function _interopNamespaceDefault(e) {
|
|
|
22
21
|
const Solid__namespace = /* @__PURE__ */ _interopNamespaceDefault(Solid);
|
|
23
22
|
function useNavigate(_defaultOpts) {
|
|
24
23
|
const router = useRouter.useRouter();
|
|
25
|
-
const {
|
|
26
|
-
getFromPath,
|
|
27
|
-
setActiveLocation
|
|
28
|
-
} = useActiveLocation.useActiveLocation(router.latestLocation);
|
|
29
24
|
return (options) => {
|
|
30
|
-
setActiveLocation(router.latestLocation);
|
|
31
|
-
const from = getFromPath(options.from ?? _defaultOpts?.from);
|
|
32
25
|
return router.navigate({
|
|
33
26
|
...options,
|
|
34
|
-
from: from
|
|
27
|
+
from: options.from ?? _defaultOpts?.from
|
|
35
28
|
});
|
|
36
29
|
};
|
|
37
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigate.cjs","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { useRouter } from './useRouter'\nimport
|
|
1
|
+
{"version":3,"file":"useNavigate.cjs","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n FromPathOption,\n NavigateOptions,\n RegisteredRouter,\n UseNavigateResult,\n} from '@tanstack/router-core'\n\nexport function useNavigate<\n TRouter extends AnyRouter = RegisteredRouter,\n TDefaultFrom extends string = string,\n>(_defaultOpts?: {\n from?: FromPathOption<TRouter, TDefaultFrom>\n}): UseNavigateResult<TDefaultFrom> {\n const router = useRouter()\n\n return ((options: NavigateOptions) => {\n return router.navigate({\n ...options,\n from: options.from ?? _defaultOpts?.from,\n })\n }) as UseNavigateResult<TDefaultFrom>\n}\n\nexport function Navigate<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null {\n const { navigate } = useRouter()\n\n Solid.onMount(() => {\n navigate({\n ...props,\n })\n })\n\n return null\n}\n"],"names":["useNavigate","_defaultOpts","router","useRouter","options","navigate","from","Navigate","props","Solid","onMount"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAUO,SAASA,YAGdC,cAEkC;AAClC,QAAMC,SAASC,UAAAA,UAAAA;AAEf,SAAQ,CAACC,YAA6B;AACpC,WAAOF,OAAOG,SAAS;AAAA,MACrB,GAAGD;AAAAA,MACHE,MAAMF,QAAQE,QAAQL,cAAcK;AAAAA,IAAAA,CACrC;AAAA,EACH;AACF;AAEO,SAASC,SAMdC,OAAuE;AACvE,QAAM;AAAA,IAAEH;AAAAA,EAAAA,IAAaF,oBAAAA;AAErBM,mBAAMC,QAAQ,MAAM;AAClBL,aAAS;AAAA,MACP,GAAGG;AAAAA,IAAAA,CACJ;AAAA,EACH,CAAC;AAED,SAAO;AACT;;;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { defer, TSR_DEFERRED_PROMISE, isMatch, joinPaths, cleanPath, trimPathLeft, trimPathRight, trimPath, resolvePath, parsePathname, interpolatePath, matchPathname,
|
|
1
|
+
export { defer, TSR_DEFERRED_PROMISE, isMatch, joinPaths, cleanPath, trimPathLeft, trimPathRight, trimPath, resolvePath, parsePathname, interpolatePath, matchPathname, matchByPath, rootRouteId, defaultSerializeError, defaultParseSearch, defaultStringifySearch, parseSearchWith, stringifySearchWith, functionalUpdate, replaceEqualDeep, isPlainObject, isPlainArray, deepEqual, createControlledPromise, retainSearchParams, stripSearchParams, createSerializationAdapter, } from '@tanstack/router-core';
|
|
2
2
|
export type { DeferredPromiseState, DeferredPromise, ParsedLocation, RemoveTrailingSlashes, RemoveLeadingSlashes, ActiveOptions, Segment, ResolveRelativePath, RootRouteId, AnyPathParams, ResolveParams, ResolveOptionalParams, ResolveRequiredParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, UpdatableStaticRouteOption, MetaDescriptor, RouteLinkEntry, ParseParamsFn, SearchFilter, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, TrimPath, TrimPathLeft, TrimPathRight, StringifyParamsFn, ParamsOptions, InferAllParams, InferAllContext, LooseReturnType, LooseAsyncReturnType, ContextReturnType, ContextAsyncReturnType, ResolveLoaderData, ResolveRouteContext, SearchSerializer, SearchParser, TrailingSlashOption, Manifest, RouterManagedTag, ControlledPromise, Constrain, Expand, MergeAll, Assign, IntersectAssign, ResolveValidatorInput, ResolveValidatorOutput, AnyValidator, DefaultValidator, ValidatorFn, AnySchema, AnyValidatorAdapter, AnyValidatorFn, AnyValidatorObj, ResolveValidatorInputFn, ResolveValidatorOutputFn, ResolveSearchValidatorInput, ResolveSearchValidatorInputFn, Validator, ValidatorAdapter, ValidatorObj, NavigateFn, BuildLocationFn, InferDescendantToPaths, RelativeToPath, RelativeToParentPath, RelativeToCurrentPath, Register, AbsoluteToPath, RelativeToPathAutoComplete, NavigateOptions, ToOptions, ToMaskOptions, ToSubOptions, ResolveRoute, SearchParamOptions, PathParamOptions, ToPathOption, LinkOptions, MakeOptionalPathParams, AnyRouterWithContext, ParseRoute, RoutesById, RouteById, RouteIds, RoutesByPath, RouteByPath, RoutePaths, FullSearchSchema, AllParams, AllLoaderData, FullSearchSchemaInput, AllContext, CommitLocationOptions, MatchLocation, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, ResolveAllParamsFromParent, RouteContextParameter, BeforeLoadContextParameter, ResolveAllContext, FullSearchSchemaOption, MakeRemountDepsOptionsUnion, RemountDepsOptions, FileRouteTypes, FileRoutesByPath, UseNavigateResult, AnyRedirect, Redirect, RedirectOptions, ResolvedRedirect, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, RouteLoaderFn, LoaderFnContext, MakeRouteMatch, MakeRouteMatchUnion, RouteMatch, AnyRouteMatch, RouteContextFn, RouteContextOptions, BeforeLoadFn, BeforeLoadContextOptions, ContextOptions, RootRouteOptions, AnyRouteWithContext, LazyRouteOptions, AnyRoute, ResolveFullPath, RouteConstraints, RouterState, ListenerFn, BuildNextOptions, AnyRouter, RegisteredRouter, RouterEvents, RouterEvent, RouterListener, MatchRouteOptions, RouteMask, RouterContextOptions, RouterOptions, RouterConstructorOptions, ControllablePromise, InjectedHtmlEntry, CreateFileRoute, CreateLazyFileRoute, AnySerializationAdapter, SerializationAdapter, } from '@tanstack/router-core';
|
|
3
3
|
export { createHistory, createBrowserHistory, createHashHistory, createMemoryHistory, } from '@tanstack/history';
|
|
4
4
|
export type { BlockerFn, HistoryLocation, RouterHistory, ParsedPath, HistoryState, } from '@tanstack/history';
|
|
@@ -47,3 +47,5 @@ export { ScriptOnce } from './ScriptOnce.js';
|
|
|
47
47
|
export { Asset } from './Asset.js';
|
|
48
48
|
export { HeadContent, useTags } from './HeadContent.js';
|
|
49
49
|
export { Scripts } from './Scripts.js';
|
|
50
|
+
export { rewriteBasepath, composeRewrites } from '@tanstack/router-core';
|
|
51
|
+
export type { LocationRewrite, LocationRewriteFunction, } from '@tanstack/router-core';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PathParamError, SearchParamError, TSR_DEFERRED_PROMISE, cleanPath, componentTypes, createControlledPromise, createSerializationAdapter, deepEqual, defaultParseSearch, defaultSerializeError, defaultStringifySearch, defer, functionalUpdate, getInitialRouterState, interpolatePath, isMatch, isNotFound, isPlainArray, isPlainObject, isRedirect, joinPaths, lazyFn, matchByPath, matchPathname, notFound, parsePathname, parseSearchWith, redirect,
|
|
1
|
+
import { PathParamError, SearchParamError, TSR_DEFERRED_PROMISE, cleanPath, componentTypes, composeRewrites, createControlledPromise, createSerializationAdapter, deepEqual, defaultParseSearch, defaultSerializeError, defaultStringifySearch, defer, functionalUpdate, getInitialRouterState, interpolatePath, isMatch, isNotFound, isPlainArray, isPlainObject, isRedirect, joinPaths, lazyFn, matchByPath, matchPathname, notFound, parsePathname, parseSearchWith, redirect, replaceEqualDeep, resolvePath, retainSearchParams, rewriteBasepath, rootRouteId, stringifySearchWith, stripSearchParams, trimPath, trimPathLeft, trimPathRight } from "@tanstack/router-core";
|
|
2
2
|
import { createBrowserHistory, createHashHistory, createHistory, createMemoryHistory } from "@tanstack/history";
|
|
3
3
|
import { Await, useAwaited } from "./awaited.js";
|
|
4
4
|
import { CatchBoundary, ErrorComponent } from "./CatchBoundary.js";
|
|
@@ -66,6 +66,7 @@ export {
|
|
|
66
66
|
TSR_DEFERRED_PROMISE,
|
|
67
67
|
cleanPath,
|
|
68
68
|
componentTypes,
|
|
69
|
+
composeRewrites,
|
|
69
70
|
createBrowserHistory,
|
|
70
71
|
createControlledPromise,
|
|
71
72
|
createFileRoute,
|
|
@@ -107,10 +108,10 @@ export {
|
|
|
107
108
|
parsePathname,
|
|
108
109
|
parseSearchWith,
|
|
109
110
|
redirect,
|
|
110
|
-
removeBasepath,
|
|
111
111
|
replaceEqualDeep,
|
|
112
112
|
resolvePath,
|
|
113
113
|
retainSearchParams,
|
|
114
|
+
rewriteBasepath,
|
|
114
115
|
rootRouteId,
|
|
115
116
|
rootRouteWithContext,
|
|
116
117
|
stringifySearchWith,
|
package/dist/esm/link.js
CHANGED
|
@@ -5,7 +5,6 @@ import { functionalUpdate, preloadWarning, exactPathTest, removeTrailingSlash, d
|
|
|
5
5
|
import { useRouterState } from "./useRouterState.js";
|
|
6
6
|
import { useRouter } from "./useRouter.js";
|
|
7
7
|
import { useIntersectionObserver } from "./utils.js";
|
|
8
|
-
import { useActiveLocation } from "./useActiveLocation.js";
|
|
9
8
|
function useLinkProps(options) {
|
|
10
9
|
const router = useRouter();
|
|
11
10
|
const [isTransitioning, setIsTransitioning] = Solid.createSignal(false);
|
|
@@ -17,35 +16,58 @@ function useLinkProps(options) {
|
|
|
17
16
|
inactiveProps: () => ({})
|
|
18
17
|
}, options), ["activeProps", "inactiveProps", "activeOptions", "to", "preload", "preloadDelay", "hashScrollIntoView", "replace", "startTransition", "resetScroll", "viewTransition", "target", "disabled", "style", "class", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onMouseOver", "onMouseOut", "onTouchStart", "ignoreBlocker"]);
|
|
19
18
|
const [_, propsSafeToSpread] = Solid.splitProps(rest, ["params", "search", "hash", "state", "mask", "reloadDocument", "unsafeRelative"]);
|
|
20
|
-
const type = () => {
|
|
21
|
-
try {
|
|
22
|
-
new URL(`${local.to}`);
|
|
23
|
-
return "external";
|
|
24
|
-
} catch {
|
|
25
|
-
}
|
|
26
|
-
return "internal";
|
|
27
|
-
};
|
|
28
19
|
const currentSearch = useRouterState({
|
|
29
20
|
select: (s) => s.location.searchStr
|
|
30
21
|
});
|
|
31
|
-
const
|
|
32
|
-
getFromPath,
|
|
33
|
-
activeLocation
|
|
34
|
-
} = useActiveLocation();
|
|
35
|
-
const from = getFromPath(options.from);
|
|
22
|
+
const from = options.from;
|
|
36
23
|
const _options = () => {
|
|
37
24
|
return {
|
|
38
25
|
...options,
|
|
39
|
-
from
|
|
26
|
+
from
|
|
40
27
|
};
|
|
41
28
|
};
|
|
42
29
|
const next = Solid.createMemo(() => {
|
|
43
30
|
currentSearch();
|
|
44
|
-
activeLocation();
|
|
45
31
|
return router.buildLocation(_options());
|
|
46
32
|
});
|
|
33
|
+
const hrefOption = Solid.createMemo(() => {
|
|
34
|
+
if (_options().disabled) {
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
let href;
|
|
38
|
+
const maskedLocation = next().maskedLocation;
|
|
39
|
+
if (maskedLocation) {
|
|
40
|
+
href = maskedLocation.url;
|
|
41
|
+
} else {
|
|
42
|
+
href = next().url;
|
|
43
|
+
}
|
|
44
|
+
let external = false;
|
|
45
|
+
if (router.origin) {
|
|
46
|
+
if (href.startsWith(router.origin)) {
|
|
47
|
+
href = href.replace(router.origin, "");
|
|
48
|
+
} else {
|
|
49
|
+
external = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
href,
|
|
54
|
+
external
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
const externalLink = Solid.createMemo(() => {
|
|
58
|
+
const _href = hrefOption();
|
|
59
|
+
if (_href?.external) {
|
|
60
|
+
return _href.href;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
new URL(_options().to);
|
|
64
|
+
return _options().to;
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
return void 0;
|
|
68
|
+
});
|
|
47
69
|
const preload = Solid.createMemo(() => {
|
|
48
|
-
if (_options().reloadDocument) {
|
|
70
|
+
if (_options().reloadDocument || externalLink()) {
|
|
49
71
|
return false;
|
|
50
72
|
}
|
|
51
73
|
return local.preload ?? router.options.defaultPreload;
|
|
@@ -53,6 +75,7 @@ function useLinkProps(options) {
|
|
|
53
75
|
const preloadDelay = () => local.preloadDelay ?? router.options.defaultPreloadDelay ?? 0;
|
|
54
76
|
const isActive = useRouterState({
|
|
55
77
|
select: (s) => {
|
|
78
|
+
if (externalLink()) return false;
|
|
56
79
|
if (local.activeOptions?.exact) {
|
|
57
80
|
const testExact = exactPathTest(s.location.pathname, next().pathname, router.basepath);
|
|
58
81
|
if (!testExact) {
|
|
@@ -105,15 +128,10 @@ function useLinkProps(options) {
|
|
|
105
128
|
hasRenderFetched = true;
|
|
106
129
|
}
|
|
107
130
|
});
|
|
108
|
-
if (
|
|
131
|
+
if (externalLink()) {
|
|
109
132
|
return Solid.mergeProps(propsSafeToSpread, {
|
|
110
133
|
ref,
|
|
111
|
-
|
|
112
|
-
return type();
|
|
113
|
-
},
|
|
114
|
-
get href() {
|
|
115
|
-
return local.to;
|
|
116
|
-
}
|
|
134
|
+
href: externalLink
|
|
117
135
|
}, Solid.splitProps(local, ["target", "disabled", "style", "class", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onMouseOut", "onMouseOver", "onTouchStart"])[0]);
|
|
118
136
|
}
|
|
119
137
|
const handleClick = (e) => {
|
|
@@ -188,14 +206,9 @@ function useLinkProps(options) {
|
|
|
188
206
|
...resolvedActiveProps().style,
|
|
189
207
|
...resolvedInactiveProps().style
|
|
190
208
|
});
|
|
191
|
-
const href = Solid.createMemo(() => {
|
|
192
|
-
const nextLocation = next();
|
|
193
|
-
const maskedLocation = nextLocation?.maskedLocation;
|
|
194
|
-
return _options().disabled ? void 0 : maskedLocation ? router.history.createHref(maskedLocation.href) : router.history.createHref(nextLocation?.href);
|
|
195
|
-
});
|
|
196
209
|
return Solid.mergeProps(propsSafeToSpread, resolvedActiveProps, resolvedInactiveProps, () => {
|
|
197
210
|
return {
|
|
198
|
-
href:
|
|
211
|
+
href: hrefOption()?.href,
|
|
199
212
|
ref: mergeRefs(setRef, _options().ref),
|
|
200
213
|
onClick: composeEventHandlers([local.onClick, handleClick]),
|
|
201
214
|
onFocus: composeEventHandlers([local.onFocus, handleFocus]),
|