/**
* Attributes for HTML form elements
*/
export declare interface FormAttributes {
/** Form action URL (with method spoofing via _method parameter if needed) */
action: string;
/** Form method (always 'get' or 'post') */
method: 'get' | 'post';
}
/**
* Utility type to remove the first parameter from a tuple
*/
declare type RemoveFirstParam = T extends [any, ...infer Rest] ? Rest : T;
/**
* Route helper function with method variants (no form support)
* Matches the interface generated by nb_routes in rich mode
*/
export declare interface RouteHelper {
/** Main helper - returns RouteResult with url and method */
(...args: TParams): RouteResult;
/** GET method variant */
get(...args: TParams): RouteResult;
/** POST method variant */
post(...args: TParams): RouteResult;
/** PATCH method variant */
patch(...args: TParams): RouteResult;
/** PUT method variant */
put(...args: TParams): RouteResult;
/** DELETE method variant */
delete(...args: TParams): RouteResult;
/** HEAD method variant */
head(...args: TParams): RouteResult;
/** URL-only variant - returns just the URL string */
url(...args: TParams): string;
}
/**
* Route helper function with method and form variants
* Matches the interface generated by nb_routes in rich mode
*/
export declare interface RouteHelperWithForm {
/** Main helper - returns RouteResult with url and method */
(...args: TParams): RouteResult;
/** GET method variant */
get(...args: TParams): RouteResult;
/** POST method variant */
post(...args: TParams): RouteResult;
/** PATCH method variant */
patch(...args: TParams): RouteResult;
/** PUT method variant */
put(...args: TParams): RouteResult;
/** DELETE method variant */
delete(...args: TParams): RouteResult;
/** HEAD method variant */
head(...args: TParams): RouteResult;
/** URL-only variant - returns just the URL string */
url(...args: TParams): string;
/** Form helper - returns FormAttributes for use with HTML forms */
form: {
/** Main form helper - uses the route's original HTTP method */
(...args: TParams): FormAttributes;
/** PATCH form variant */
patch(...args: TParams): FormAttributes;
/** PUT form variant */
put(...args: TParams): FormAttributes;
/** DELETE form variant */
delete(...args: TParams): FormAttributes;
};
}
/**
* Result returned by rich route helpers
*/
export declare interface RouteResult {
/** Generated URL */
url: string;
/** HTTP method */
method: 'get' | 'post' | 'patch' | 'put' | 'delete' | 'head' | 'options';
}
/**
* Transform a route helper to remove the scope parameter (first parameter)
*/
declare type ScopedRouteHelper = T extends RouteHelperWithForm ? RouteHelperWithForm> : T extends RouteHelper ? RouteHelper> : T;
/**
* Transform all route helpers in an object to their scoped versions
*/
export declare type ScopedRoutes> = {
[K in keyof TRoutes]: ScopedRouteHelper;
};
/**
* React hook that provides auto-scoped route helpers
*
* Automatically injects a scope parameter from Inertia page props as the first
* parameter to all route helpers, eliminating the need to manually pass it
* throughout your application.
*
* @param routeHelpers - Object containing route helper functions
* @param options - Configuration for scope parameter injection
* @returns Route helpers with scope parameter removed from signatures
*
* @throws {Error} If scope value is not available and throwOnMissing is true
*
* @example
* // Setup in your app
* import { useRoutes } from '@nordbeam/nb-inertia/react/useRoutes';
* import * as rawRoutes from './routes';
*
* function MyComponent() {
* const routes = useRoutes(rawRoutes, {
* scopeParam: 'account_subdomain',
* getScopeValue: (props) => props.currentScope?.account?.subdomain,
* });
*
* // Before (manual scope passing)
* // router.visit(rawRoutes.spaces_index_path(account.subdomain));
* // router.visit(rawRoutes.space_path(account.subdomain, space.id));
*
* // After (auto-scoped)
* router.visit(routes.spaces_index_path());
* router.visit(routes.space_path(space.id));
* }
*/
declare function useRoutes = Record, TPageProps = Record>(routeHelpers: TRoutes, options: UseRoutesOptions): ScopedRoutes;
export default useRoutes;
export { useRoutes }
/**
* useRoutes Hook for Auto-Scoped Route Helpers
*
* Automatically injects a scope parameter (e.g., account subdomain) into route helpers,
* eliminating the need for manual prop drilling throughout your application.
*
* @example
* import { useRoutes } from '@nordbeam/nb-inertia/react/useRoutes';
* import * as rawRoutes from './routes';
*
* function MyComponent() {
* const routes = useRoutes(rawRoutes, {
* scopeParam: 'account_subdomain',
* getScopeValue: (props) => props.currentScope?.account?.subdomain,
* });
*
* // Subdomain automatically injected!
* router.visit(routes.spaces_index_path());
* router.visit(routes.space_path(space.id));
* }
*/
export declare interface UseRoutesOptions> {
/**
* Name of the parameter to auto-inject (e.g., 'account_subdomain', 'tenant_id')
*/
scopeParam: string;
/**
* Function to extract the scope value from Inertia page props
* Receives the page props and should return the value to inject
*
* @example
* getScopeValue: (props) => props.currentScope?.account?.subdomain
*/
getScopeValue: (props: TPageProps) => string | number | undefined;
/**
* Whether to throw an error if the scope value is not available
* @default true
*/
throwOnMissing?: boolean;
}
export { }