/** * vapor-chamber-router — composables. Vue 3.6-native: cleanup via * onScopeDispose directly, reads through the router's shallowRefs. */ import { type Ref } from 'vue'; import { type Breadcrumb, type MenuItem } from './menu'; import type { Router } from './router-type'; import type { QueryParamDef, RouteLocation } from './types'; export declare function useRouter(): Router; /** Reactive current location (URL state — outlets read snapshot.render). */ export declare function useRoute(): { readonly value: RouteLocation; }; /** * A real Vue `Ref` whose backing store is the URL, plus explicit history * controls. * * Being an actual ref matters: refs returned from `setup()` are AUTO-UNWRAPPED * in templates, so `{{ page }}` works and `.value` is script-only — exactly * like `useRoute()`, `useRouteData()` and every sibling composable. A * lookalike object with a `value` accessor does NOT unwrap, which made this * the one composable whose templates needed `.value`. */ export type QueryParamHandle = Ref & { /** Write with an explicit pushState (back returns to the old value). */ push: (next: T) => void; /** Write with an explicit replaceState (no history entry). */ replace: (next: T) => void; /** Remove the key from the URL (reads fall back to the declared default). */ clear: () => void; }; /** * Typed, writable access to one query param through the query fast path — * never triggers matching, guards or remounts. Loaders whose template * depends on the key refetch automatically. */ export declare function useQueryParam(key: string, def?: QueryParamDef): QueryParamHandle; /** * Loader data of the current route (two-phase committed — never the previous * page's data). By default the LEAF record's data; pass a record name when a * layout ancestor also loads. */ export declare function useRouteData(recordName?: string): { readonly value: T | undefined; }; /** * Route-level error boundary: the latest navigation error (RouterError with * a machine-readable `code`) plus clear(). */ export declare function useRouteError(): { latestError: { readonly value: unknown; }; clear: () => void; }; /** * The navigation menu, projected from the route table (see menu.ts for the * contract: `meta.menu` position + `meta.title` i18n key, nested by nearest * menued ancestor, server-side permission filtering, data-active semantics). * Reactive to navigation AND table swaps (setRoutes / reload). */ export declare function useMenu(): { readonly value: readonly MenuItem[]; }; /** * Parent-chain breadcrumbs of the current route: matched records carrying a * `meta.title`, root-first, the page itself last (`current: true`). Group * rows and ancestors whose params the location can't supply come href-less. */ export declare function useBreadcrumbs(): { readonly value: readonly Breadcrumb[]; }; /** * Leave guard scoped to the calling component's lifetime: fires on every * PATH navigation (query changes never trigger it) while mounted; return * false to refuse. Pairs with dirty-state trackers for unsaved-changes * protection. Auto-disposes with the component scope. */ export declare function onBeforeLeave(guard: (to: RouteLocation, from: RouteLocation) => boolean | void | Promise): () => void; /** What a paginated loader response is read as. Every field has a default * extractor covering the common envelope shapes; override any of them when * your backend disagrees. */ export type PaginationOptions = { /** Read another record's loader data (default: the leaf record). */ recordName?: string; /** Query key carrying the page number. Default: 'page'. */ key?: string; items?: (data: any) => readonly T[]; total?: (data: any) => number; perPage?: (data: any) => number; lastPage?: (data: any) => number; /** How many numbered links `pageRange` produces. Default: 7. */ window?: number; }; export type Pagination = { /** Rows of the current page — the loader's, committed with the snapshot. */ items: Readonly>; /** The page number, backed by the URL. Writable: `page.value = 3`. */ page: QueryParamHandle; perPage: Readonly>; total: Readonly>; lastPage: Readonly>; hasNext: Readonly>; hasPrev: Readonly>; /** Windowed page numbers for a pager UI; 0 marks an elision ("…"). */ pageRange: Readonly>; /** True while a loader for the current navigation is in flight. */ loading: Readonly>; next: () => void; prev: () => void; go: (page: number) => void; }; /** * Pagination over a loader-backed list, driven entirely by the URL. * * `page` is a query param, so a page change is STATE, not navigation: no * matching, no guards, no remount — only the loaders whose template depends * on the key refetch, with the previous request aborted. `page` pushes by * convention, so Back steps through pages, and the URL is shareable. * * const { items, page, hasNext, next, pageRange, loading } = usePagination(); * * Reading the response is the only part that varies between backends, so each * extractor is overridable; the defaults accept `{ items | data }` with * `{ total, per_page | perPage, last_page | lastPage }` (or their `meta` * nesting), which covers Laravel's paginator and most plain-JSON APIs. */ export declare function usePagination(options?: PaginationOptions): Pagination; //# sourceMappingURL=composables.d.ts.map