@formkit/inertia
Version:
FormKit + Inertia = ❤️
58 lines (54 loc) • 3.4 kB
text/typescript
import * as vue from 'vue';
import * as axios from 'axios';
import * as _inertiajs_core from '@inertiajs/core';
import { GlobalEventsMap, RequestPayload, Method, VisitOptions } from '@inertiajs/core';
import { FormKitNode } from '@formkit/core';
type EventCallback = {
[K in keyof Omit<GlobalEventsMap, 'navigate' | 'invalid' | 'exception'>]: (...args: [...GlobalEventsMap[K]['parameters'], ...[node: FormKitNode]]) => K extends 'success' | 'error' ? Promise<GlobalEventsMap[K]['result']> | GlobalEventsMap[K]['result'] : GlobalEventsMap[K]['result'];
} & {
cancelToken: (...args: [{
cancel: () => void;
}, ...[node: FormKitNode]]) => void;
};
declare const createEventManager: () => {
events: Partial<{
before: ((args_0: _inertiajs_core.PendingVisit, node: FormKitNode) => boolean | void)[];
start: ((args_0: _inertiajs_core.PendingVisit, node: FormKitNode) => void)[];
progress: ((args_0: axios.AxiosProgressEvent | undefined, node: FormKitNode) => void)[];
finish: ((args_0: _inertiajs_core.ActiveVisit, node: FormKitNode) => void)[];
cancel: ((node: FormKitNode) => void)[];
success: ((args_0: _inertiajs_core.Page<_inertiajs_core.PageProps>, node: FormKitNode) => void | Promise<void>)[];
error: ((args_0: _inertiajs_core.Errors, node: FormKitNode) => void | Promise<void>)[];
cancelToken: ((args_0: {
cancel: () => void;
}, node: FormKitNode) => void)[];
}>;
on: <T extends "before" | "start" | "progress" | "finish" | "cancel" | "success" | "error" | "cancelToken">(name: T, cb: EventCallback[T]) => void;
run: (name: keyof EventCallback, ...args: any) => Promise<void> | void | boolean;
};
type AddonExtension = (on: ReturnType<typeof createEventManager>['on']) => void;
interface UseFormOptions {
recentlySuccessfulTimeoutTime?: number;
formLevelErrorName?: string;
}
declare const useForm: <F extends RequestPayload>(initialFields?: F | undefined, options?: UseFormOptions) => {
on: <T extends "before" | "start" | "progress" | "finish" | "cancel" | "success" | "error" | "cancelToken">(name: T, cb: EventCallback[T]) => void;
addon: (addons: AddonExtension | AddonExtension[]) => void;
plugin: (node: FormKitNode) => false | undefined;
node: vue.Ref<FormKitNode | null>;
dirty: vue.Ref<boolean | null>;
errors: vue.Ref<boolean | null>;
valid: vue.Ref<boolean | null>;
processing: vue.Ref<boolean>;
progress: vue.Ref<number>;
recentlySuccessful: vue.Ref<boolean>;
wasSuccessful: vue.Ref<boolean>;
submit: (method: Method, url: URL | string, options?: Exclude<VisitOptions, 'method' | 'data'>) => (data: F, node: FormKitNode) => void;
get: (url: URL | string, options?: Exclude<VisitOptions, 'method' | 'data'>) => (data: F, node: FormKitNode) => void;
post: (url: URL | string, options?: Exclude<VisitOptions, 'method' | 'data'>) => (data: F, node: FormKitNode) => void;
put: (url: URL | string, options?: Exclude<VisitOptions, 'method' | 'data'>) => (data: F, node: FormKitNode) => void;
patch: (url: URL | string, options?: Exclude<VisitOptions, 'method' | 'data'>) => (data: F, node: FormKitNode) => void;
delete: (url: URL | string, options?: Exclude<VisitOptions, 'method' | 'data'>) => (data: F, node: FormKitNode) => void;
cancel: () => void;
};
export { AddonExtension, useForm };