@standardbeagle/virtual-router 1.0.0 → 1.1.0

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.
@@ -0,0 +1,18 @@
1
+ import { Component, ReactNode, ErrorInfo } from 'react';
2
+ interface Props {
3
+ children: ReactNode;
4
+ fallback?: ReactNode;
5
+ onError?: (error: Error, errorInfo: ErrorInfo) => void;
6
+ }
7
+ interface State {
8
+ hasError: boolean;
9
+ error?: Error;
10
+ errorInfo?: ErrorInfo;
11
+ }
12
+ export declare class RouterErrorBoundary extends Component<Props, State> {
13
+ constructor(props: Props);
14
+ static getDerivedStateFromError(error: Error): State;
15
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
16
+ render(): string | number | boolean | Iterable<ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
17
+ }
18
+ export {};
@@ -0,0 +1,20 @@
1
+ import { ReactNode } from 'react';
2
+ interface RouterError {
3
+ message: string;
4
+ code?: string;
5
+ path?: string;
6
+ timestamp: number;
7
+ }
8
+ interface ErrorContextType {
9
+ errors: RouterError[];
10
+ addError: (error: RouterError) => void;
11
+ clearErrors: () => void;
12
+ clearError: (timestamp: number) => void;
13
+ }
14
+ interface ErrorProviderProps {
15
+ children: ReactNode;
16
+ }
17
+ export declare function ErrorProvider({ children }: ErrorProviderProps): import("react/jsx-runtime").JSX.Element;
18
+ export declare function useRouteError(): RouterError | null;
19
+ export declare function useRouteErrors(): ErrorContextType | null;
20
+ export {};
@@ -0,0 +1,38 @@
1
+ import { ReactNode } from 'react';
2
+ interface FormData {
3
+ [key: string]: string | File | (string | File)[];
4
+ }
5
+ interface FormHandlerProps {
6
+ action?: string;
7
+ method?: 'GET' | 'POST';
8
+ onSubmit?: (data: FormData, navigate: (path: string) => void) => void;
9
+ children: ReactNode;
10
+ className?: string;
11
+ id?: string;
12
+ }
13
+ export declare function Form({ action, method, onSubmit, children, ...props }: FormHandlerProps): import("react/jsx-runtime").JSX.Element;
14
+ export declare function useFormData(): FormData | null;
15
+ interface SubmitButtonProps {
16
+ formAction?: string;
17
+ formMethod?: 'GET' | 'POST';
18
+ children: ReactNode;
19
+ type?: 'submit' | 'button';
20
+ className?: string;
21
+ disabled?: boolean;
22
+ }
23
+ export declare function SubmitButton({ formAction, formMethod, children, type, ...props }: SubmitButtonProps): import("react/jsx-runtime").JSX.Element;
24
+ export declare function useFormSubmission(): {
25
+ isSubmitting: boolean;
26
+ lastSubmission: FormData | null;
27
+ error: Error | null;
28
+ };
29
+ interface FormLinkProps {
30
+ to: string;
31
+ formData?: FormData;
32
+ method?: 'GET' | 'POST';
33
+ children: ReactNode;
34
+ className?: string;
35
+ onClick?: () => void;
36
+ }
37
+ export declare function FormLink({ to, formData, method, children, onClick, ...props }: FormLinkProps): import("react/jsx-runtime").JSX.Element;
38
+ export {};
@@ -0,0 +1 @@
1
+ export * from './nextjs'
@@ -0,0 +1,24 @@
1
+ import { j as jsxRuntimeExports, c as PathProvider } from "../provider-F-pulqTx.js";
2
+ import { useCallback } from "react";
3
+ import { usePathname, useRouter } from "next/navigation";
4
+ function NextRouterConnector({ basePath, children, path }) {
5
+ const pathname = usePathname();
6
+ const router = useRouter();
7
+ const handleChange = useCallback((newPath) => {
8
+ router.push(newPath);
9
+ }, [router]);
10
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
11
+ PathProvider,
12
+ {
13
+ path: path ?? "/",
14
+ basePath,
15
+ externalPath: pathname,
16
+ onChange: handleChange,
17
+ children
18
+ }
19
+ );
20
+ }
21
+ export {
22
+ NextRouterConnector
23
+ };
24
+ //# sourceMappingURL=nextjs.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextjs.es.js","sources":["../../src/connectors/nextjs.tsx"],"sourcesContent":["import { useCallback } from 'react';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { PathProvider } from '../provider';\nimport type { ConnectorProps } from './types';\n\nexport function NextRouterConnector({ basePath, children, path }: ConnectorProps) {\n const pathname = usePathname();\n const router = useRouter();\n\n const handleChange = useCallback((newPath: string) => {\n router.push(newPath);\n }, [router]);\n\n return (\n <PathProvider\n path={path ?? '/'}\n basePath={basePath}\n externalPath={pathname}\n onChange={handleChange}\n >\n {children}\n </PathProvider>\n );\n}\n"],"names":["jsx"],"mappings":";;;AAKO,SAAS,oBAAoB,EAAE,UAAU,UAAU,QAAwB;AAC9E,QAAM,WAAW;AACjB,QAAM,SAAS;AAET,QAAA,eAAe,YAAY,CAAC,YAAoB;AAClD,WAAO,KAAK,OAAO;AAAA,EAAA,GACpB,CAAC,MAAM,CAAC;AAGP,SAAAA,kCAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAM,QAAQ;AAAA,MACd;AAAA,MACA,cAAc;AAAA,MACd,UAAU;AAAA,MAET;AAAA,IAAA;AAAA,EAAA;AAGb;"}
@@ -0,0 +1 @@
1
+ export * from './react-router'
@@ -0,0 +1,24 @@
1
+ import { j as jsxRuntimeExports, c as PathProvider } from "../provider-F-pulqTx.js";
2
+ import { useCallback } from "react";
3
+ import { useLocation, useNavigate } from "react-router-dom";
4
+ function ReactRouterConnector({ basePath, children, path }) {
5
+ const location = useLocation();
6
+ const navigate = useNavigate();
7
+ const handleChange = useCallback((newPath) => {
8
+ navigate(newPath);
9
+ }, [navigate]);
10
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
11
+ PathProvider,
12
+ {
13
+ path: path ?? "/",
14
+ basePath,
15
+ externalPath: location.pathname,
16
+ onChange: handleChange,
17
+ children
18
+ }
19
+ );
20
+ }
21
+ export {
22
+ ReactRouterConnector
23
+ };
24
+ //# sourceMappingURL=react-router.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-router.es.js","sources":["../../src/connectors/react-router.tsx"],"sourcesContent":["import { useCallback } from 'react';\nimport { useLocation, useNavigate } from 'react-router-dom';\nimport { PathProvider } from '../provider';\nimport type { ConnectorProps } from './types';\n\nexport function ReactRouterConnector({ basePath, children, path }: ConnectorProps) {\n const location = useLocation();\n const navigate = useNavigate();\n\n const handleChange = useCallback((newPath: string) => {\n navigate(newPath);\n }, [navigate]);\n\n return (\n <PathProvider\n path={path ?? '/'}\n basePath={basePath}\n externalPath={location.pathname}\n onChange={handleChange}\n >\n {children}\n </PathProvider>\n );\n}\n"],"names":["jsx"],"mappings":";;;AAKO,SAAS,qBAAqB,EAAE,UAAU,UAAU,QAAwB;AAC/E,QAAM,WAAW;AACjB,QAAM,WAAW;AAEX,QAAA,eAAe,YAAY,CAAC,YAAoB;AAClD,aAAS,OAAO;AAAA,EAAA,GACjB,CAAC,QAAQ,CAAC;AAGT,SAAAA,kCAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAM,QAAQ;AAAA,MACd;AAAA,MACA,cAAc,SAAS;AAAA,MACvB,UAAU;AAAA,MAET;AAAA,IAAA;AAAA,EAAA;AAGb;"}
@@ -0,0 +1 @@
1
+ export * from './tanstack'
@@ -0,0 +1,24 @@
1
+ import { j as jsxRuntimeExports, c as PathProvider } from "../provider-F-pulqTx.js";
2
+ import { useCallback } from "react";
3
+ import { useLocation, useNavigate } from "@tanstack/react-router";
4
+ function TanStackRouterConnector({ basePath, children, path }) {
5
+ const location = useLocation();
6
+ const navigate = useNavigate();
7
+ const handleChange = useCallback((newPath) => {
8
+ navigate({ to: newPath });
9
+ }, [navigate]);
10
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
11
+ PathProvider,
12
+ {
13
+ path: path ?? "/",
14
+ basePath,
15
+ externalPath: location.pathname,
16
+ onChange: handleChange,
17
+ children
18
+ }
19
+ );
20
+ }
21
+ export {
22
+ TanStackRouterConnector
23
+ };
24
+ //# sourceMappingURL=tanstack.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tanstack.es.js","sources":["../../src/connectors/tanstack.tsx"],"sourcesContent":["import { useCallback } from 'react';\nimport { useLocation, useNavigate } from '@tanstack/react-router';\nimport { PathProvider } from '../provider';\nimport type { ConnectorProps } from './types';\n\nexport function TanStackRouterConnector({ basePath, children, path }: ConnectorProps) {\n const location = useLocation();\n const navigate = useNavigate();\n\n const handleChange = useCallback((newPath: string) => {\n navigate({ to: newPath });\n }, [navigate]);\n\n return (\n <PathProvider\n path={path ?? '/'}\n basePath={basePath}\n externalPath={location.pathname}\n onChange={handleChange}\n >\n {children}\n </PathProvider>\n );\n}\n"],"names":["jsx"],"mappings":";;;AAKO,SAAS,wBAAwB,EAAE,UAAU,UAAU,QAAwB;AAClF,QAAM,WAAW;AACjB,QAAM,WAAW;AAEX,QAAA,eAAe,YAAY,CAAC,YAAoB;AACzC,aAAA,EAAE,IAAI,QAAA,CAAS;AAAA,EAAA,GACzB,CAAC,QAAQ,CAAC;AAGT,SAAAA,kCAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAM,QAAQ;AAAA,MACd;AAAA,MACA,cAAc,SAAS;AAAA,MACvB,UAAU;AAAA,MAET;AAAA,IAAA;AAAA,EAAA;AAGb;"}
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from 'react';
2
+ export interface ConnectorProps {
3
+ basePath: string;
4
+ children: ReactNode;
5
+ path?: string;
6
+ }
7
+ export declare function stripBasePath(basePath: string, fullPath: string): string;
8
+ export declare function prependBasePath(basePath: string, internalPath: string): string;
package/dist/index.d.ts CHANGED
@@ -1,19 +1,29 @@
1
1
  import React from 'react';
