@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 @@
|
|
|
1
|
+
{"version":3,"file":"useRouter.js","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as Vue from 'vue'\nimport warning from 'tiny-warning'\nimport { getRouterContext } from './routerContext'\nimport type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'\n\nexport function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {\n warn?: boolean\n}): TRouter {\n const value = Vue.inject(getRouterContext() as any, null)\n warning(\n !((opts?.warn ?? true) && !value),\n 'useRouter must be used inside a <RouterProvider> component!',\n )\n return value as any\n}\n"],"names":["useRouter","opts","value","Vue","inject","getRouterContext","warning","warn"],"mappings":";;;AAKO,SAASA,UAAwDC,MAE5D;AACV,QAAMC,QAAQC,IAAIC,OAAOC,iBAAgB,GAAW,IAAI;AACxDC,UACE,GAAGL,MAAMM,QAAQ,SAAS,CAACL,QAC3B,6DACF;AACA,SAAOA;AACT;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AnyRouter, RegisteredRouter, RouterState } from '@tanstack/router-core';
|
|
2
|
+
import * as Vue from 'vue';
|
|
3
|
+
export type UseRouterStateOptions<TRouter extends AnyRouter, TSelected> = {
|
|
4
|
+
router?: TRouter;
|
|
5
|
+
select?: (state: RouterState<TRouter['routeTree']>) => TSelected;
|
|
6
|
+
};
|
|
7
|
+
export type UseRouterStateResult<TRouter extends AnyRouter, TSelected> = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected;
|
|
8
|
+
export declare function useRouterState<TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown>(opts?: UseRouterStateOptions<TRouter, TSelected>): Vue.Ref<UseRouterStateResult<TRouter, TSelected>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useStore } from "@tanstack/vue-store";
|
|
2
|
+
import * as Vue from "vue";
|
|
3
|
+
import { useRouter } from "./useRouter.js";
|
|
4
|
+
function useRouterState(opts) {
|
|
5
|
+
const contextRouter = useRouter({
|
|
6
|
+
warn: opts?.router === void 0
|
|
7
|
+
});
|
|
8
|
+
const router = opts?.router || contextRouter;
|
|
9
|
+
if (!router || !router.__store) {
|
|
10
|
+
return Vue.ref(void 0);
|
|
11
|
+
}
|
|
12
|
+
return useStore(router.__store, (state) => {
|
|
13
|
+
if (opts?.select) return opts.select(state);
|
|
14
|
+
return state;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
useRouterState
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=useRouterState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRouterState.js","sources":["../../src/useRouterState.tsx"],"sourcesContent":["import { useStore } from '@tanstack/vue-store'\nimport * as Vue from 'vue'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterState,\n} from '@tanstack/router-core'\n\nexport type UseRouterStateOptions<TRouter extends AnyRouter, TSelected> = {\n router?: TRouter\n select?: (state: RouterState<TRouter['routeTree']>) => TSelected\n}\n\nexport type UseRouterStateResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected\n\nexport function useRouterState<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n>(\n opts?: UseRouterStateOptions<TRouter, TSelected>,\n): Vue.Ref<UseRouterStateResult<TRouter, TSelected>> {\n const contextRouter = useRouter<TRouter>({\n warn: opts?.router === undefined,\n })\n const router = opts?.router || contextRouter\n\n // Return a safe default if router is undefined\n if (!router || !router.__store) {\n return Vue.ref(undefined) as Vue.Ref<\n UseRouterStateResult<TRouter, TSelected>\n >\n }\n\n return useStore(router.__store, (state) => {\n if (opts?.select) return opts.select(state)\n\n return state\n }) as Vue.Ref<UseRouterStateResult<TRouter, TSelected>>\n}\n"],"names":["useRouterState","opts","contextRouter","useRouter","warn","router","undefined","__store","Vue","ref","useStore","state","select"],"mappings":";;;AAmBO,SAASA,eAIdC,MACmD;AACnD,QAAMC,gBAAgBC,UAAmB;AAAA,IACvCC,MAAMH,MAAMI,WAAWC;AAAAA,EACzB,CAAC;AACD,QAAMD,SAASJ,MAAMI,UAAUH;AAG/B,MAAI,CAACG,UAAU,CAACA,OAAOE,SAAS;AAC9B,WAAOC,IAAIC,IAAIH,MAAS;AAAA,EAG1B;AAEA,SAAOI,SAASL,OAAOE,SAAUI,WAAU;AACzC,QAAIV,MAAMW,OAAQ,QAAOX,KAAKW,OAAOD,KAAK;AAE1C,WAAOA;AAAAA,EACT,CAAC;AACH;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AnyRouter, RegisteredRouter, ResolveUseSearch, StrictOrFrom, ThrowConstraint, ThrowOrOptional, UseSearchResult } from '@tanstack/router-core';
|
|
2
|
+
import type * as Vue from 'vue';
|
|
3
|
+
export interface UseSearchBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected> {
|
|
4
|
+
select?: (state: ResolveUseSearch<TRouter, TFrom, TStrict>) => TSelected;
|
|
5
|
+
shouldThrow?: TThrow;
|
|
6
|
+
}
|
|
7
|
+
export type UseSearchOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected> = StrictOrFrom<TRouter, TFrom, TStrict> & UseSearchBaseOptions<TRouter, TFrom, TStrict, TThrow, TSelected>;
|
|
8
|
+
export type UseSearchRoute<out TFrom> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown>(opts?: UseSearchBaseOptions<TRouter, TFrom, true, true, TSelected>) => Vue.Ref<UseSearchResult<TRouter, TFrom, true, TSelected>>;
|
|
9
|
+
export declare function useSearch<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TStrict extends boolean = true, TThrow extends boolean = true, TSelected = unknown>(opts: UseSearchOptions<TRouter, TFrom, TStrict, ThrowConstraint<TStrict, TThrow>, TSelected>): Vue.Ref<ThrowOrOptional<UseSearchResult<TRouter, TFrom, TStrict, TSelected>, TThrow>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useMatch } from "./useMatch.js";
|
|
2
|
+
function useSearch(opts) {
|
|
3
|
+
return useMatch({
|
|
4
|
+
from: opts.from,
|
|
5
|
+
strict: opts.strict,
|
|
6
|
+
shouldThrow: opts.shouldThrow,
|
|
7
|
+
select: (match) => {
|
|
8
|
+
return opts.select ? opts.select(match.search) : match.search;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
useSearch
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=useSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSearch.js","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type * as Vue from 'vue'\nimport type {\n AnyRouter,\n RegisteredRouter,\n ResolveUseSearch,\n StrictOrFrom,\n ThrowConstraint,\n ThrowOrOptional,\n UseSearchResult,\n} from '@tanstack/router-core'\n\nexport interface UseSearchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n> {\n select?: (state: ResolveUseSearch<TRouter, TFrom, TStrict>) => TSelected\n shouldThrow?: TThrow\n}\n\nexport type UseSearchOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseSearchBaseOptions<TRouter, TFrom, TStrict, TThrow, TSelected>\n\nexport type UseSearchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n>(\n opts?: UseSearchBaseOptions<\n TRouter,\n TFrom,\n /* TStrict */ true,\n /* TThrow */ true,\n TSelected\n >,\n) => Vue.Ref<UseSearchResult<TRouter, TFrom, true, TSelected>>\n\nexport function useSearch<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TThrow extends boolean = true,\n TSelected = unknown,\n>(\n opts: UseSearchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected\n >,\n): Vue.Ref<\n ThrowOrOptional<UseSearchResult<TRouter, TFrom, TStrict, TSelected>, TThrow>\n> {\n return useMatch({\n from: opts.from!,\n strict: opts.strict,\n shouldThrow: opts.shouldThrow,\n select: (match: any) => {\n return opts.select ? opts.select(match.search) : match.search\n },\n }) as any\n}\n"],"names":["useSearch","opts","useMatch","from","strict","shouldThrow","select","match","search"],"mappings":";AA6CO,SAASA,UAOdC,MASA;AACA,SAAOC,SAAS;AAAA,IACdC,MAAMF,KAAKE;AAAAA,IACXC,QAAQH,KAAKG;AAAAA,IACbC,aAAaJ,KAAKI;AAAAA,IAClBC,QAASC,WAAe;AACtB,aAAON,KAAKK,SAASL,KAAKK,OAAOC,MAAMC,MAAM,IAAID,MAAMC;AAAAA,IACzD;AAAA,EACF,CAAC;AACH;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as Vue from 'vue';
|
|
2
|
+
export declare const useLayoutEffect: typeof Vue.effect;
|
|
3
|
+
export declare const usePrevious: (fn: () => boolean) => Vue.ComputedRef<{
|
|
4
|
+
current: boolean | null;
|
|
5
|
+
previous: boolean | null;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* React hook to wrap `IntersectionObserver`.
|
|
9
|
+
*
|
|
10
|
+
* This hook will create an `IntersectionObserver` and observe the ref passed to it.
|
|
11
|
+
*
|
|
12
|
+
* When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.
|
|
13
|
+
*
|
|
14
|
+
* @param ref - The ref to observe
|
|
15
|
+
* @param intersectionObserverOptions - The options to pass to the IntersectionObserver
|
|
16
|
+
* @param options - The options to pass to the hook
|
|
17
|
+
* @param callback - The callback to call when the intersection changes
|
|
18
|
+
* @returns The IntersectionObserver instance
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const MyComponent = () => {
|
|
22
|
+
* const ref = React.useRef<HTMLDivElement>(null)
|
|
23
|
+
* useIntersectionObserver(
|
|
24
|
+
* ref,
|
|
25
|
+
* (entry) => { doSomething(entry) },
|
|
26
|
+
* { rootMargin: '10px' },
|
|
27
|
+
* { disabled: false }
|
|
28
|
+
* )
|
|
29
|
+
* return <div ref={ref} />
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function useIntersectionObserver<T extends Element>(ref: Vue.Ref<T | null>, callback: (entry: IntersectionObserverEntry | undefined) => void, intersectionObserverOptions?: IntersectionObserverInit, options?: {
|
|
33
|
+
disabled?: boolean | (() => boolean);
|
|
34
|
+
}): Vue.Ref<IntersectionObserver | null>;
|
|
35
|
+
export declare function splitProps<T extends Record<string, any>>(props: T, keys: Array<keyof T>): Vue.ComputedRef<{
|
|
36
|
+
[k: string]: unknown;
|
|
37
|
+
}>[];
|
|
38
|
+
export type ParentProps<T = {}> = T & {
|
|
39
|
+
children?: Vue.VNode | Array<Vue.VNode> | string;
|
|
40
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as Vue from "vue";
|
|
2
|
+
const useLayoutEffect = typeof window !== "undefined" ? Vue.effect : Vue.effect;
|
|
3
|
+
const usePrevious = (fn) => {
|
|
4
|
+
return Vue.computed(
|
|
5
|
+
(prev = {
|
|
6
|
+
current: null,
|
|
7
|
+
previous: null
|
|
8
|
+
}) => {
|
|
9
|
+
const current = fn();
|
|
10
|
+
if (prev.current !== current) {
|
|
11
|
+
prev.previous = prev.current;
|
|
12
|
+
prev.current = current;
|
|
13
|
+
}
|
|
14
|
+
return prev;
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
function useIntersectionObserver(ref, callback, intersectionObserverOptions = {}, options = {}) {
|
|
19
|
+
const isIntersectionObserverAvailable = typeof IntersectionObserver === "function";
|
|
20
|
+
const observerRef = Vue.ref(null);
|
|
21
|
+
Vue.watchEffect((onCleanup) => {
|
|
22
|
+
const r = ref.value;
|
|
23
|
+
const isDisabled = typeof options.disabled === "function" ? options.disabled() : options.disabled;
|
|
24
|
+
if (!r || !isIntersectionObserverAvailable || isDisabled) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
28
|
+
callback(entry);
|
|
29
|
+
}, intersectionObserverOptions);
|
|
30
|
+
observerRef.value = observer;
|
|
31
|
+
observer.observe(r);
|
|
32
|
+
onCleanup(() => {
|
|
33
|
+
observer.disconnect();
|
|
34
|
+
observerRef.value = null;
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
return observerRef;
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
useIntersectionObserver,
|
|
41
|
+
useLayoutEffect,
|
|
42
|
+
usePrevious
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as Vue from 'vue'\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? Vue.effect : Vue.effect\n\nexport const usePrevious = (fn: () => boolean) => {\n return Vue.computed(\n (\n prev: { current: boolean | null; previous: boolean | null } = {\n current: null,\n previous: null,\n },\n ) => {\n const current = fn()\n\n if (prev.current !== current) {\n prev.previous = prev.current\n prev.current = current\n }\n\n return prev\n },\n )\n}\n\n/**\n * React hook to wrap `IntersectionObserver`.\n *\n * This hook will create an `IntersectionObserver` and observe the ref passed to it.\n *\n * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.\n *\n * @param ref - The ref to observe\n * @param intersectionObserverOptions - The options to pass to the IntersectionObserver\n * @param options - The options to pass to the hook\n * @param callback - The callback to call when the intersection changes\n * @returns The IntersectionObserver instance\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const ref = React.useRef<HTMLDivElement>(null)\n * useIntersectionObserver(\n * ref,\n * (entry) => { doSomething(entry) },\n * { rootMargin: '10px' },\n * { disabled: false }\n * )\n * return <div ref={ref} />\n * ```\n */\nexport function useIntersectionObserver<T extends Element>(\n ref: Vue.Ref<T | null>,\n callback: (entry: IntersectionObserverEntry | undefined) => void,\n intersectionObserverOptions: IntersectionObserverInit = {},\n options: { disabled?: boolean | (() => boolean) } = {},\n): Vue.Ref<IntersectionObserver | null> {\n const isIntersectionObserverAvailable =\n typeof IntersectionObserver === 'function'\n const observerRef = Vue.ref<IntersectionObserver | null>(null)\n\n // Use watchEffect with cleanup to properly manage the observer lifecycle\n Vue.watchEffect((onCleanup) => {\n const r = ref.value\n // Support both static boolean and function for disabled check\n const isDisabled =\n typeof options.disabled === 'function'\n ? options.disabled()\n : options.disabled\n if (!r || !isIntersectionObserverAvailable || isDisabled) {\n return\n }\n\n const observer = new IntersectionObserver(([entry]) => {\n callback(entry)\n }, intersectionObserverOptions)\n\n observerRef.value = observer\n observer.observe(r)\n\n onCleanup(() => {\n observer.disconnect()\n observerRef.value = null\n })\n })\n\n return observerRef\n}\n\nexport function splitProps<T extends Record<string, any>>(\n props: T,\n keys: Array<keyof T>,\n) {\n // Get the specified props\n const selectedProps = Vue.computed(() => {\n return Object.fromEntries(keys.map((key) => [key, props[key]]))\n })\n\n // Get remaining props as attrs\n const remainingAttrs = Vue.computed(() => {\n const attrs = Vue.useAttrs()\n return Object.fromEntries(\n Object.entries(attrs).filter(([key]) => !keys.includes(key as keyof T)),\n )\n })\n\n return [selectedProps, remainingAttrs]\n}\n\nexport type ParentProps<T = {}> = T & {\n children?: Vue.VNode | Array<Vue.VNode> | string\n}\n"],"names":[],"mappings":";AAEO,MAAM,kBACX,OAAO,WAAW,cAAc,IAAI,SAAS,IAAI;AAE5C,MAAM,cAAc,CAAC,OAAsB;AAChD,SAAO,IAAI;AAAA,IACT,CACE,OAA8D;AAAA,MAC5D,SAAS;AAAA,MACT,UAAU;AAAA,IAAA,MAET;AACH,YAAM,UAAU,GAAA;AAEhB,UAAI,KAAK,YAAY,SAAS;AAC5B,aAAK,WAAW,KAAK;AACrB,aAAK,UAAU;AAAA,MACjB;AAEA,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;AA2BO,SAAS,wBACd,KACA,UACA,8BAAwD,CAAA,GACxD,UAAoD,IACd;AACtC,QAAM,kCACJ,OAAO,yBAAyB;AAClC,QAAM,cAAc,IAAI,IAAiC,IAAI;AAG7D,MAAI,YAAY,CAAC,cAAc;AAC7B,UAAM,IAAI,IAAI;AAEd,UAAM,aACJ,OAAO,QAAQ,aAAa,aACxB,QAAQ,aACR,QAAQ;AACd,QAAI,CAAC,KAAK,CAAC,mCAAmC,YAAY;AACxD;AAAA,IACF;AAEA,UAAM,WAAW,IAAI,qBAAqB,CAAC,CAAC,KAAK,MAAM;AACrD,eAAS,KAAK;AAAA,IAChB,GAAG,2BAA2B;AAE9B,gBAAY,QAAQ;AACpB,aAAS,QAAQ,CAAC;AAElB,cAAU,MAAM;AACd,eAAS,WAAA;AACT,kBAAY,QAAQ;AAAA,IACtB,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function Asset({ tag, attrs, children }) {
|
|
2
|
+
switch (tag) {
|
|
3
|
+
case 'title':
|
|
4
|
+
return <title {...attrs}>{children}</title>;
|
|
5
|
+
case 'meta':
|
|
6
|
+
return <meta {...attrs}/>;
|
|
7
|
+
case 'link':
|
|
8
|
+
return <link {...attrs}/>;
|
|
9
|
+
case 'style':
|
|
10
|
+
return <style {...attrs} innerHTML={children}/>;
|
|
11
|
+
case 'script':
|
|
12
|
+
if (attrs && attrs.src) {
|
|
13
|
+
return <script {...attrs}/>;
|
|
14
|
+
}
|
|
15
|
+
if (typeof children === 'string')
|
|
16
|
+
return <script {...attrs} innerHTML={children}/>;
|
|
17
|
+
return null;
|
|
18
|
+
default:
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=Asset.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Asset.jsx","sourceRoot":"","sources":["../../src/Asset.tsx"],"names":[],"mappings":"AAEA,MAAM,UAAU,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAoB;IAC9D,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,OAAO;YACV,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAA;QAC7C,KAAK,MAAM;YACT,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,EAAG,CAAA;QAC5B,KAAK,MAAM;YACT,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,EAAG,CAAA;QAC5B,KAAK,OAAO;YACV,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,EAAG,CAAA;QAClD,KAAK,QAAQ;YACX,IAAK,KAAa,IAAK,KAAa,CAAC,GAAG,EAAE,CAAC;gBACzC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,EAAG,CAAA;YAC9B,CAAC;YACD,IAAI,OAAO,QAAQ,KAAK,QAAQ;gBAC9B,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,EAAG,CAAA;YACnD,OAAO,IAAI,CAAA;QACb;YACE,OAAO,IAAI,CAAA;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as Vue from 'vue';
|
|
2
|
+
import type { ErrorRouteComponent } from './route';
|
|
3
|
+
export declare function CatchBoundary(props: {
|
|
4
|
+
getResetKey: () => number | string;
|
|
5
|
+
children: Vue.VNode;
|
|
6
|
+
errorComponent?: ErrorRouteComponent;
|
|
7
|
+
onCatch?: (error: Error) => void;
|
|
8
|
+
}): Vue.VNode<Vue.RendererNode, Vue.RendererElement, {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const ErrorComponent: Vue.DefineComponent<Vue.ExtractPropTypes<{
|
|
12
|
+
error: ObjectConstructor;
|
|
13
|
+
reset: FunctionConstructor;
|
|
14
|
+
}>, () => Vue.VNode<Vue.RendererNode, Vue.RendererElement, {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}>, {}, {}, {}, Vue.ComponentOptionsMixin, Vue.ComponentOptionsMixin, {}, string, Vue.PublicProps, Readonly<Vue.ExtractPropTypes<{
|
|
17
|
+
error: ObjectConstructor;
|
|
18
|
+
reset: FunctionConstructor;
|
|
19
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, Vue.ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as Vue from 'vue';
|
|
2
|
+
// Create a Vue error boundary component
|
|
3
|
+
const VueErrorBoundary = Vue.defineComponent({
|
|
4
|
+
name: 'VueErrorBoundary',
|
|
5
|
+
props: {
|
|
6
|
+
onError: Function,
|
|
7
|
+
resetKey: [String, Number],
|
|
8
|
+
},
|
|
9
|
+
emits: ['catch'],
|
|
10
|
+
setup(props, { slots }) {
|
|
11
|
+
const error = Vue.ref(null);
|
|
12
|
+
const resetFn = Vue.ref(null);
|
|
13
|
+
const reset = () => {
|
|
14
|
+
error.value = null;
|
|
15
|
+
};
|
|
16
|
+
// Watch for changes in the reset key
|
|
17
|
+
Vue.watch(() => props.resetKey, (newKey, oldKey) => {
|
|
18
|
+
if (newKey !== oldKey && error.value) {
|
|
19
|
+
reset();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
// Capture errors from child components
|
|
23
|
+
Vue.onErrorCaptured((err) => {
|
|
24
|
+
// If the error is a Promise (thrown for Suspense), don't treat it as an error
|
|
25
|
+
// Just ignore it - Suspense will handle it
|
|
26
|
+
if (err instanceof Promise ||
|
|
27
|
+
(err && typeof err.then === 'function')) {
|
|
28
|
+
return false; // Prevent from propagating as an error, but don't set error state
|
|
29
|
+
}
|
|
30
|
+
error.value = err;
|
|
31
|
+
resetFn.value = reset;
|
|
32
|
+
// Call the onError callback if provided
|
|
33
|
+
if (props.onError) {
|
|
34
|
+
props.onError(err);
|
|
35
|
+
}
|
|
36
|
+
// Prevent the error from propagating further
|
|
37
|
+
return false;
|
|
38
|
+
});
|
|
39
|
+
return () => {
|
|
40
|
+
// If there's an error, render the fallback
|
|
41
|
+
if (error.value && slots.fallback) {
|
|
42
|
+
return slots.fallback({
|
|
43
|
+
error: error.value,
|
|
44
|
+
reset,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// Otherwise render the default slot
|
|
48
|
+
return slots.default && slots.default();
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
// Main CatchBoundary component
|
|
53
|
+
export function CatchBoundary(props) {
|
|
54
|
+
// Create a component to use in the template
|
|
55
|
+
const CatchBoundaryWrapper = Vue.defineComponent({
|
|
56
|
+
name: 'CatchBoundaryWrapper',
|
|
57
|
+
inheritAttrs: false,
|
|
58
|
+
setup() {
|
|
59
|
+
const resetKey = Vue.computed(() => props.getResetKey());
|
|
60
|
+
return () => {
|
|
61
|
+
// Always use our default component as a safe fallback
|
|
62
|
+
const defaultErrorComponent = ErrorComponent;
|
|
63
|
+
return Vue.h(VueErrorBoundary, {
|
|
64
|
+
resetKey: resetKey.value,
|
|
65
|
+
onError: props.onCatch,
|
|
66
|
+
}, {
|
|
67
|
+
default: () => props.children,
|
|
68
|
+
fallback: ({ error, reset }) => {
|
|
69
|
+
// Safely render the error component - either the provided one or the default
|
|
70
|
+
if (props.errorComponent) {
|
|
71
|
+
// Use the provided error component
|
|
72
|
+
return Vue.h(props.errorComponent, { error, reset });
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// Use the default error component
|
|
76
|
+
return Vue.h(defaultErrorComponent, { error, reset });
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
return Vue.h(CatchBoundaryWrapper);
|
|
84
|
+
}
|
|
85
|
+
// Error component
|
|
86
|
+
export const ErrorComponent = Vue.defineComponent({
|
|
87
|
+
name: 'ErrorComponent',
|
|
88
|
+
props: {
|
|
89
|
+
error: Object,
|
|
90
|
+
reset: Function,
|
|
91
|
+
},
|
|
92
|
+
setup(props) {
|
|
93
|
+
const show = Vue.ref(process.env.NODE_ENV !== 'production');
|
|
94
|
+
const toggleShow = () => {
|
|
95
|
+
show.value = !show.value;
|
|
96
|
+
};
|
|
97
|
+
return () => Vue.h('div', { style: { padding: '.5rem', maxWidth: '100%' } }, [
|
|
98
|
+
Vue.h('div', { style: { display: 'flex', alignItems: 'center', gap: '.5rem' } }, [
|
|
99
|
+
Vue.h('strong', { style: { fontSize: '1rem' } }, 'Something went wrong!'),
|
|
100
|
+
Vue.h('button', {
|
|
101
|
+
style: {
|
|
102
|
+
appearance: 'none',
|
|
103
|
+
fontSize: '.6em',
|
|
104
|
+
border: '1px solid currentColor',
|
|
105
|
+
padding: '.1rem .2rem',
|
|
106
|
+
fontWeight: 'bold',
|
|
107
|
+
borderRadius: '.25rem',
|
|
108
|
+
},
|
|
109
|
+
onClick: toggleShow,
|
|
110
|
+
}, show.value ? 'Hide Error' : 'Show Error'),
|
|
111
|
+
]),
|
|
112
|
+
Vue.h('div', { style: { height: '.25rem' } }),
|
|
113
|
+
show.value
|
|
114
|
+
? Vue.h('div', {}, [
|
|
115
|
+
Vue.h('pre', {
|
|
116
|
+
style: {
|
|
117
|
+
fontSize: '.7em',
|
|
118
|
+
border: '1px solid red',
|
|
119
|
+
borderRadius: '.25rem',
|
|
120
|
+
padding: '.3rem',
|
|
121
|
+
color: 'red',
|
|
122
|
+
overflow: 'auto',
|
|
123
|
+
},
|
|
124
|
+
}, [
|
|
125
|
+
props.error?.message
|
|
126
|
+
? Vue.h('code', {}, props.error.message)
|
|
127
|
+
: null,
|
|
128
|
+
]),
|
|
129
|
+
])
|
|
130
|
+
: null,
|
|
131
|
+
]);
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
//# sourceMappingURL=CatchBoundary.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CatchBoundary.jsx","sourceRoot":"","sources":["../../src/CatchBoundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAS1B,wCAAwC;AACxC,MAAM,gBAAgB,GAAG,GAAG,CAAC,eAAe,CAAC;IAC3C,IAAI,EAAE,kBAAkB;IACxB,KAAK,EAAE;QACL,OAAO,EAAE,QAAQ;QACjB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;KAC3B;IACD,KAAK,EAAE,CAAC,OAAO,CAAC;IAChB,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE;QACpB,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAe,IAAI,CAAC,CAAA;QACzC,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAsB,IAAI,CAAC,CAAA;QAElD,MAAM,KAAK,GAAG,GAAG,EAAE;YACjB,KAAK,CAAC,KAAK,GAAG,IAAI,CAAA;QACpB,CAAC,CAAA;QAED,qCAAqC;QACrC,GAAG,CAAC,KAAK,CACP,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EACpB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;YACjB,IAAI,MAAM,KAAK,MAAM,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;gBACrC,KAAK,EAAE,CAAA;YACT,CAAC;QACH,CAAC,CACF,CAAA;QAED,uCAAuC;QACvC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAU,EAAE,EAAE;YACjC,8EAA8E;YAC9E,2CAA2C;YAC3C,IACE,GAAG,YAAY,OAAO;gBACtB,CAAC,GAAG,IAAI,OAA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|
1
|
+
import * as Vue from 'vue';
|
|
2
|
+
export interface ClientOnlyProps {
|
|
3
|
+
/**
|
|
4
|
+
* The children to render when the JS is loaded.
|
|
5
|
+
*/
|
|
6
|
+
children?: Vue.VNode;
|
|
7
|
+
/**
|
|
8
|
+
* The fallback component to render if the JS is not yet loaded.
|
|
9
|
+
*/
|
|
10
|
+
fallback?: Vue.VNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Render the children only after the JS has loaded client-side. Use an optional
|
|
14
|
+
* fallback component if the JS is not yet loaded.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* Render a Chart component if JS loads, renders a simple FakeChart
|
|
18
|
+
* component server-side or if there is no JS. The FakeChart can have only the
|
|
19
|
+
* UI without the behavior or be a loading spinner or skeleton.
|
|
20
|
+
*
|
|
21
|
+
* ```tsx
|
|
22
|
+
* return (
|
|
23
|
+
* <ClientOnly fallback={<FakeChart />}>
|
|
24
|
+
* <Chart />
|
|
25
|
+
* </ClientOnly>
|
|
26
|
+
* )
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const ClientOnly: Vue.DefineComponent<Vue.ExtractPropTypes<{
|
|
30
|
+
fallback: {
|
|
31
|
+
type: Vue.PropType<Vue.VNode>;
|
|
32
|
+
default: null;
|
|
33
|
+
};
|
|
34
|
+
}>, () => Vue.VNode<Vue.RendererNode, Vue.RendererElement, {
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}> | Vue.VNode<Vue.RendererNode, Vue.RendererElement, {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}>[] | undefined, {}, {}, {}, Vue.ComponentOptionsMixin, Vue.ComponentOptionsMixin, {}, string, Vue.PublicProps, Readonly<Vue.ExtractPropTypes<{
|
|
39
|
+
fallback: {
|
|
40
|
+
type: Vue.PropType<Vue.VNode>;
|
|
41
|
+
default: null;
|
|
42
|
+
};
|
|
43
|
+
}>> & Readonly<{}>, {
|
|
44
|
+
fallback: Vue.VNode<Vue.RendererNode, Vue.RendererElement, {
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}>;
|
|
47
|
+
}, {}, {}, {}, string, Vue.ComponentProvideOptions, true, {}, any>;
|
|
48
|
+
/**
|
|
49
|
+
* Return a boolean indicating if the JS has been hydrated already.
|
|
50
|
+
* When doing Server-Side Rendering, the result will always be false.
|
|
51
|
+
* When doing Client-Side Rendering, the result will always be false on the
|
|
52
|
+
* first render and true from then on. Even if a new component renders it will
|
|
53
|
+
* always start with true.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* // Disable a button that needs JS to work.
|
|
58
|
+
* const hydrated = useHydrated()
|
|
59
|
+
* return (
|
|
60
|
+
* <button type="button" disabled={!hydrated.value} onClick={doSomethingCustom}>
|
|
61
|
+
* Click me
|
|
62
|
+
* </button>
|
|
63
|
+
* )
|
|
64
|
+
* ```
|
|
65
|
+
* @returns True if the JS has been hydrated already, false otherwise.
|
|
66
|
+
*/
|
|
67
|
+
export declare function useHydrated(): Vue.Ref<boolean>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as Vue from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Render the children only after the JS has loaded client-side. Use an optional
|
|
4
|
+
* fallback component if the JS is not yet loaded.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* Render a Chart component if JS loads, renders a simple FakeChart
|
|
8
|
+
* component server-side or if there is no JS. The FakeChart can have only the
|
|
9
|
+
* UI without the behavior or be a loading spinner or skeleton.
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* return (
|
|
13
|
+
* <ClientOnly fallback={<FakeChart />}>
|
|
14
|
+
* <Chart />
|
|
15
|
+
* </ClientOnly>
|
|
16
|
+
* )
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const ClientOnly = Vue.defineComponent({
|
|
20
|
+
name: 'ClientOnly',
|
|
21
|
+
props: {
|
|
22
|
+
fallback: {
|
|
23
|
+
type: Object,
|
|
24
|
+
default: null,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
setup(props, { slots }) {
|
|
28
|
+
const hydrated = useHydrated();
|
|
29
|
+
return () => {
|
|
30
|
+
if (hydrated.value) {
|
|
31
|
+
return slots.default?.();
|
|
32
|
+
}
|
|
33
|
+
return props.fallback ?? null;
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Return a boolean indicating if the JS has been hydrated already.
|
|
39
|
+
* When doing Server-Side Rendering, the result will always be false.
|
|
40
|
+
* When doing Client-Side Rendering, the result will always be false on the
|
|
41
|
+
* first render and true from then on. Even if a new component renders it will
|
|
42
|
+
* always start with true.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```tsx
|
|
46
|
+
* // Disable a button that needs JS to work.
|
|
47
|
+
* const hydrated = useHydrated()
|
|
48
|
+
* return (
|
|
49
|
+
* <button type="button" disabled={!hydrated.value} onClick={doSomethingCustom}>
|
|
50
|
+
* Click me
|
|
51
|
+
* </button>
|
|
52
|
+
* )
|
|
53
|
+
* ```
|
|
54
|
+
* @returns True if the JS has been hydrated already, false otherwise.
|
|
55
|
+
*/
|
|
56
|
+
export function useHydrated() {
|
|
57
|
+
const hydrated = Vue.ref(false);
|
|
58
|
+
Vue.onMounted(() => {
|
|
59
|
+
hydrated.value = true;
|
|
60
|
+
});
|
|
61
|
+
return hydrated;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=ClientOnly.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientOnly.jsx","sourceRoot":"","sources":["../../src/ClientOnly.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAa1B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC,eAAe,CAAC;IAC5C,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE;QACL,QAAQ,EAAE;YACR,IAAI,EAAE,MAAiC;YACvC,OAAO,EAAE,IAAI;SACd;KACF;IACD,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE;QACpB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;QAC9B,OAAO,GAAG,EAAE;YACV,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;gBACnB,OAAO,KAAK,CAAC,OAAO,EAAE,EAAE,CAAA;YAC1B,CAAC;YACD,OAAO,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAA;QAC/B,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAC/B,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAA;IACvB,CAAC,CAAC,CAAA;IACF,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as Vue from 'vue';
|
|
2
|
+
import type { RouterManagedTag } from '@tanstack/router-core';
|
|
3
|
+
export declare const useTags: () => () => RouterManagedTag[];
|
|
4
|
+
/**
|
|
5
|
+
* @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.
|
|
6
|
+
* It should be rendered in the `<head>` of your document.
|
|
7
|
+
*/
|
|
8
|
+
export declare const HeadContent: Vue.DefineComponent<{}, () => Vue.VNode<Vue.RendererNode, Vue.RendererElement, {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}>[], {}, {}, {}, Vue.ComponentOptionsMixin, Vue.ComponentOptionsMixin, {}, string, Vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, Vue.ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as Vue from 'vue';
|
|
2
|
+
import { Asset } from './Asset';
|
|
3
|
+
import { useRouter } from './useRouter';
|
|
4
|
+
import { useRouterState } from './useRouterState';
|
|
5
|
+
export const useTags = () => {
|
|
6
|
+
const router = useRouter();
|
|
7
|
+
const routeMeta = useRouterState({
|
|
8
|
+
select: (state) => {
|
|
9
|
+
return state.matches.map((match) => match.meta).filter(Boolean);
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
const meta = Vue.computed(() => {
|
|
13
|
+
const resultMeta = [];
|
|
14
|
+
const metaByAttribute = {};
|
|
15
|
+
let title;
|
|
16
|
+
[...routeMeta.value].reverse().forEach((metas) => {
|
|
17
|
+
;
|
|
18
|
+
[...metas].reverse().forEach((m) => {
|
|
19
|
+
if (!m)
|
|
20
|
+
return;
|
|
21
|
+
if (m.title) {
|
|
22
|
+
if (!title) {
|
|
23
|
+
title = {
|
|
24
|
+
tag: 'title',
|
|
25
|
+
children: m.title,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const attribute = m.name ?? m.property;
|
|
31
|
+
if (attribute) {
|
|
32
|
+
if (metaByAttribute[attribute]) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
metaByAttribute[attribute] = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
resultMeta.push({
|
|
40
|
+
tag: 'meta',
|
|
41
|
+
attrs: {
|
|
42
|
+
...m,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
if (title) {
|
|
49
|
+
resultMeta.push(title);
|
|
50
|
+
}
|
|
51
|
+
resultMeta.reverse();
|
|
52
|
+
return resultMeta;
|
|
53
|
+
});
|
|
54
|
+
const links = useRouterState({
|
|
55
|
+
select: (state) => state.matches
|
|
56
|
+
.map((match) => match.links)
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.flat(1)
|
|
59
|
+
.map((link) => ({
|
|
60
|
+
tag: 'link',
|
|
61
|
+
attrs: {
|
|
62
|
+
...link,
|
|
63
|
+
},
|
|
64
|
+
})),
|
|
65
|
+
});
|
|
66
|
+
const preloadMeta = useRouterState({
|
|
67
|
+
select: (state) => {
|
|
68
|
+
const preloadMeta = [];
|
|
69
|
+
state.matches
|
|
70
|
+
.map((match) => router.looseRoutesById[match.routeId])
|
|
71
|
+
.forEach((route) => router.ssr?.manifest?.routes[route.id]?.preloads
|
|
72
|
+
?.filter(Boolean)
|
|
73
|
+
.forEach((preload) => {
|
|
74
|
+
preloadMeta.push({
|
|
75
|
+
tag: 'link',
|
|
76
|
+
attrs: {
|
|
77
|
+
rel: 'modulepreload',
|
|
78
|
+
href: preload,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}));
|
|
82
|
+
return preloadMeta;
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
const headScripts = useRouterState({
|
|
86
|
+
select: (state) => state.matches
|
|
87
|
+
.map((match) => match.headScripts)
|
|
88
|
+
.flat(1)
|
|
89
|
+
.filter(Boolean).map(({ children, ...script }) => ({
|
|
90
|
+
tag: 'script',
|
|
91
|
+
attrs: {
|
|
92
|
+
...script,
|
|
93
|
+
},
|
|
94
|
+
children,
|
|
95
|
+
})),
|
|
96
|
+
});
|
|
97
|
+
return () => uniqBy([
|
|
98
|
+
...meta.value,
|
|
99
|
+
...preloadMeta.value,
|
|
100
|
+
...links.value,
|
|
101
|
+
...headScripts.value,
|
|
102
|
+
], (d) => {
|
|
103
|
+
return JSON.stringify(d);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.
|
|
108
|
+
* It should be rendered in the `<head>` of your document.
|
|
109
|
+
*/
|
|
110
|
+
export const HeadContent = Vue.defineComponent({
|
|
111
|
+
name: 'HeadContent',
|
|
112
|
+
setup() {
|
|
113
|
+
const tags = useTags();
|
|
114
|
+
return () => {
|
|
115
|
+
return tags().map((tag) => Vue.h(Asset, {
|
|
116
|
+
...tag,
|
|
117
|
+
key: `tsr-meta-${JSON.stringify(tag)}`,
|
|
118
|
+
}));
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
function uniqBy(arr, fn) {
|
|
123
|
+
const seen = new Set();
|
|
124
|
+
return arr.filter((item) => {
|
|
125
|
+
const key = fn(item);
|
|
126
|
+
if (seen.has(key)) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
seen.add(key);
|
|
130
|
+
return true;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=HeadContent.jsx.map
|