import type { Match, LocationDescriptor, RouteObject as Route, useRouter as useRouterFromFound } from '@catamphetamine/found'; // import type { Match, LocationDescriptor } from 'found'; export type { RouteObject as Route } from '@catamphetamine/found'; import type { Dispatch, Action as ReduxAction, ActionCreator, Reducer, UnknownAction } from 'redux'; import type { TypedUseSelectorHook } from 'react-redux'; import type { Location, LocationInput, HttpClient } from './types.d.js'; export type { Location, LocationInput, Settings, HttpClient } from './types.d.js' export interface LocationHistory { push(location: LocationInput): void; replace(location: LocationInput): void; go(position: number): void; } export interface NavigateOptions { load?: boolean; instantBack?: boolean; context?: any; } export interface RedirectOptions { load?: boolean; } export function getHttpClient(): HttpClient; export function getPreferredLocale(): string | undefined; export function getPreferredLocales(): string[]; export function getLanguageFromLocale(locale: string): string; export function wasInstantNavigation(): boolean; export function isInstantBackAbleNavigation(): boolean; export function canGoBackInstantly(): boolean; export function canGoForwardInstantly(): boolean; type ReduxModuleActionResultApplier = string | ReduxModuleActionResultApplierFunction; type ReduxModuleActionResultApplierFunction = (state: State, ...args: Parameters) => State type ReduxModuleAsyncAction = (...args: Parameters) => (http: HttpClient) => Promise export type Settings = Record export class ReduxModule = UnknownAction> { constructor(namespace?: string, settings?: Settings); // Deprecated? // Replaces an event handler with a custom one. replace(event: string, handler: Reducer): void; // Adds an event handler with a custom one. on(namespace: string, event: string, handler: Reducer): void; on(namespaceAndEvent: string, handler: Reducer): void; action(event: string, action: ReduxModuleAsyncAction, result: ReduxModuleActionResultApplier>): ActionCreator; action(event: string, action: ReduxModuleAsyncAction): ActionCreator; action(action: ReduxModuleAsyncAction, result: ReduxModuleActionResultApplier>): ActionCreator; action(action: ReduxModuleAsyncAction): ActionCreator; simpleAction(event: string, result: ReduxModuleActionResultApplier): ActionCreator; simpleAction(result: ReduxModuleActionResultApplier): ActionCreator; reducer(initialState?: State): Reducer; } export function underscoredToCamelCase(string: string): string; interface LinkProps extends React.AnchorHTMLAttributes { to: string | LocationInput; navigationContext?: NavigationContext; } export const Link: React.ForwardRefExoticComponent>; export function getCookie(name: string): string | undefined; // `` route. export interface Redirect { path?: string; to: string | ((match: Match) => LocationDescriptor); status?: number; } // Returns a `found` router object. export const useRouter: useRouterFromFound // These are "older" ways of `dispatch()`-ing Redux actions to perform a navigation action. // In React components code, consider using the corresponding hooks instead. // // These Redux action creators are still not removed though: // // * Older projects might still be using them. By not removing those actions, // the migration path is easier for those "legacy" projects. // // * In some edge cases, it may be required to perform a navigation action from somewhere // outside of any React component: for example, from a Redux "middleware". // For example, one could be using `import { isRejectedWithValue } from '@reduxjs/toolkit'` // in order to detect errors and then redirect to the `/error` page if there was an error. // export function goto(location: LocationInput, options?: NavigateOptions): UnknownAction; export function redirect(location: LocationInput, options?: RedirectOptions): UnknownAction; export function pushLocation(location: LocationInput, options?: NavigateOptions): UnknownAction; export function replaceLocation(location: LocationInput, options?: RedirectOptions): UnknownAction; export function goBack(): UnknownAction; export function goBackTwoPages(): UnknownAction; export function goForward(): UnknownAction; export interface NavigationPage { location: Location; route: string; params: Record; instantBack: boolean; navigationContext?: NavigationContext; } export function useBeforeNavigateToAnotherPage(callback: (newPage: NavigationPage) => void): void; export function useBeforeRenderAnotherPage(callback: (newPage: NavigationPage) => void): void; // export function useAfterNavigatedToAnotherPage(callback: (newPage: NavigationPage) => void): void; export function useAfterRenderedThisPage(callback: (newPage: NavigationPage) => void): void; export function useBeforeRenderNewPage(callback: (newPage: NavigationPage, prevPage?: NavigationPage) => void): void; export function useAfterRenderedNewPage(callback: (newPage: NavigationPage, prevPage?: NavigationPage) => void): void; export function useNavigationLocation(): Location; export function usePageStateSelector unknown = (state: State) => unknown>(reducerName: PageStateReducerName, selector: Selector): ReturnType; export function usePageStateSelectorOutsideOfPage unknown = (state: State) => unknown>(reducerName: PageStateReducerName, selector: Selector): ReturnType; export function useLocation(): Location; export function useLocationHistory(): LocationHistory; export function useGoBack(): () => void; export function useGoForward(): () => void; export function useNavigate(): (location: LocationInput, options?: NavigateOptions) => void; export function useRedirect(): (location: LocationInput, options?: RedirectOptions) => void; export function useLoading(): boolean; export function useRoute(): Route; export function updateReducers = UnknownAction>(reducers: Record>): void; // Navigation history. // Each entry is an object having properties: // * `route: string` — Example: "/user/:userId/post/:postId". // * `action: string` — One of: "start", "push", "redirect", "back", "forward". export interface NavigationHistory { route: string; action: 'start' | 'push' | 'redirect' | 'back' | 'forward'; } export type PageLoadFunction, State = any, LoadContext = any, NavigationContext = any> = (parameters: { dispatch: Dispatch, useSelector: TypedUseSelectorHook, context?: LoadContext, navigationContext?: NavigationContext, location: Location, params: Record, history: NavigationHistory, server: boolean; getCookie: (name: string) => string | null; }) => Promise<{ props?: Props, redirect?: { url: string } } | void>; // export interface PageMetaImage { // // `_` is image URL. // _: string; // width: number; // height: number; // type: string; // } type PageMetaValue = string | number | boolean; // Objects are expanded: `{ a: { b: 'c' } }` becomes ``. // Arrays of values are expanded: `[{ a: 'b' }, { a: 'c' }]` becomes `` and ``. // Arrays of objects are expanded: `[{ a: { b: 'c' } }, { a: { b: 'd' } }]` becomes `` and ``. type PageMetaObject = Record; export type PageMetaFunction, State = any, PageStateReducerName = string> = (parameters: { props: Props, useSelector: TypedUseSelectorHook, usePageStateSelector: (reducerName: PageStateReducerName, selector: (state: State) => unknown) => any }) => Record | void;