2
- import type { PropsWithChildren } from 'react';
3
- import type { ReactElement } from 'react';
2
+ import type { ComponentProps } from 'react';
3
+ import type { ReactElement, ReactNode } from 'react';
4
+ import type { RouteParams, SearchParams, NavigationObject } from './types.ts';
4
5
  export { PathProvider } from './provider.tsx';
6
+ export type { ConnectorProps } from './connectors/types';
5
7
  export declare function usePath(): string;
6
- export declare function useHistory(): string[];
8
+ export declare function useHistory(): readonly string[];
7
9
  export declare function useNavigate(): (url: string) => void;
8
- export declare function useNavigation(): any;
9
- export declare function useParams(): any;
10
- export declare function useSearchParams(): any;
11
- export declare function useRouteError(): any;
12
- export declare const Link: React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<unknown>>;
10
+ export declare function useNavigation(): NavigationObject;
11
+ export declare function useParams(): RouteParams;
12
+ export declare function useSearchParams(): SearchParams;
13
+ export { useRouteError, useRouteErrors, ErrorProvider } from './ErrorContext';
14
+ export { RouterErrorBoundary } from './ErrorBoundary';
15
+ export { Form, SubmitButton, FormLink, useFormData, useFormSubmission } from './FormHandler';
16
+ interface LinkProps extends Omit<ComponentProps<'a'>, 'href' | 'onClick'> {
17
+ to: string;
18
+ children: ReactNode;
19
+ }
20
+ export declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
13
21
  interface RoutesProps {
22
+ children?: ReactNode;
14
23
  }
15
- export declare function Routes(props: PropsWithChildren<RoutesProps>): ReactElement;
24
+ export declare function Routes({ children }: RoutesProps): ReactElement;
16
25
  interface RouteProps {
17
- route: string;
26
+ path: string;
27
+ children?: ReactNode;
18
28
  }
19
- export declare function Route(_: PropsWithChildren<RouteProps>): ReactElement;
29
+ export declare function Route(_: RouteProps): ReactElement;