@tanstack/vue-router 0.0.1 → 1.140.1
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/LICENSE +21 -0
- package/README.md +66 -45
- package/dist/esm/Asset.d.ts +2 -0
- package/dist/esm/Asset.js +33 -0
- package/dist/esm/Asset.js.map +1 -0
- package/dist/esm/CatchBoundary.d.ts +19 -0
- package/dist/esm/CatchBoundary.js +135 -0
- package/dist/esm/CatchBoundary.js.map +1 -0
- package/dist/esm/ClientOnly.d.ts +67 -0
- package/dist/esm/HeadContent.d.ts +10 -0
- package/dist/esm/HeadContent.js +116 -0
- package/dist/esm/HeadContent.js.map +1 -0
- package/dist/esm/Match.d.ts +25 -0
- package/dist/esm/Match.js +262 -0
- package/dist/esm/Match.js.map +1 -0
- package/dist/esm/Matches.d.ts +39 -0
- package/dist/esm/Matches.js +186 -0
- package/dist/esm/Matches.js.map +1 -0
- package/dist/esm/RouterProvider.d.ts +33 -0
- package/dist/esm/RouterProvider.js +65 -0
- package/dist/esm/RouterProvider.js.map +1 -0
- package/dist/esm/SafeFragment.d.ts +4 -0
- package/dist/esm/ScriptOnce.d.ts +5 -0
- package/dist/esm/ScriptOnce.js +21 -0
- package/dist/esm/ScriptOnce.js.map +1 -0
- package/dist/esm/Scripts.d.ts +1 -0
- package/dist/esm/Scripts.js +46 -0
- package/dist/esm/Scripts.js.map +1 -0
- package/dist/esm/ScrollRestoration.d.ts +14 -0
- package/dist/esm/ScrollRestoration.js +36 -0
- package/dist/esm/ScrollRestoration.js.map +1 -0
- package/dist/esm/Transitioner.d.ts +2 -0
- package/dist/esm/Transitioner.js +154 -0
- package/dist/esm/Transitioner.js.map +1 -0
- package/dist/esm/awaited.d.ts +12 -0
- package/dist/esm/awaited.js +40 -0
- package/dist/esm/awaited.js.map +1 -0
- package/dist/esm/fileRoute.d.ts +54 -0
- package/dist/esm/fileRoute.js +103 -0
- package/dist/esm/fileRoute.js.map +1 -0
- package/dist/esm/history.d.ts +8 -0
- package/dist/esm/index.d.ts +51 -0
- package/dist/esm/index.js +138 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lazyRouteComponent.d.ts +8 -0
- package/dist/esm/lazyRouteComponent.js +106 -0
- package/dist/esm/lazyRouteComponent.js.map +1 -0
- package/dist/esm/link.d.ts +61 -0
- package/dist/esm/link.js +376 -0
- package/dist/esm/link.js.map +1 -0
- package/dist/esm/matchContext.d.ts +20 -0
- package/dist/esm/matchContext.js +16 -0
- package/dist/esm/matchContext.js.map +1 -0
- package/dist/esm/not-found.d.ts +12 -0
- package/dist/esm/not-found.js +45 -0
- package/dist/esm/not-found.js.map +1 -0
- package/dist/esm/renderRouteNotFound.d.ts +11 -0
- package/dist/esm/renderRouteNotFound.js +19 -0
- package/dist/esm/renderRouteNotFound.js.map +1 -0
- package/dist/esm/route.d.ts +96 -0
- package/dist/esm/route.js +176 -0
- package/dist/esm/route.js.map +1 -0
- package/dist/esm/router.d.ts +69 -0
- package/dist/esm/router.js +14 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/esm/routerContext.d.ts +21 -0
- package/dist/esm/routerContext.js +21 -0
- package/dist/esm/routerContext.js.map +1 -0
- package/dist/esm/scroll-restoration.d.ts +1 -0
- package/dist/esm/scroll-restoration.js +21 -0
- package/dist/esm/scroll-restoration.js.map +1 -0
- package/dist/esm/typePrimitives.d.ts +10 -0
- package/dist/esm/useBlocker.d.ts +66 -0
- package/dist/esm/useBlocker.js +295 -0
- package/dist/esm/useBlocker.js.map +1 -0
- package/dist/esm/useCanGoBack.d.ts +1 -0
- package/dist/esm/useCanGoBack.js +8 -0
- package/dist/esm/useCanGoBack.js.map +1 -0
- package/dist/esm/useLoaderData.d.ts +8 -0
- package/dist/esm/useLoaderData.js +14 -0
- package/dist/esm/useLoaderData.js.map +1 -0
- package/dist/esm/useLoaderDeps.d.ts +7 -0
- package/dist/esm/useLoaderDeps.js +17 -0
- package/dist/esm/useLoaderDeps.js.map +1 -0
- package/dist/esm/useLocation.d.ts +7 -0
- package/dist/esm/useLocation.js +10 -0
- package/dist/esm/useLocation.js.map +1 -0
- package/dist/esm/useMatch.d.ts +10 -0
- package/dist/esm/useMatch.js +39 -0
- package/dist/esm/useMatch.js.map +1 -0
- package/dist/esm/useNavigate.d.ts +5 -0
- package/dist/esm/useNavigate.js +29 -0
- package/dist/esm/useNavigate.js.map +1 -0
- package/dist/esm/useParams.d.ts +9 -0
- package/dist/esm/useParams.js +15 -0
- package/dist/esm/useParams.js.map +1 -0
- package/dist/esm/useRouteContext.d.ts +4 -0
- package/dist/esm/useRouteContext.js +11 -0
- package/dist/esm/useRouteContext.js.map +1 -0
- package/dist/esm/useRouter.d.ts +4 -0
- package/dist/esm/useRouter.js +12 -0
- package/dist/esm/useRouter.js.map +1 -0
- package/dist/esm/useRouterState.d.ts +8 -0
- package/dist/esm/useRouterState.js +20 -0
- package/dist/esm/useRouterState.js.map +1 -0
- package/dist/esm/useSearch.d.ts +9 -0
- package/dist/esm/useSearch.js +15 -0
- package/dist/esm/useSearch.js.map +1 -0
- package/dist/esm/utils.d.ts +40 -0
- package/dist/esm/utils.js +44 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/source/Asset.d.ts +2 -0
- package/dist/source/Asset.jsx +22 -0
- package/dist/source/Asset.jsx.map +1 -0
- package/dist/source/CatchBoundary.d.ts +19 -0
- package/dist/source/CatchBoundary.jsx +134 -0
- package/dist/source/CatchBoundary.jsx.map +1 -0
- package/dist/source/ClientOnly.d.ts +67 -0
- package/dist/source/ClientOnly.jsx +63 -0
- package/dist/source/ClientOnly.jsx.map +1 -0
- package/dist/source/HeadContent.d.ts +10 -0
- package/dist/source/HeadContent.jsx +133 -0
- package/dist/source/HeadContent.jsx.map +1 -0
- package/dist/source/Match.d.ts +25 -0
- package/dist/source/Match.jsx +316 -0
- package/dist/source/Match.jsx.map +1 -0
- package/dist/source/Matches.d.ts +39 -0
- package/dist/source/Matches.jsx +191 -0
- package/dist/source/Matches.jsx.map +1 -0
- package/dist/source/RouterProvider.d.ts +33 -0
- package/dist/source/RouterProvider.jsx +63 -0
- package/dist/source/RouterProvider.jsx.map +1 -0
- package/dist/source/SafeFragment.d.ts +4 -0
- package/dist/source/SafeFragment.jsx +10 -0
- package/dist/source/SafeFragment.jsx.map +1 -0
- package/dist/source/ScriptOnce.d.ts +5 -0
- package/dist/source/ScriptOnce.jsx +17 -0
- package/dist/source/ScriptOnce.jsx.map +1 -0
- package/dist/source/Scripts.d.ts +1 -0
- package/dist/source/Scripts.jsx +49 -0
- package/dist/source/Scripts.jsx.map +1 -0
- package/dist/source/ScrollRestoration.d.ts +14 -0
- package/dist/source/ScrollRestoration.jsx +37 -0
- package/dist/source/ScrollRestoration.jsx.map +1 -0
- package/dist/source/Transitioner.d.ts +2 -0
- package/dist/source/Transitioner.jsx +181 -0
- package/dist/source/Transitioner.jsx.map +1 -0
- package/dist/source/awaited.d.ts +12 -0
- package/dist/source/awaited.jsx +38 -0
- package/dist/source/awaited.jsx.map +1 -0
- package/dist/source/fileRoute.d.ts +54 -0
- package/dist/source/fileRoute.js +98 -0
- package/dist/source/fileRoute.js.map +1 -0
- package/dist/source/history.d.ts +8 -0
- package/dist/source/history.js +2 -0
- package/dist/source/history.js.map +1 -0
- package/dist/source/index.d.ts +51 -0
- package/dist/source/index.jsx +40 -0
- package/dist/source/index.jsx.map +1 -0
- package/dist/source/lazyRouteComponent.d.ts +8 -0
- package/dist/source/lazyRouteComponent.jsx +135 -0
- package/dist/source/lazyRouteComponent.jsx.map +1 -0
- package/dist/source/link.d.ts +61 -0
- package/dist/source/link.jsx +495 -0
- package/dist/source/link.jsx.map +1 -0
- package/dist/source/matchContext.d.ts +20 -0
- package/dist/source/matchContext.jsx +32 -0
- package/dist/source/matchContext.jsx.map +1 -0
- package/dist/source/not-found.d.ts +12 -0
- package/dist/source/not-found.jsx +48 -0
- package/dist/source/not-found.jsx.map +1 -0
- package/dist/source/renderRouteNotFound.d.ts +11 -0
- package/dist/source/renderRouteNotFound.jsx +24 -0
- package/dist/source/renderRouteNotFound.jsx.map +1 -0
- package/dist/source/route.d.ts +97 -0
- package/dist/source/route.js +167 -0
- package/dist/source/route.js.map +1 -0
- package/dist/source/router.d.ts +70 -0
- package/dist/source/router.js +10 -0
- package/dist/source/router.js.map +1 -0
- package/dist/source/routerContext.d.ts +21 -0
- package/dist/source/routerContext.jsx +37 -0
- package/dist/source/routerContext.jsx.map +1 -0
- package/dist/source/scroll-restoration.d.ts +1 -0
- package/dist/source/scroll-restoration.jsx +16 -0
- package/dist/source/scroll-restoration.jsx.map +1 -0
- package/dist/source/typePrimitives.d.ts +10 -0
- package/dist/source/typePrimitives.js +2 -0
- package/dist/source/typePrimitives.js.map +1 -0
- package/dist/source/useBlocker.d.ts +66 -0
- package/dist/source/useBlocker.jsx +308 -0
- package/dist/source/useBlocker.jsx.map +1 -0
- package/dist/source/useCanGoBack.d.ts +1 -0
- package/dist/source/useCanGoBack.js +5 -0
- package/dist/source/useCanGoBack.js.map +1 -0
- package/dist/source/useLoaderData.d.ts +8 -0
- package/dist/source/useLoaderData.jsx +11 -0
- package/dist/source/useLoaderData.jsx.map +1 -0
- package/dist/source/useLoaderDeps.d.ts +7 -0
- package/dist/source/useLoaderDeps.jsx +11 -0
- package/dist/source/useLoaderDeps.jsx.map +1 -0
- package/dist/source/useLocation.d.ts +7 -0
- package/dist/source/useLocation.jsx +7 -0
- package/dist/source/useLocation.jsx.map +1 -0
- package/dist/source/useMatch.d.ts +10 -0
- package/dist/source/useMatch.jsx +46 -0
- package/dist/source/useMatch.jsx.map +1 -0
- package/dist/source/useNavigate.d.ts +5 -0
- package/dist/source/useNavigate.jsx +18 -0
- package/dist/source/useNavigate.jsx.map +1 -0
- package/dist/source/useParams.d.ts +9 -0
- package/dist/source/useParams.jsx +12 -0
- package/dist/source/useParams.jsx.map +1 -0
- package/dist/source/useRouteContext.d.ts +4 -0
- package/dist/source/useRouteContext.js +8 -0
- package/dist/source/useRouteContext.js.map +1 -0
- package/dist/source/useRouter.d.ts +4 -0
- package/dist/source/useRouter.jsx +9 -0
- package/dist/source/useRouter.jsx.map +1 -0
- package/dist/source/useRouterState.d.ts +8 -0
- package/dist/source/useRouterState.jsx +19 -0
- package/dist/source/useRouterState.jsx.map +1 -0
- package/dist/source/useSearch.d.ts +9 -0
- package/dist/source/useSearch.jsx +12 -0
- package/dist/source/useSearch.jsx.map +1 -0
- package/dist/source/utils.d.ts +40 -0
- package/dist/source/utils.js +78 -0
- package/dist/source/utils.js.map +1 -0
- package/package.json +77 -7
- package/src/Asset.tsx +23 -0
- package/src/CatchBoundary.tsx +186 -0
- package/src/ClientOnly.tsx +75 -0
- package/src/HeadContent.tsx +159 -0
- package/src/Match.tsx +415 -0
- package/src/Matches.tsx +349 -0
- package/src/RouterProvider.tsx +117 -0
- package/src/SafeFragment.tsx +10 -0
- package/src/ScriptOnce.tsx +30 -0
- package/src/Scripts.tsx +65 -0
- package/src/ScrollRestoration.tsx +69 -0
- package/src/Transitioner.tsx +213 -0
- package/src/awaited.tsx +54 -0
- package/src/fileRoute.ts +271 -0
- package/src/history.ts +9 -0
- package/src/index.tsx +346 -0
- package/src/lazyRouteComponent.tsx +173 -0
- package/src/link.tsx +765 -0
- package/src/matchContext.tsx +41 -0
- package/src/not-found.tsx +55 -0
- package/src/renderRouteNotFound.tsx +35 -0
- package/src/route.ts +658 -0
- package/src/router.ts +103 -0
- package/src/routerContext.tsx +53 -0
- package/src/scroll-restoration.tsx +29 -0
- package/src/typePrimitives.ts +74 -0
- package/src/useBlocker.tsx +501 -0
- package/src/useCanGoBack.ts +5 -0
- package/src/useLoaderData.tsx +50 -0
- package/src/useLoaderDeps.tsx +46 -0
- package/src/useLocation.tsx +30 -0
- package/src/useMatch.tsx +127 -0
- package/src/useNavigate.tsx +40 -0
- package/src/useParams.tsx +71 -0
- package/src/useRouteContext.ts +31 -0
- package/src/useRouter.tsx +15 -0
- package/src/useRouterState.tsx +43 -0
- package/src/useSearch.tsx +71 -0
- package/src/utils.ts +111 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as Vue from "vue";
|
|
2
|
+
import { Matches } from "./Matches.js";
|
|
3
|
+
import { provideRouter } from "./routerContext.js";
|
|
4
|
+
const RouterContextProvider = Vue.defineComponent({
|
|
5
|
+
name: "RouterContextProvider",
|
|
6
|
+
props: {
|
|
7
|
+
router: {
|
|
8
|
+
type: Object,
|
|
9
|
+
required: true
|
|
10
|
+
}
|
|
11
|
+
// Rest of router options will be passed as attrs
|
|
12
|
+
},
|
|
13
|
+
setup(props, {
|
|
14
|
+
attrs,
|
|
15
|
+
slots
|
|
16
|
+
}) {
|
|
17
|
+
const router = props.router;
|
|
18
|
+
const restAttrs = attrs;
|
|
19
|
+
router.update({
|
|
20
|
+
...router.options,
|
|
21
|
+
...restAttrs,
|
|
22
|
+
context: {
|
|
23
|
+
...router.options.context,
|
|
24
|
+
...restAttrs.context || {}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
provideRouter(router);
|
|
28
|
+
return () => {
|
|
29
|
+
const childContent = slots.default?.();
|
|
30
|
+
if (router.options.Wrap) {
|
|
31
|
+
const WrapComponent = router.options.Wrap;
|
|
32
|
+
return Vue.h(WrapComponent, null, () => childContent);
|
|
33
|
+
}
|
|
34
|
+
return childContent;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const RouterProvider = Vue.defineComponent({
|
|
39
|
+
name: "RouterProvider",
|
|
40
|
+
props: {
|
|
41
|
+
router: {
|
|
42
|
+
type: Object,
|
|
43
|
+
required: true
|
|
44
|
+
}
|
|
45
|
+
// Rest of router options will be passed as attrs
|
|
46
|
+
},
|
|
47
|
+
setup(props, {
|
|
48
|
+
attrs
|
|
49
|
+
}) {
|
|
50
|
+
const restAttrs = attrs;
|
|
51
|
+
return () => {
|
|
52
|
+
return Vue.h(RouterContextProvider, {
|
|
53
|
+
router: props.router,
|
|
54
|
+
...restAttrs
|
|
55
|
+
}, {
|
|
56
|
+
default: () => Vue.h(Matches)
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
export {
|
|
62
|
+
RouterContextProvider,
|
|
63
|
+
RouterProvider
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=RouterProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as Vue from 'vue'\nimport { Matches } from './Matches'\nimport { provideRouter } from './routerContext'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterOptions,\n} from '@tanstack/router-core'\n\n// Component that provides router context and renders children\nexport const RouterContextProvider = Vue.defineComponent({\n name: 'RouterContextProvider',\n props: {\n router: {\n type: Object,\n required: true,\n },\n // Rest of router options will be passed as attrs\n },\n setup(props, { attrs, slots }) {\n const router = props.router as AnyRouter\n const restAttrs = attrs as Record<string, any>\n\n // Allow the router to update options on the router instance\n router.update({\n ...router.options,\n ...restAttrs,\n context: {\n ...router.options.context,\n ...((restAttrs.context as Record<string, any>) || {}),\n },\n } as any)\n\n // Provide router to all child components\n provideRouter(router)\n\n return () => {\n // Get child content\n const childContent = slots.default?.()\n\n // If a Wrap component is specified in router options, use it\n if (router.options.Wrap) {\n const WrapComponent = router.options.Wrap\n return Vue.h(WrapComponent, null, () => childContent)\n }\n\n // Otherwise just return the child content\n return childContent\n }\n },\n})\n\n// The main router provider component that includes matches\nexport const RouterProvider = Vue.defineComponent({\n name: 'RouterProvider',\n props: {\n router: {\n type: Object,\n required: true,\n },\n // Rest of router options will be passed as attrs\n },\n setup(props, { attrs }) {\n const restAttrs = attrs as Record<string, any>\n\n return () => {\n return Vue.h(\n RouterContextProvider,\n {\n router: props.router,\n ...restAttrs,\n },\n {\n default: () => Vue.h(Matches),\n },\n )\n }\n },\n}) as unknown as {\n <TRouter extends AnyRouter = RegisteredRouter>(\n props: {\n router: TRouter\n routeTree?: TRouter['routeTree']\n } & Record<string, any>,\n ): Vue.VNode\n new (): {\n $props: {\n router: AnyRouter\n routeTree?: AnyRouter['routeTree']\n }\n }\n}\n\nexport type RouterProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n false,\n TRouter['history'],\n TDehydrated\n >,\n 'context'\n> & {\n router: TRouter\n context?: Partial<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n false,\n TRouter['history'],\n TDehydrated\n >['context']\n >\n}\n"],"names":["RouterContextProvider","Vue","defineComponent","name","props","router","type","Object","required","setup","attrs","slots","restAttrs","update","options","context","provideRouter","childContent","default","Wrap","WrapComponent","h","RouterProvider","Matches"],"mappings":";;;MAUaA,wBAAwBC,IAAIC,gBAAgB;AAAA,EACvDC,MAAM;AAAA,EACNC,OAAO;AAAA,IACLC,QAAQ;AAAA,MACNC,MAAMC;AAAAA,MACNC,UAAU;AAAA,IACZ;AAAA;AAAA;EAGFC,MAAML,OAAO;AAAA,IAAEM;AAAAA,IAAOC;AAAAA,EAAM,GAAG;AAC7B,UAAMN,SAASD,MAAMC;AACrB,UAAMO,YAAYF;AAGlBL,WAAOQ,OAAO;AAAA,MACZ,GAAGR,OAAOS;AAAAA,MACV,GAAGF;AAAAA,MACHG,SAAS;AAAA,QACP,GAAGV,OAAOS,QAAQC;AAAAA,QAClB,GAAKH,UAAUG,WAAmC,CAAA;AAAA,MACpD;AAAA,IACF,CAAQ;AAGRC,kBAAcX,MAAM;AAEpB,WAAO,MAAM;AAEX,YAAMY,eAAeN,MAAMO,UAAO;AAGlC,UAAIb,OAAOS,QAAQK,MAAM;AACvB,cAAMC,gBAAgBf,OAAOS,QAAQK;AACrC,eAAOlB,IAAIoB,EAAED,eAAe,MAAM,MAAMH,YAAY;AAAA,MACtD;AAGA,aAAOA;AAAAA,IACT;AAAA,EACF;AACF,CAAC;MAGYK,iBAAiBrB,IAAIC,gBAAgB;AAAA,EAChDC,MAAM;AAAA,EACNC,OAAO;AAAA,IACLC,QAAQ;AAAA,MACNC,MAAMC;AAAAA,MACNC,UAAU;AAAA,IACZ;AAAA;AAAA;EAGFC,MAAML,OAAO;AAAA,IAAEM;AAAAA,EAAM,GAAG;AACtB,UAAME,YAAYF;AAElB,WAAO,MAAM;AACX,aAAOT,IAAIoB,EACTrB,uBACA;AAAA,QACEK,QAAQD,MAAMC;AAAAA,QACd,GAAGO;AAAAA,MACL,GACA;AAAA,QACEM,SAASA,MAAMjB,IAAIoB,EAAEE,OAAO;AAAA,MAC9B,CACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as Vue from 'vue';
|
|
2
|
+
export declare const SafeFragment: Vue.DefineComponent<{}, () => Vue.VNode<Vue.RendererNode, Vue.RendererElement, {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}>, {}, {}, {}, Vue.ComponentOptionsMixin, Vue.ComponentOptionsMixin, {}, string, Vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, Vue.ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createVNode } from "vue";
|
|
2
|
+
import jsesc from "jsesc";
|
|
3
|
+
function ScriptOnce({
|
|
4
|
+
children,
|
|
5
|
+
log
|
|
6
|
+
}) {
|
|
7
|
+
if (typeof document !== "undefined") {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return createVNode("script", {
|
|
11
|
+
"class": "tsr-once",
|
|
12
|
+
"innerHTML": [children, (log ?? true) && process.env.NODE_ENV === "development" ? `console.info(\`Injected From Server:
|
|
13
|
+
${jsesc(children.toString(), {
|
|
14
|
+
quotes: "backtick"
|
|
15
|
+
})}\`)` : "", 'if (typeof __TSR_SSR__ !== "undefined") __TSR_SSR__.cleanScripts()'].filter(Boolean).join("\n")
|
|
16
|
+
}, null);
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
ScriptOnce
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=ScriptOnce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScriptOnce.js","sources":["../../src/ScriptOnce.tsx"],"sourcesContent":["import jsesc from 'jsesc'\n\nexport function ScriptOnce({\n children,\n log,\n}: {\n children: string\n log?: boolean\n sync?: boolean\n}) {\n if (typeof document !== 'undefined') {\n return null\n }\n\n return (\n <script\n class=\"tsr-once\"\n innerHTML={[\n children,\n (log ?? true) && process.env.NODE_ENV === 'development'\n ? `console.info(\\`Injected From Server:\n${jsesc(children.toString(), { quotes: 'backtick' })}\\`)`\n : '',\n 'if (typeof __TSR_SSR__ !== \"undefined\") __TSR_SSR__.cleanScripts()',\n ]\n .filter(Boolean)\n .join('\\n')}\n />\n )\n}\n"],"names":["ScriptOnce","children","log","document","_createVNode","process","env","NODE_ENV","jsesc","toString","quotes","filter","Boolean","join"],"mappings":";;AAEO,SAASA,WAAW;AAAA,EACzBC;AAAAA,EACAC;AAKF,GAAG;AACD,MAAI,OAAOC,aAAa,aAAa;AACnC,WAAO;AAAA,EACT;AAEA,SAAAC,YAAA,UAAA;AAAA,IAAA,SAAA;AAAA,IAAA,aAGe,CACTH,WACCC,OAAO,SAASG,QAAQC,IAAIC,aAAa,gBACtC;AAAA,EACVC,MAAMP,SAASQ,YAAY;AAAA,MAAEC,QAAQ;AAAA,IAAW,CAAC,CAAC,QACxC,IACJ,oEAAoE,EAEnEC,OAAOC,OAAO,EACdC,KAAK,IAAI;AAAA,EAAC,GAAA,IAAA;AAGnB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Scripts: () => import("vue/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createVNode, Fragment, mergeProps } from "vue";
|
|
2
|
+
import { Asset } from "./Asset.js";
|
|
3
|
+
import { useRouterState } from "./useRouterState.js";
|
|
4
|
+
import { useRouter } from "./useRouter.js";
|
|
5
|
+
const Scripts = () => {
|
|
6
|
+
const router = useRouter();
|
|
7
|
+
const assetScripts = useRouterState({
|
|
8
|
+
select: (state) => {
|
|
9
|
+
const assetScripts2 = [];
|
|
10
|
+
const manifest = router.ssr?.manifest;
|
|
11
|
+
if (!manifest) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
state.matches.map((match) => router.looseRoutesById[match.routeId]).forEach((route) => manifest.routes[route.id]?.assets?.filter((d) => d.tag === "script").forEach((asset) => {
|
|
15
|
+
assetScripts2.push({
|
|
16
|
+
tag: "script",
|
|
17
|
+
attrs: asset.attrs,
|
|
18
|
+
children: asset.children
|
|
19
|
+
});
|
|
20
|
+
}));
|
|
21
|
+
return assetScripts2;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const scripts = useRouterState({
|
|
25
|
+
select: (state) => ({
|
|
26
|
+
scripts: state.matches.map((match) => match.scripts).flat(1).filter(Boolean).map(({
|
|
27
|
+
children,
|
|
28
|
+
...script
|
|
29
|
+
}) => ({
|
|
30
|
+
tag: "script",
|
|
31
|
+
attrs: {
|
|
32
|
+
...script
|
|
33
|
+
},
|
|
34
|
+
children
|
|
35
|
+
}))
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
const allScripts = [...scripts.value.scripts, ...assetScripts.value];
|
|
39
|
+
return createVNode(Fragment, null, [allScripts.map((asset, i) => createVNode(Asset, mergeProps(asset, {
|
|
40
|
+
"key": i
|
|
41
|
+
}), null))]);
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
Scripts
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=Scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Scripts.js","sources":["../../src/Scripts.tsx"],"sourcesContent":["import { Asset } from './Asset'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport type { RouterManagedTag } from '@tanstack/router-core'\n\nexport const Scripts = () => {\n const router = useRouter()\n\n const assetScripts = useRouterState({\n select: (state) => {\n const assetScripts: Array<RouterManagedTag> = []\n const manifest = router.ssr?.manifest\n\n if (!manifest) {\n return []\n }\n\n state.matches\n .map((match) => router.looseRoutesById[match.routeId]!)\n .forEach((route) =>\n manifest.routes[route.id]?.assets\n ?.filter((d) => d.tag === 'script')\n .forEach((asset) => {\n assetScripts.push({\n tag: 'script',\n attrs: asset.attrs,\n children: asset.children,\n } as any)\n }),\n )\n\n return assetScripts\n },\n })\n\n const scripts = useRouterState({\n select: (state) => ({\n scripts: (\n state.matches\n .map((match) => match.scripts!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...script }) => ({\n tag: 'script',\n attrs: {\n ...script,\n },\n children,\n })),\n }),\n })\n\n const allScripts = [\n ...scripts.value.scripts,\n ...assetScripts.value,\n ] as Array<RouterManagedTag>\n\n return (\n <>\n {allScripts.map((asset, i) => (\n <Asset {...asset} key={i} />\n ))}\n </>\n )\n}\n"],"names":["Scripts","router","useRouter","assetScripts","useRouterState","select","state","manifest","ssr","matches","map","match","looseRoutesById","routeId","forEach","route","routes","id","assets","filter","d","tag","asset","push","attrs","children","scripts","flat","Boolean","script","allScripts","value","_createVNode","_Fragment","i","Asset","_mergeProps"],"mappings":";;;;AAKO,MAAMA,UAAUA,MAAM;AAC3B,QAAMC,SAASC,UAAS;AAExB,QAAMC,eAAeC,eAAe;AAAA,IAClCC,QAASC,WAAU;AACjB,YAAMH,gBAAwC,CAAA;AAC9C,YAAMI,WAAWN,OAAOO,KAAKD;AAE7B,UAAI,CAACA,UAAU;AACb,eAAO,CAAA;AAAA,MACT;AAEAD,YAAMG,QACHC,IAAKC,WAAUV,OAAOW,gBAAgBD,MAAME,OAAO,CAAE,EACrDC,QAASC,WACRR,SAASS,OAAOD,MAAME,EAAE,GAAGC,QACvBC,OAAQC,OAAMA,EAAEC,QAAQ,QAAQ,EACjCP,QAASQ,WAAU;AAClBnB,QAAAA,cAAaoB,KAAK;AAAA,UAChBF,KAAK;AAAA,UACLG,OAAOF,MAAME;AAAAA,UACbC,UAAUH,MAAMG;AAAAA,QAClB,CAAQ;AAAA,MACV,CAAC,CACL;AAEF,aAAOtB;AAAAA,IACT;AAAA,EACF,CAAC;AAED,QAAMuB,UAAUtB,eAAe;AAAA,IAC7BC,QAASC,YAAW;AAAA,MAClBoB,SACEpB,MAAMG,QACHC,IAAKC,WAAUA,MAAMe,OAAQ,EAC7BC,KAAK,CAAC,EACNR,OAAOS,OAAO,EACjBlB,IAAI,CAAC;AAAA,QAAEe;AAAAA,QAAU,GAAGI;AAAAA,MAAO,OAAO;AAAA,QAClCR,KAAK;AAAA,QACLG,OAAO;AAAA,UACL,GAAGK;AAAAA;QAELJ;AAAAA,MACF,EAAE;AAAA;EAEN,CAAC;AAED,QAAMK,aAAa,CACjB,GAAGJ,QAAQK,MAAML,SACjB,GAAGvB,aAAa4B,KAAK;AAGvB,SAAAC,YAAAC,iBAEKH,WAAWpB,IAAI,CAACY,OAAOY,MAACF,YAAAG,OAAAC,WACZd,OAAK;AAAA,IAAA,OAAOY;AAAAA,EAAC,CAAA,GAAA,IAAA,CACzB,CAAC,CAAA;AAGR;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ParsedLocation, ScrollRestorationEntry, ScrollRestorationOptions } from '@tanstack/router-core';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated use createRouter's `scrollRestoration` option instead
|
|
4
|
+
*/
|
|
5
|
+
export declare function ScrollRestoration(_props: ScrollRestorationOptions): null;
|
|
6
|
+
export declare function useElementScrollRestoration(options: ({
|
|
7
|
+
id: string;
|
|
8
|
+
getElement?: () => Window | Element | undefined | null;
|
|
9
|
+
} | {
|
|
10
|
+
id?: string;
|
|
11
|
+
getElement: () => Window | Element | undefined | null;
|
|
12
|
+
}) & {
|
|
13
|
+
getKey?: (location: ParsedLocation) => string;
|
|
14
|
+
}): ScrollRestorationEntry | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { defaultGetScrollRestorationKey, getCssSelector, scrollRestorationCache, setupScrollRestoration } from "@tanstack/router-core";
|
|
2
|
+
import { useRouter } from "./useRouter.js";
|
|
3
|
+
function useScrollRestoration() {
|
|
4
|
+
const router = useRouter();
|
|
5
|
+
setupScrollRestoration(router, true);
|
|
6
|
+
}
|
|
7
|
+
function ScrollRestoration(_props) {
|
|
8
|
+
useScrollRestoration();
|
|
9
|
+
if (process.env.NODE_ENV === "development") {
|
|
10
|
+
console.warn("The ScrollRestoration component is deprecated. Use createRouter's `scrollRestoration` option instead.");
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
function useElementScrollRestoration(options) {
|
|
15
|
+
useScrollRestoration();
|
|
16
|
+
const router = useRouter();
|
|
17
|
+
const getKey = options.getKey || defaultGetScrollRestorationKey;
|
|
18
|
+
let elementSelector = "";
|
|
19
|
+
if (options.id) {
|
|
20
|
+
elementSelector = `[data-scroll-restoration-id="${options.id}"]`;
|
|
21
|
+
} else {
|
|
22
|
+
const element = options.getElement?.();
|
|
23
|
+
if (!element) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
elementSelector = element instanceof Window ? "window" : getCssSelector(element);
|
|
27
|
+
}
|
|
28
|
+
const restoreKey = getKey(router.latestLocation);
|
|
29
|
+
const byKey = scrollRestorationCache?.state[restoreKey];
|
|
30
|
+
return byKey?.[elementSelector];
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
ScrollRestoration,
|
|
34
|
+
useElementScrollRestoration
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=ScrollRestoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScrollRestoration.js","sources":["../../src/ScrollRestoration.tsx"],"sourcesContent":["import {\n defaultGetScrollRestorationKey,\n getCssSelector,\n scrollRestorationCache,\n setupScrollRestoration,\n} from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport type {\n ParsedLocation,\n ScrollRestorationEntry,\n ScrollRestorationOptions,\n} from '@tanstack/router-core'\n\nfunction useScrollRestoration() {\n const router = useRouter()\n setupScrollRestoration(router, true)\n}\n\n/**\n * @deprecated use createRouter's `scrollRestoration` option instead\n */\nexport function ScrollRestoration(_props: ScrollRestorationOptions) {\n useScrollRestoration()\n\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n \"The ScrollRestoration component is deprecated. Use createRouter's `scrollRestoration` option instead.\",\n )\n }\n\n return null\n}\n\nexport function useElementScrollRestoration(\n options: (\n | {\n id: string\n getElement?: () => Window | Element | undefined | null\n }\n | {\n id?: string\n getElement: () => Window | Element | undefined | null\n }\n ) & {\n getKey?: (location: ParsedLocation) => string\n },\n): ScrollRestorationEntry | undefined {\n useScrollRestoration()\n\n const router = useRouter()\n const getKey = options.getKey || defaultGetScrollRestorationKey\n\n let elementSelector = ''\n\n if (options.id) {\n elementSelector = `[data-scroll-restoration-id=\"${options.id}\"]`\n } else {\n const element = options.getElement?.()\n if (!element) {\n return\n }\n elementSelector =\n element instanceof Window ? 'window' : getCssSelector(element)\n }\n\n const restoreKey = getKey(router.latestLocation)\n const byKey = scrollRestorationCache?.state[restoreKey]\n return byKey?.[elementSelector]\n}\n"],"names":["useScrollRestoration","router","useRouter","setupScrollRestoration","ScrollRestoration","_props","process","env","NODE_ENV","console","warn","useElementScrollRestoration","options","getKey","defaultGetScrollRestorationKey","elementSelector","id","element","getElement","Window","getCssSelector","restoreKey","latestLocation","byKey","scrollRestorationCache","state"],"mappings":";;AAaA,SAASA,uBAAuB;AAC9B,QAAMC,SAASC,UAAS;AACxBC,yBAAuBF,QAAQ,IAAI;AACrC;AAKO,SAASG,kBAAkBC,QAAkC;AAClEL,uBAAoB;AAEpB,MAAIM,QAAQC,IAAIC,aAAa,eAAe;AAC1CC,YAAQC,KACN,uGACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAASC,4BACdC,SAYoC;AACpCZ,uBAAoB;AAEpB,QAAMC,SAASC,UAAS;AACxB,QAAMW,SAASD,QAAQC,UAAUC;AAEjC,MAAIC,kBAAkB;AAEtB,MAAIH,QAAQI,IAAI;AACdD,sBAAkB,gCAAgCH,QAAQI,EAAE;AAAA,EAC9D,OAAO;AACL,UAAMC,UAAUL,QAAQM,aAAU;AAClC,QAAI,CAACD,SAAS;AACZ;AAAA,IACF;AACAF,sBACEE,mBAAmBE,SAAS,WAAWC,eAAeH,OAAO;AAAA,EACjE;AAEA,QAAMI,aAAaR,OAAOZ,OAAOqB,cAAc;AAC/C,QAAMC,QAAQC,wBAAwBC,MAAMJ,UAAU;AACtD,SAAOE,QAAQR,eAAe;AAChC;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import * as Vue from 'vue';
|
|
2
|
+
export declare const Transitioner: Vue.DefineComponent<{}, () => null, {}, {}, {}, Vue.ComponentOptionsMixin, Vue.ComponentOptionsMixin, {}, string, Vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, Vue.ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import * as Vue from "vue";
|
|
2
|
+
import { trimPathRight, getLocationChangeInfo, handleHashScroll } from "@tanstack/router-core";
|
|
3
|
+
import { useRouter } from "./useRouter.js";
|
|
4
|
+
import { useRouterState } from "./useRouterState.js";
|
|
5
|
+
import { usePrevious } from "./utils.js";
|
|
6
|
+
const Transitioner = Vue.defineComponent({
|
|
7
|
+
name: "Transitioner",
|
|
8
|
+
setup() {
|
|
9
|
+
const router = useRouter();
|
|
10
|
+
let mountLoadForRouter = {
|
|
11
|
+
router,
|
|
12
|
+
mounted: false
|
|
13
|
+
};
|
|
14
|
+
if (router.isServer) {
|
|
15
|
+
return () => null;
|
|
16
|
+
}
|
|
17
|
+
const isLoading = useRouterState({
|
|
18
|
+
select: ({
|
|
19
|
+
isLoading: isLoading2
|
|
20
|
+
}) => isLoading2
|
|
21
|
+
});
|
|
22
|
+
const isTransitioning = Vue.ref(false);
|
|
23
|
+
const hasPendingMatches = useRouterState({
|
|
24
|
+
select: (s) => s.matches.some((d) => d.status === "pending")
|
|
25
|
+
});
|
|
26
|
+
const previousIsLoading = usePrevious(() => isLoading.value);
|
|
27
|
+
const isAnyPending = Vue.computed(() => isLoading.value || isTransitioning.value || hasPendingMatches.value);
|
|
28
|
+
const previousIsAnyPending = usePrevious(() => isAnyPending.value);
|
|
29
|
+
const isPagePending = Vue.computed(() => isLoading.value || hasPendingMatches.value);
|
|
30
|
+
const previousIsPagePending = usePrevious(() => isPagePending.value);
|
|
31
|
+
router.startTransition = (fn) => {
|
|
32
|
+
isTransitioning.value = true;
|
|
33
|
+
try {
|
|
34
|
+
router.__store.setState((s) => ({
|
|
35
|
+
...s,
|
|
36
|
+
isTransitioning: true
|
|
37
|
+
}));
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
const endTransition = () => {
|
|
41
|
+
Vue.nextTick(() => {
|
|
42
|
+
try {
|
|
43
|
+
isTransitioning.value = false;
|
|
44
|
+
router.__store.setState((s) => ({
|
|
45
|
+
...s,
|
|
46
|
+
isTransitioning: false
|
|
47
|
+
}));
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
fn();
|
|
53
|
+
endTransition();
|
|
54
|
+
};
|
|
55
|
+
router.startViewTransition = (fn) => {
|
|
56
|
+
fn();
|
|
57
|
+
};
|
|
58
|
+
let unsubscribe;
|
|
59
|
+
Vue.onMounted(() => {
|
|
60
|
+
unsubscribe = router.history.subscribe(router.load);
|
|
61
|
+
const nextLocation = router.buildLocation({
|
|
62
|
+
to: router.latestLocation.pathname,
|
|
63
|
+
search: true,
|
|
64
|
+
params: true,
|
|
65
|
+
hash: true,
|
|
66
|
+
state: true,
|
|
67
|
+
_includeValidateSearch: true
|
|
68
|
+
});
|
|
69
|
+
if (trimPathRight(router.latestLocation.href) !== trimPathRight(nextLocation.href)) {
|
|
70
|
+
router.commitLocation({
|
|
71
|
+
...nextLocation,
|
|
72
|
+
replace: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const isMounted = Vue.ref(false);
|
|
77
|
+
Vue.onMounted(() => {
|
|
78
|
+
isMounted.value = true;
|
|
79
|
+
});
|
|
80
|
+
Vue.onUnmounted(() => {
|
|
81
|
+
isMounted.value = false;
|
|
82
|
+
if (unsubscribe) {
|
|
83
|
+
unsubscribe();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
Vue.onMounted(() => {
|
|
87
|
+
if (typeof window !== "undefined" && router.ssr || mountLoadForRouter.router === router && mountLoadForRouter.mounted) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
mountLoadForRouter = {
|
|
91
|
+
router,
|
|
92
|
+
mounted: true
|
|
93
|
+
};
|
|
94
|
+
const tryLoad = async () => {
|
|
95
|
+
try {
|
|
96
|
+
await router.load();
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.error(err);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
tryLoad();
|
|
102
|
+
});
|
|
103
|
+
Vue.watch(() => isLoading.value, (newValue) => {
|
|
104
|
+
if (!isMounted.value) return;
|
|
105
|
+
try {
|
|
106
|
+
if (previousIsLoading.value.previous && !newValue) {
|
|
107
|
+
router.emit({
|
|
108
|
+
type: "onLoad",
|
|
109
|
+
...getLocationChangeInfo(router.state)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Vue.watch(isPagePending, (newValue) => {
|
|
116
|
+
if (!isMounted.value) return;
|
|
117
|
+
try {
|
|
118
|
+
if (previousIsPagePending.value.previous && !newValue) {
|
|
119
|
+
router.emit({
|
|
120
|
+
type: "onBeforeRouteMount",
|
|
121
|
+
...getLocationChangeInfo(router.state)
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
Vue.watch(isAnyPending, (newValue) => {
|
|
128
|
+
if (!isMounted.value) return;
|
|
129
|
+
try {
|
|
130
|
+
if (previousIsAnyPending.value.previous && !newValue) {
|
|
131
|
+
const changeInfo = getLocationChangeInfo(router.state);
|
|
132
|
+
router.emit({
|
|
133
|
+
type: "onResolved",
|
|
134
|
+
...changeInfo
|
|
135
|
+
});
|
|
136
|
+
router.__store.setState((s) => ({
|
|
137
|
+
...s,
|
|
138
|
+
status: "idle",
|
|
139
|
+
resolvedLocation: s.location
|
|
140
|
+
}));
|
|
141
|
+
if (changeInfo.hrefChanged) {
|
|
142
|
+
handleHashScroll(router);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return () => null;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
export {
|
|
152
|
+
Transitioner
|
|
153
|
+
};
|
|
154
|
+
//# sourceMappingURL=Transitioner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transitioner.js","sources":["../../src/Transitioner.tsx"],"sourcesContent":["import * as Vue from 'vue'\nimport {\n getLocationChangeInfo,\n handleHashScroll,\n trimPathRight,\n} from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport { useRouterState } from './useRouterState'\nimport { usePrevious } from './utils'\n\nexport const Transitioner = Vue.defineComponent({\n name: 'Transitioner',\n setup() {\n const router = useRouter()\n let mountLoadForRouter = { router, mounted: false }\n\n if (router.isServer) {\n return () => null\n }\n\n const isLoading = useRouterState({\n select: ({ isLoading }) => isLoading,\n })\n\n // Track if we're in a transition - using a ref to track async transitions\n const isTransitioning = Vue.ref(false)\n\n // Track pending state changes\n const hasPendingMatches = useRouterState({\n select: (s) => s.matches.some((d) => d.status === 'pending'),\n })\n\n const previousIsLoading = usePrevious(() => isLoading.value)\n\n const isAnyPending = Vue.computed(\n () => isLoading.value || isTransitioning.value || hasPendingMatches.value,\n )\n const previousIsAnyPending = usePrevious(() => isAnyPending.value)\n\n const isPagePending = Vue.computed(\n () => isLoading.value || hasPendingMatches.value,\n )\n const previousIsPagePending = usePrevious(() => isPagePending.value)\n\n // Implement startTransition similar to React/Solid\n // Vue doesn't have a native useTransition like React 18, so we simulate it\n // We also update the router state's isTransitioning flag so useMatch can check it\n router.startTransition = (fn: () => void | Promise<void>) => {\n isTransitioning.value = true\n // Also update the router state so useMatch knows we're transitioning\n try {\n router.__store.setState((s) => ({ ...s, isTransitioning: true }))\n } catch {\n // Ignore errors if component is unmounted\n }\n\n // Helper to end the transition\n const endTransition = () => {\n // Use nextTick to ensure Vue has processed all reactive updates\n Vue.nextTick(() => {\n try {\n isTransitioning.value = false\n router.__store.setState((s) => ({ ...s, isTransitioning: false }))\n } catch {\n // Ignore errors if component is unmounted\n }\n })\n }\n\n // Execute the function synchronously\n // The function internally may call startViewTransition which schedules async work\n // via document.startViewTransition, but we don't need to wait for it here\n // because Vue's reactivity will trigger re-renders when state changes\n fn()\n\n // End the transition on next tick to allow Vue to process reactive updates\n endTransition()\n }\n\n // For Vue, we need to completely override startViewTransition because Vue's\n // async rendering doesn't work well with the View Transitions API's requirement\n // for synchronous DOM updates. The browser expects the DOM to be updated\n // when the callback promise resolves, but Vue updates asynchronously.\n //\n // Our approach: Skip the actual view transition animation but still update state.\n // This ensures navigation works correctly even without the visual transition.\n // In the future, we could explore using viewTransition.captured like vue-view-transitions does.\n router.startViewTransition = (fn: () => Promise<void>) => {\n // Just run the callback directly without wrapping in document.startViewTransition\n // This ensures the state updates happen and Vue can render them normally\n fn()\n }\n\n // Subscribe to location changes\n // and try to load the new location\n let unsubscribe: (() => void) | undefined\n\n Vue.onMounted(() => {\n unsubscribe = router.history.subscribe(router.load)\n\n const nextLocation = router.buildLocation({\n to: router.latestLocation.pathname,\n search: true,\n params: true,\n hash: true,\n state: true,\n _includeValidateSearch: true,\n })\n\n if (\n trimPathRight(router.latestLocation.href) !==\n trimPathRight(nextLocation.href)\n ) {\n router.commitLocation({ ...nextLocation, replace: true })\n }\n })\n\n // Track if component is mounted to prevent updates after unmount\n const isMounted = Vue.ref(false)\n\n Vue.onMounted(() => {\n isMounted.value = true\n })\n\n Vue.onUnmounted(() => {\n isMounted.value = false\n if (unsubscribe) {\n unsubscribe()\n }\n })\n\n // Try to load the initial location\n Vue.onMounted(() => {\n if (\n (typeof window !== 'undefined' && router.ssr) ||\n (mountLoadForRouter.router === router && mountLoadForRouter.mounted)\n ) {\n return\n }\n mountLoadForRouter = { router, mounted: true }\n const tryLoad = async () => {\n try {\n await router.load()\n } catch (err) {\n console.error(err)\n }\n }\n tryLoad()\n })\n\n // Setup watchers for emitting events\n // All watchers check isMounted to prevent updates after unmount\n Vue.watch(\n () => isLoading.value,\n (newValue) => {\n if (!isMounted.value) return\n try {\n if (previousIsLoading.value.previous && !newValue) {\n router.emit({\n type: 'onLoad',\n ...getLocationChangeInfo(router.state),\n })\n }\n } catch {\n // Ignore errors if component is unmounted\n }\n },\n )\n\n Vue.watch(isPagePending, (newValue) => {\n if (!isMounted.value) return\n try {\n // emit onBeforeRouteMount\n if (previousIsPagePending.value.previous && !newValue) {\n router.emit({\n type: 'onBeforeRouteMount',\n ...getLocationChangeInfo(router.state),\n })\n }\n } catch {\n // Ignore errors if component is unmounted\n }\n })\n\n Vue.watch(isAnyPending, (newValue) => {\n if (!isMounted.value) return\n try {\n // The router was pending and now it's not\n if (previousIsAnyPending.value.previous && !newValue) {\n const changeInfo = getLocationChangeInfo(router.state)\n router.emit({\n type: 'onResolved',\n ...changeInfo,\n })\n\n router.__store.setState((s) => ({\n ...s,\n status: 'idle',\n resolvedLocation: s.location,\n }))\n\n if (changeInfo.hrefChanged) {\n handleHashScroll(router)\n }\n }\n } catch {\n // Ignore errors if component is unmounted\n }\n })\n\n return () => null\n },\n})\n"],"names":["Transitioner","Vue","defineComponent","name","setup","router","useRouter","mountLoadForRouter","mounted","isServer","isLoading","useRouterState","select","isTransitioning","ref","hasPendingMatches","s","matches","some","d","status","previousIsLoading","usePrevious","value","isAnyPending","computed","previousIsAnyPending","isPagePending","previousIsPagePending","startTransition","fn","__store","setState","endTransition","nextTick","startViewTransition","unsubscribe","onMounted","history","subscribe","load","nextLocation","buildLocation","to","latestLocation","pathname","search","params","hash","state","_includeValidateSearch","trimPathRight","href","commitLocation","replace","isMounted","onUnmounted","window","ssr","tryLoad","err","console","error","watch","newValue","previous","emit","type","getLocationChangeInfo","changeInfo","resolvedLocation","location","hrefChanged","handleHashScroll"],"mappings":"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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DeferredPromise } from '@tanstack/router-core';
|
|
2
|
+
import * as Vue from 'vue';
|
|
3
|
+
export type AwaitOptions<T> = {
|
|
4
|
+
promise: Promise<T>;
|
|
5
|
+
};
|
|
6
|
+
export declare function useAwaited<T>({ promise: _promise, }: AwaitOptions<T>): [T, DeferredPromise<T>];
|
|
7
|
+
export declare function Await<T>(props: AwaitOptions<T> & {
|
|
8
|
+
fallback?: Vue.VNode;
|
|
9
|
+
children: (result: T) => Vue.VNode;
|
|
10
|
+
}): () => Vue.VNode<Vue.RendererNode, Vue.RendererElement, {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}> | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as Vue from "vue";
|
|
2
|
+
import { defer, TSR_DEFERRED_PROMISE } from "@tanstack/router-core";
|
|
3
|
+
function useAwaited({
|
|
4
|
+
promise: _promise
|
|
5
|
+
}) {
|
|
6
|
+
const promise = defer(_promise);
|
|
7
|
+
if (promise[TSR_DEFERRED_PROMISE].status === "pending") {
|
|
8
|
+
throw promise;
|
|
9
|
+
}
|
|
10
|
+
if (promise[TSR_DEFERRED_PROMISE].status === "error") {
|
|
11
|
+
throw promise[TSR_DEFERRED_PROMISE].error;
|
|
12
|
+
}
|
|
13
|
+
return [promise[TSR_DEFERRED_PROMISE].data, promise];
|
|
14
|
+
}
|
|
15
|
+
function Await(props) {
|
|
16
|
+
const data = Vue.ref(null);
|
|
17
|
+
const error = Vue.ref(null);
|
|
18
|
+
const pending = Vue.ref(true);
|
|
19
|
+
Vue.watchEffect(async () => {
|
|
20
|
+
pending.value = true;
|
|
21
|
+
try {
|
|
22
|
+
data.value = await props.promise;
|
|
23
|
+
} catch (err) {
|
|
24
|
+
error.value = err;
|
|
25
|
+
} finally {
|
|
26
|
+
pending.value = false;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const inner = Vue.computed(() => {
|
|
30
|
+
if (error.value) throw error.value;
|
|
31
|
+
if (pending.value) return props.fallback;
|
|
32
|
+
return props.children(data.value);
|
|
33
|
+
});
|
|
34
|
+
return () => inner.value;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
Await,
|
|
38
|
+
useAwaited
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=awaited.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"awaited.js","sources":["../../src/awaited.tsx"],"sourcesContent":["import * as Vue from 'vue'\n\nimport { TSR_DEFERRED_PROMISE, defer } from '@tanstack/router-core'\nimport type { DeferredPromise } from '@tanstack/router-core'\n\nexport type AwaitOptions<T> = {\n promise: Promise<T>\n}\n\nexport function useAwaited<T>({\n promise: _promise,\n}: AwaitOptions<T>): [T, DeferredPromise<T>] {\n const promise = defer(_promise)\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'pending') {\n throw promise\n }\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'error') {\n throw promise[TSR_DEFERRED_PROMISE].error\n }\n\n return [promise[TSR_DEFERRED_PROMISE].data, promise]\n}\n\nexport function Await<T>(\n props: AwaitOptions<T> & {\n fallback?: Vue.VNode\n children: (result: T) => Vue.VNode\n },\n) {\n const data = Vue.ref<T | null>(null)\n const error = Vue.ref<Error | null>(null)\n const pending = Vue.ref(true)\n\n Vue.watchEffect(async () => {\n pending.value = true\n try {\n data.value = await props.promise\n } catch (err) {\n error.value = err as Error\n } finally {\n pending.value = false\n }\n })\n\n const inner = Vue.computed(() => {\n if (error.value) throw error.value\n if (pending.value) return props.fallback\n return props.children(data.value as T)\n })\n\n return () => inner.value\n}\n"],"names":["useAwaited","promise","_promise","defer","TSR_DEFERRED_PROMISE","status","error","data","Await","props","Vue","ref","pending","watchEffect","value","err","inner","computed","fallback","children"],"mappings":";;AASO,SAASA,WAAc;AAAA,EAC5BC,SAASC;AACM,GAA4B;AAC3C,QAAMD,UAAUE,MAAMD,QAAQ;AAE9B,MAAID,QAAQG,oBAAoB,EAAEC,WAAW,WAAW;AACtD,UAAMJ;AAAAA,EACR;AAEA,MAAIA,QAAQG,oBAAoB,EAAEC,WAAW,SAAS;AACpD,UAAMJ,QAAQG,oBAAoB,EAAEE;AAAAA,EACtC;AAEA,SAAO,CAACL,QAAQG,oBAAoB,EAAEG,MAAMN,OAAO;AACrD;AAEO,SAASO,MACdC,OAIA;AACA,QAAMF,OAAOG,IAAIC,IAAc,IAAI;AACnC,QAAML,QAAQI,IAAIC,IAAkB,IAAI;AACxC,QAAMC,UAAUF,IAAIC,IAAI,IAAI;AAE5BD,MAAIG,YAAY,YAAY;AAC1BD,YAAQE,QAAQ;AAChB,QAAI;AACFP,WAAKO,QAAQ,MAAML,MAAMR;AAAAA,IAC3B,SAASc,KAAK;AACZT,YAAMQ,QAAQC;AAAAA,IAChB,UAAC;AACCH,cAAQE,QAAQ;AAAA,IAClB;AAAA,EACF,CAAC;AAED,QAAME,QAAQN,IAAIO,SAAS,MAAM;AAC/B,QAAIX,MAAMQ,MAAO,OAAMR,MAAMQ;AAC7B,QAAIF,QAAQE,MAAO,QAAOL,MAAMS;AAChC,WAAOT,MAAMU,SAASZ,KAAKO,KAAU;AAAA,EACvC,CAAC;AAED,SAAO,MAAME,MAAMF;AACrB;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { UseParamsRoute } from './useParams.js';
|
|
2
|
+
import { UseMatchRoute } from './useMatch.js';
|
|
3
|
+
import { UseSearchRoute } from './useSearch.js';
|
|
4
|
+
import { AnyContext, AnyRoute, AnyRouter, Constrain, ConstrainLiteral, FileBaseRouteOptions, FileRoutesByPath, LazyRouteOptions, Register, RegisteredRouter, ResolveParams, Route, RouteById, RouteConstraints, RouteIds, RouteLoaderFn, UpdatableRouteOptions, UseNavigateResult } from '@tanstack/router-core';
|
|
5
|
+
import { UseLoaderDepsRoute } from './useLoaderDeps.js';
|
|
6
|
+
import { UseLoaderDataRoute } from './useLoaderData.js';
|
|
7
|
+
import { UseRouteContextRoute } from './useRouteContext.js';
|
|
8
|
+
export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']>(path?: TFilePath): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'];
|
|
9
|
+
/**
|
|
10
|
+
@deprecated It's no longer recommended to use the `FileRoute` class directly.
|
|
11
|
+
Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.
|
|
12
|
+
*/
|
|
13
|
+
export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']> {
|
|
14
|
+
path?: TFilePath | undefined;
|
|
15
|
+
silent?: boolean;
|
|
16
|
+
constructor(path?: TFilePath | undefined, _opts?: {
|
|
17
|
+
silent: boolean;
|
|
18
|
+
});
|
|
19
|
+
createRoute: <TRegister = Register, TSearchValidator = undefined, TParams = ResolveParams<TPath>, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined, TChildren = unknown, TSSR = unknown, TMiddlewares = unknown, THandlers = undefined>(options?: FileBaseRouteOptions<TRegister, TParentRoute, TId, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, AnyContext, TRouteContextFn, TBeforeLoadFn, AnyContext, TSSR, TMiddlewares, THandlers> & UpdatableRouteOptions<TParentRoute, TId, TFullPath, TParams, TSearchValidator, TLoaderFn, TLoaderDeps, AnyContext, TRouteContextFn, TBeforeLoadFn>) => Route<TRegister, TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchValidator, TParams, AnyContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, unknown, TSSR, TMiddlewares, THandlers>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
@deprecated It's recommended not to split loaders into separate files.
|
|
23
|
+
Instead, place the loader function in the the main route file, inside the
|
|
24
|
+
`createFileRoute('/path/to/file)(options)` options.
|
|
25
|
+
*/
|
|
26
|
+
export declare function FileRouteLoader<TFilePath extends keyof FileRoutesByPath, TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute']>(_path: TFilePath): <TLoaderFn>(loaderFn: Constrain<TLoaderFn, RouteLoaderFn<Register, TRoute['parentRoute'], TRoute['types']['id'], TRoute['types']['params'], TRoute['types']['loaderDeps'], TRoute['types']['routerContext'], TRoute['types']['routeContextFn'], TRoute['types']['beforeLoadFn']>>) => TLoaderFn;
|
|
27
|
+
declare module '@tanstack/router-core' {
|
|
28
|
+
interface LazyRoute<in out TRoute extends AnyRoute> {
|
|
29
|
+
useMatch: UseMatchRoute<TRoute['id']>;
|
|
30
|
+
useRouteContext: UseRouteContextRoute<TRoute['id']>;
|
|
31
|
+
useSearch: UseSearchRoute<TRoute['id']>;
|
|
32
|
+
useParams: UseParamsRoute<TRoute['id']>;
|
|
33
|
+
useLoaderDeps: UseLoaderDepsRoute<TRoute['id']>;
|
|
34
|
+
useLoaderData: UseLoaderDataRoute<TRoute['id']>;
|
|
35
|
+
useNavigate: () => UseNavigateResult<TRoute['fullPath']>;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export declare class LazyRoute<TRoute extends AnyRoute> {
|
|
39
|
+
options: {
|
|
40
|
+
id: string;
|
|
41
|
+
} & LazyRouteOptions;
|
|
42
|
+
constructor(opts: {
|
|
43
|
+
id: string;
|
|
44
|
+
} & LazyRouteOptions);
|
|
45
|
+
useMatch: UseMatchRoute<TRoute['id']>;
|
|
46
|
+
useRouteContext: UseRouteContextRoute<TRoute['id']>;
|
|
47
|
+
useSearch: UseSearchRoute<TRoute['id']>;
|
|
48
|
+
useParams: UseParamsRoute<TRoute['id']>;
|
|
49
|
+
useLoaderDeps: UseLoaderDepsRoute<TRoute['id']>;
|
|
50
|
+
useLoaderData: UseLoaderDataRoute<TRoute['id']>;
|
|
51
|
+
useNavigate: () => UseNavigateResult<TRoute["fullPath"]>;
|
|
52
|
+
}
|
|
53
|
+
export declare function createLazyRoute<TRouter extends AnyRouter = RegisteredRouter, TId extends string = string, TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>): (opts: LazyRouteOptions) => LazyRoute<TRoute>;
|
|
54
|
+
export declare function createLazyFileRoute<TFilePath extends keyof FileRoutesByPath, TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute']>(id: TFilePath): (opts: LazyRouteOptions) => LazyRoute<TRoute>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import warning from "tiny-warning";
|
|
2
|
+
import { createRoute } from "./route.js";
|
|
3
|
+
import { useMatch } from "./useMatch.js";
|
|
4
|
+
import { useLoaderDeps } from "./useLoaderDeps.js";
|
|
5
|
+
import { useLoaderData } from "./useLoaderData.js";
|
|
6
|
+
import { useSearch } from "./useSearch.js";
|
|
7
|
+
import { useParams } from "./useParams.js";
|
|
8
|
+
import { useNavigate } from "./useNavigate.js";
|
|
9
|
+
import { useRouter } from "./useRouter.js";
|
|
10
|
+
function createFileRoute(path) {
|
|
11
|
+
if (typeof path === "object") {
|
|
12
|
+
return new FileRoute(path, {
|
|
13
|
+
silent: true
|
|
14
|
+
}).createRoute(path);
|
|
15
|
+
}
|
|
16
|
+
return new FileRoute(path, {
|
|
17
|
+
silent: true
|
|
18
|
+
}).createRoute;
|
|
19
|
+
}
|
|
20
|
+
class FileRoute {
|
|
21
|
+
constructor(path, _opts) {
|
|
22
|
+
this.path = path;
|
|
23
|
+
this.createRoute = (options) => {
|
|
24
|
+
warning(
|
|
25
|
+
this.silent,
|
|
26
|
+
"FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead."
|
|
27
|
+
);
|
|
28
|
+
const route = createRoute(options);
|
|
29
|
+
route.isRoot = false;
|
|
30
|
+
return route;
|
|
31
|
+
};
|
|
32
|
+
this.silent = _opts?.silent;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function FileRouteLoader(_path) {
|
|
36
|
+
warning(
|
|
37
|
+
false,
|
|
38
|
+
`FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`
|
|
39
|
+
);
|
|
40
|
+
return (loaderFn) => loaderFn;
|
|
41
|
+
}
|
|
42
|
+
class LazyRoute {
|
|
43
|
+
constructor(opts) {
|
|
44
|
+
this.useMatch = (opts2) => {
|
|
45
|
+
return useMatch({
|
|
46
|
+
select: opts2?.select,
|
|
47
|
+
from: this.options.id
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
this.useRouteContext = (opts2) => {
|
|
51
|
+
return useMatch({
|
|
52
|
+
from: this.options.id,
|
|
53
|
+
select: (d) => opts2?.select ? opts2.select(d.context) : d.context
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
this.useSearch = (opts2) => {
|
|
57
|
+
return useSearch({
|
|
58
|
+
select: opts2?.select,
|
|
59
|
+
from: this.options.id
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
this.useParams = (opts2) => {
|
|
63
|
+
return useParams({
|
|
64
|
+
select: opts2?.select,
|
|
65
|
+
from: this.options.id
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
this.useLoaderDeps = (opts2) => {
|
|
69
|
+
return useLoaderDeps({ ...opts2, from: this.options.id });
|
|
70
|
+
};
|
|
71
|
+
this.useLoaderData = (opts2) => {
|
|
72
|
+
return useLoaderData({ ...opts2, from: this.options.id });
|
|
73
|
+
};
|
|
74
|
+
this.useNavigate = () => {
|
|
75
|
+
const router = useRouter();
|
|
76
|
+
return useNavigate({ from: router.routesById[this.options.id].fullPath });
|
|
77
|
+
};
|
|
78
|
+
this.options = opts;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function createLazyRoute(id) {
|
|
82
|
+
return (opts) => {
|
|
83
|
+
return new LazyRoute({
|
|
84
|
+
id,
|
|
85
|
+
...opts
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function createLazyFileRoute(id) {
|
|
90
|
+
if (typeof id === "object") {
|
|
91
|
+
return new LazyRoute(id);
|
|
92
|
+
}
|
|
93
|
+
return (opts) => new LazyRoute({ id, ...opts });
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
FileRoute,
|
|
97
|
+
FileRouteLoader,
|
|
98
|
+
LazyRoute,
|
|
99
|
+
createFileRoute,
|
|
100
|
+
createLazyFileRoute,
|
|
101
|
+
createLazyRoute
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=fileRoute.js.map
|