Repository URL to install this package:
|
Version:
6.1.0 ▾
|
import { MemoryRouter, StaticRouter, match } from 'react-router'
import { BrowserRouter } from 'react-router-dom'
// import { Serializable } from 'chain-able-boost'
// import * as HistoryType from 'history'
import { ClassAttributes } from 'react'
// should just compose with `&`
export interface DefaultPropsWithRouter<Props = any>
extends ClassAttributes<Props> {
location?: {
pathname?: string
}
}
/**
* @see https://github.com/mjackson/history
*/
export type Action = 'PUSH' | 'POP' | 'REPLACE'
export type UnregisterCallback = () => void
export type LocationDescriptor = Path | LocationDescriptorObject
export type LocationKey = string
export type LocationListener = (location: Location, action: Action) => void
export type LocationState = any
export type Path = string
export type Pathname = string
export type Search = string
export type TransitionHook = (
location: Location,
callback: (result: any) => void
) => any
export interface HistoryType {
length: number
action: Action
location: Location
push(path: Path, state?: LocationState): void
push(location: LocationDescriptorObject): void
replace(path: Path, state?: LocationState): void
replace(location: LocationDescriptorObject): void
go(n: number): void
goBack(): void
goForward(): void
block(prompt?: boolean): UnregisterCallback
listen(listener: LocationListener): UnregisterCallback
createHref(location: LocationDescriptorObject): Href
}
export interface Location {
pathname: Pathname
search: Search
state?: LocationState
hash: Hash
key?: LocationKey
// ... @todo added @@fixme
href?: string
origin?: string
}
export interface LocationDescriptorObject {
pathname?: Pathname
search?: Search
state?: LocationState
hash?: Hash
key?: LocationKey
}
/**
* @see https://gist.github.com/icfantv/775a6000748384e9f77569017d67c240
* @see https://github.com/Microsoft/TypeScript/issues/6579
* @description /^(?:[a-z]+:)?/
*/
export type FullyQualifiedWebAddress = string
export type RelativeWebAddress = '/route' | string
export type StringifiedParam = '=' | '?' | '#' | String
export type OneRouterParamVariations = Object | StringifiedParam
export type Hash = string
export type Href = string
// === domain specific ===
export interface OneRouterOptions {
shouldUseNative?: boolean
shouldStringify?: boolean
shouldMerge?: boolean
}
export type OneRouterSubscriberOnChange = LocationListener
export interface UpdateToObj {
pathname?: never
[key: string]: SerializableType
}
export type UpdateTo = UpdateToObj | string | Array<UpdateToObj | string>
// MemoryRouter | StaticRouter
// | BrowserRouter
export type RouterType<Params = any> = {
history: HistoryType
// location: Location
route: {
location: Location
match: match<Params>
}
}
declare var window: any
// === serializable ===
export type SerializableType =
| SerializableObj
| SerializableArray
| string
| number
| undefined
| null
export interface SerializableObj {
[key: string]: SerializableType
[key: number]: SerializableType
}
export type SerializableArray = Array<
SerializableObj | string | number | undefined | null
>
export type Serializable = SerializableObj | SerializableArray
export interface ObjWithValuesSerialized {
[key: string]: string | ObjWithValuesSerialized | ObjWithValuesSerialized[]
}
// === url ===
export interface OneUrl {
protocol: string
host: string
pathname: '/' | string
search: Serializable
hash: string
full: string
userAgent: string
toString?(): string
[Symbol.toPrimitive]?(): string
}
export interface OneRouterToRuleThemAllRehydratable {
// use here for `.from`
}
export type ParsedSearchParams = ObjWithValuesSerialized | '' | any[]
export type MatchedValue = string | number | boolean | undefined
export interface Matches {
[key: string]: MatchedValue | Matches | Matches[] | MatchedValue[]
}
export type MatchPathParamsType = {
params: {
[key: string]: any
}
}
export interface AnyObj {
[key: string]: any
}
export type StringArrayOrFrozenStringArray = string[] | Readonly<string[]>
export type PathParamsType = AnyObj | StringArrayOrFrozenStringArray
export interface RoutePathObjType {
path: string
component?: any
exact?: boolean
key?: any
}
export interface OneRouterConfigObjType {
pathParams: PathParamsType
// may not be `StringArrayOrFrozenStringArray`
routePathsList: StringArrayOrFrozenStringArray | RoutePathObjType[]
}
export interface OneRouterConfigMap extends Map<string, any> {
/* @todo - this is being mutated in the deps... */
get(key: 'pathParams'): PathParamsType | Readonly<PathParamsType>
set(key: 'pathParams', value: PathParamsType | Readonly<PathParamsType>): this
get(key: 'routePathsList'): StringArrayOrFrozenStringArray
set(key: 'routePathsList', value: StringArrayOrFrozenStringArray): this
}
export interface OneRouterStoreType extends Map<string, any> {
get(key: 'urlList'): StringArrayOrFrozenStringArray
set(key: 'urlList', value: StringArrayOrFrozenStringArray): this
get(key: 'url'): string
set(key: 'url', value: string): this
get(key: 'tapEntries'): TapEntriesType
set(key: 'tapEntries', value: TapEntriesType): this
get(key: 'hasTappedEntries'): boolean
set(key: 'hasTappedEntries', value: boolean): this
get(key: 'entries'): AnyObj
set(key: 'entries', value: AnyObj): this
get(key: 'router'): RouterType
set(key: 'router', value: RouterType): this
}
export type OneRouterEntriesType<Params = any> = Params & {
[key: string]: any
}
export type TapEntriesType = (entries: OneRouterEntriesType) => any