This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
163 lines (136 loc) · 5.87 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import * as Inertia from '@inertiajs/core'
import { renderToString } from 'preact-render-to-string'
import * as Preact from 'preact/src/index'
import { JSXInternal } from 'preact/src/jsx'
// Missing interface from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/afd309b4193c1f448386bf8fe09e512e4422e69e/types/react/index.d.ts#L146
export interface PreactElement<
P = any,
T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>,
> {
type: T
props: P
key: Preact.Key | null
}
// Missing interface from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/afd309b4193c1f448386bf8fe09e512e4422e69e/types/react/index.d.ts#L84
export type JSXElementConstructor<P> =
| ((props: P) => PreactElement<any, any> | null)
| (new (props: P) => Preact.Component<any, any>)
export type PreactInstance = PreactElement
export type PreactComponent = Preact.VNode
export type PageResolver = (name: string) => PreactComponent | Promise<PreactComponent> | NodeRequire // TODO: When shipped, replace with: Inertia.PageResolver<PreactComponent>
export type HeadManagerOnUpdate = (elements: string[]) => void // TODO: When shipped, replace with: Inertia.HeadManagerOnUpdate
export type HeadManagerTitleCallback = (title: string) => string // TODO: When shipped, replace with: Inertia.HeadManagerTitleCallback
export type AppType<SharedProps = Inertia.PageProps> = Preact.FunctionComponent<
{
children?: (props: {
Component: Preact.ComponentType
key: Preact.Key
props: Inertia.Page<SharedProps>['props']
}) => PreactComponent
} & SetupOptions<unknown, SharedProps>['props']
>
interface BaseInertiaLinkProps {
as?: string
data?: object
href: string
method?: string
headers?: object
onClick?: (event: Event) => void
preserveScroll?: boolean | ((props: Inertia.PageProps) => boolean)
preserveState?: boolean | ((props: Inertia.PageProps) => boolean) | null
replace?: boolean
only?: string[]
onCancelToken?: (cancelToken: import('axios').CancelTokenSource) => void
onBefore?: () => void
onStart?: () => void
onProgress?: (progress: Inertia.Progress) => void
onFinish?: () => void
onCancel?: () => void
onSuccess?: () => void
}
type InertiaLinkProps = BaseInertiaLinkProps &
Omit<JSXInternal.HTMLAttributes<HTMLElement>, keyof BaseInertiaLinkProps> &
Omit<JSXInternal.HTMLAttributes<HTMLElement>, keyof BaseInertiaLinkProps>
type InertiaLink = Preact.FunctionComponent<InertiaLinkProps>
type InertiaHeadProps = {
title?: string
}
type InertiaHead = Preact.FunctionComponent<InertiaHeadProps>
export function usePage<Page extends Inertia.Page = Inertia.Page>(): Page
export function useRemember<State>(initialState: State, key?: string): [State]
export const InertiaLink: InertiaLink
export const Link: InertiaLink
export const InertiaHead: InertiaHead
export const Head: InertiaHead
export const InertiaApp: AppType
export const App: AppType
type setDataByObject<TForm> = (data: TForm) => void
type setDataByMethod<TForm> = (data: (previousData: TForm) => TForm) => void
type setDataByKeyValuePair<TForm> = <K extends keyof TForm>(key: K, value: TForm[K]) => void
export interface InertiaFormProps<TForm = Record<string, any>> {
data: TForm
isDirty: boolean
errors: Record<keyof TForm, string>
hasErrors: boolean
processing: boolean
progress: Inertia.Progress | null
wasSuccessful: boolean
recentlySuccessful: boolean
setData: setDataByObject<TForm> & setDataByMethod<TForm> & setDataByKeyValuePair<TForm>
transform: (callback: (data: TForm) => TForm) => void
setDefaults(): void
setDefaults(field: keyof TForm, value: string): void
setDefaults(fields: Record<keyof TForm, string>): void
reset: (...fields: (keyof TForm)[]) => void
clearErrors: (...fields: (keyof TForm)[]) => void
setError(field: keyof TForm, value: string): void
setError(errors: Record<keyof TForm, string>): void
submit: (method: Inertia.Method, url: string, options?: Inertia.VisitOptions) => void
get: (url: string, options?: Inertia.VisitOptions) => void
patch: (url: string, options?: Inertia.VisitOptions) => void
post: (url: string, options?: Inertia.VisitOptions) => void
put: (url: string, options?: Inertia.VisitOptions) => void
delete: (url: string, options?: Inertia.VisitOptions) => void
}
export function useForm<TForm = Record<string, any>>(initialValues?: TForm): InertiaFormProps<TForm>
export function useForm<TForm = Record<string, any>>(
rememberKey: string,
initialValues?: TForm,
): InertiaFormProps<TForm>
export type SetupOptions<ElementType, SharedProps> = {
el: ElementType
App: AppType
props: {
initialPage: Inertia.Page<SharedProps>
initialComponent: PreactComponent
resolveComponent: PageResolver
titleCallback?: HeadManagerTitleCallback
onHeadUpdate?: HeadManagerOnUpdate
}
}
export type BaseInertiaAppOptions = {
title?: HeadManagerTitleCallback
resolve: PageResolver
}
export type CreateInertiaAppSetupReturnType = PreactInstance | void
export type InertiaAppOptionsForCSR<SharedProps> = BaseInertiaAppOptions & {
id?: string
page?: Inertia.Page | string
progress?: Parameters<typeof Inertia.setupProgress>[0] | boolean
render?: undefined
setup(options: SetupOptions<HTMLElement, SharedProps>): CreateInertiaAppSetupReturnType
}
export type CreateInertiaAppSSRContent = { head: string[]; body: string }
export type InertiaAppOptionsForSSR<SharedProps> = BaseInertiaAppOptions & {
id?: undefined
page: Inertia.Page | string
render: typeof renderToString
setup(options: SetupOptions<null, SharedProps>): PreactInstance
}
export function createInertiaApp<SharedProps = Inertia.PageProps>(
options: InertiaAppOptionsForCSR<SharedProps>,
): Promise<CreateInertiaAppSetupReturnType>
export function createInertiaApp<SharedProps = Inertia.PageProps>(
options: InertiaAppOptionsForSSR<SharedProps>,
): Promise<CreateInertiaAppSSRContent>
export declare const router: typeof Inertia.router