@inertiajs/react 2.3.17 → 3.0.0-beta.1
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.
- package/dist/index.js +986 -532
- package/dist/index.js.map +4 -4
- package/dist/server.js +4 -35
- package/dist/server.js.map +2 -2
- package/package.json +9 -11
- package/types/App.d.ts +3 -2
- package/types/Deferred.d.ts +4 -1
- package/types/Form.d.ts +10 -19
- package/types/InfiniteScroll.d.ts +2 -1
- package/types/createInertiaApp.d.ts +15 -4
- package/types/index.d.ts +6 -15
- package/types/layoutProps.d.ts +8 -0
- package/types/react.d.ts +0 -1
- package/types/types.d.ts +3 -1
- package/types/useForm.d.ts +10 -12
- package/types/useFormState.d.ts +79 -0
- package/types/useHttp.d.ts +65 -0
- package/dist/index.esm.js +0 -1651
- package/dist/index.esm.js.map +0 -7
- package/dist/server.esm.js +0 -6
- package/dist/server.esm.js.map +0 -7
package/dist/server.js
CHANGED
|
@@ -1,37 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
1
|
// src/server.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
module.exports = __toCommonJS(server_exports);
|
|
36
|
-
var import_server = __toESM(require("@inertiajs/core/server"), 1);
|
|
2
|
+
import { default as default2 } from "@inertiajs/core/server";
|
|
3
|
+
export {
|
|
4
|
+
default2 as default
|
|
5
|
+
};
|
|
37
6
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/server.ts"],
|
|
4
4
|
"sourcesContent": ["export { default as default } from '@inertiajs/core/server'\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": ";AAAA,SAAoB,WAAXA,gBAA0B;",
|
|
6
|
+
"names": ["default"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inertiajs/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The React adapter for Inertia.js",
|
|
6
6
|
"contributors": [
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"homepage": "https://inertiajs.com/",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/inertiajs/inertia.git",
|
|
13
|
+
"url": "git+https://github.com/inertiajs/inertia.git",
|
|
14
14
|
"directory": "packages/react"
|
|
15
15
|
},
|
|
16
16
|
"bugs": {
|
|
@@ -27,13 +27,11 @@
|
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
29
|
"types": "./types/index.d.ts",
|
|
30
|
-
"import": "./dist/index.
|
|
31
|
-
"require": "./dist/index.js"
|
|
30
|
+
"import": "./dist/index.js"
|
|
32
31
|
},
|
|
33
32
|
"./server": {
|
|
34
33
|
"types": "./types/server.d.ts",
|
|
35
|
-
"import": "./dist/server.
|
|
36
|
-
"require": "./dist/server.js"
|
|
34
|
+
"import": "./dist/server.js"
|
|
37
35
|
}
|
|
38
36
|
},
|
|
39
37
|
"typesVersions": {
|
|
@@ -55,14 +53,14 @@
|
|
|
55
53
|
"typescript": "^5.9.3"
|
|
56
54
|
},
|
|
57
55
|
"peerDependencies": {
|
|
58
|
-
"react": "^
|
|
59
|
-
"react-dom": "^
|
|
56
|
+
"react": "^19.0.0",
|
|
57
|
+
"react-dom": "^19.0.0"
|
|
60
58
|
},
|
|
61
59
|
"dependencies": {
|
|
62
60
|
"@types/lodash-es": "^4.17.12",
|
|
63
|
-
"laravel-precognition": "
|
|
61
|
+
"laravel-precognition": "2.0.0-beta.2",
|
|
64
62
|
"lodash-es": "^4.17.23",
|
|
65
|
-
"@inertiajs/core": "
|
|
63
|
+
"@inertiajs/core": "3.0.0-beta.1"
|
|
66
64
|
},
|
|
67
65
|
"scripts": {
|
|
68
66
|
"build": "pnpm clean && ./build.js && tsc",
|
|
@@ -71,6 +69,6 @@
|
|
|
71
69
|
"dev": "pnpx concurrently -c \"#ffcf00,#3178c6\" \"pnpm dev:build\" \"pnpm dev:types\" --names build,types",
|
|
72
70
|
"dev:build": "./build.js --watch",
|
|
73
71
|
"dev:types": "tsc --watch --preserveWatchOutput",
|
|
74
|
-
"es2020-check": "pnpm build:with-deps && es-check es2020 \"dist/index.
|
|
72
|
+
"es2020-check": "pnpm build:with-deps && es-check es2020 \"dist/index.js\" --checkFeatures --module --noCache --verbose"
|
|
75
73
|
}
|
|
76
74
|
}
|
package/types/App.d.ts
CHANGED
|
@@ -9,12 +9,13 @@ export interface InertiaAppProps<SharedProps extends PageProps = PageProps> {
|
|
|
9
9
|
}) => ReactNode;
|
|
10
10
|
initialPage: Page<SharedProps>;
|
|
11
11
|
initialComponent?: ReactComponent;
|
|
12
|
-
resolveComponent?: (name: string) => ReactComponent | Promise<ReactComponent>;
|
|
12
|
+
resolveComponent?: (name: string, page?: Page) => ReactComponent | Promise<ReactComponent>;
|
|
13
13
|
titleCallback?: HeadManagerTitleCallback;
|
|
14
14
|
onHeadUpdate?: HeadManagerOnUpdateCallback;
|
|
15
|
+
defaultLayout?: (name: string, page: Page) => unknown;
|
|
15
16
|
}
|
|
16
17
|
export type InertiaApp = FunctionComponent<InertiaAppProps>;
|
|
17
|
-
declare function App<SharedProps extends PageProps = PageProps>({ children, initialPage, initialComponent, resolveComponent, titleCallback, onHeadUpdate, }: InertiaAppProps<SharedProps>): import("react").FunctionComponentElement<import("react").ProviderProps<import("@inertiajs/core").HeadManager | null>>;
|
|
18
|
+
declare function App<SharedProps extends PageProps = PageProps>({ children, initialPage, initialComponent, resolveComponent, titleCallback, onHeadUpdate, defaultLayout, }: InertiaAppProps<SharedProps>): import("react").FunctionComponentElement<import("react").ProviderProps<import("@inertiajs/core").HeadManager | null>>;
|
|
18
19
|
declare namespace App {
|
|
19
20
|
var displayName: string;
|
|
20
21
|
}
|
package/types/Deferred.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
+
interface DeferredSlotProps {
|
|
3
|
+
reloading: boolean;
|
|
4
|
+
}
|
|
2
5
|
interface DeferredProps {
|
|
3
|
-
children: ReactNode | (() => ReactNode);
|
|
6
|
+
children: ReactNode | ((props: DeferredSlotProps) => ReactNode);
|
|
4
7
|
fallback: ReactNode | (() => ReactNode);
|
|
5
8
|
data: string | string[];
|
|
6
9
|
}
|
package/types/Form.d.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import { FormComponentRef, FormComponentSlotProps
|
|
1
|
+
import { FormComponentProps, FormComponentRef, FormComponentSlotProps } from '@inertiajs/core';
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
setDefaultsOnSuccess?: boolean;
|
|
13
|
-
validateFiles?: boolean;
|
|
14
|
-
validationTimeout?: number;
|
|
15
|
-
withAllErrors?: boolean | null;
|
|
16
|
-
} & Omit<React.FormHTMLAttributes<HTMLFormElement>, "children" | "method" | "headers" | "errorBag" | "queryStringArrayFormat" | "showProgress" | "invalidateCacheTags" | "onCancelToken" | "onBefore" | "onBeforeUpdate" | "onStart" | "onProgress" | "onFinish" | "onCancel" | "onSuccess" | "onError" | "onFlash" | "withAllErrors" | "options" | "action" | "transform" | "onSubmitComplete" | "disableWhileProcessing" | "resetOnSuccess" | "resetOnError" | "setDefaultsOnSuccess" | "validateFiles" | "validationTimeout"> & Omit<React.AllHTMLAttributes<HTMLFormElement>, "children" | "method" | "headers" | "errorBag" | "queryStringArrayFormat" | "showProgress" | "invalidateCacheTags" | "onCancelToken" | "onBefore" | "onBeforeUpdate" | "onStart" | "onProgress" | "onFinish" | "onCancel" | "onSuccess" | "onError" | "onFlash" | "withAllErrors" | "options" | "action" | "transform" | "onSubmitComplete" | "disableWhileProcessing" | "resetOnSuccess" | "resetOnError" | "setDefaultsOnSuccess" | "validateFiles" | "validationTimeout"> & {
|
|
17
|
-
children: ReactNode | ((props: FormComponentSlotProps) => ReactNode);
|
|
18
|
-
} & React.RefAttributes<FormComponentSlotProps>>;
|
|
19
|
-
export declare function useFormContext(): FormComponentRef | undefined;
|
|
20
|
-
export default Form;
|
|
3
|
+
type FormProps<TForm extends object = Record<string, any>> = FormComponentProps & Omit<React.FormHTMLAttributes<HTMLFormElement>, keyof FormComponentProps | 'children'> & Omit<React.AllHTMLAttributes<HTMLFormElement>, keyof FormComponentProps | 'children'> & {
|
|
4
|
+
children: ReactNode | ((props: FormComponentSlotProps<TForm>) => ReactNode);
|
|
5
|
+
};
|
|
6
|
+
export declare function useFormContext<TForm extends object = Record<string, any>>(): FormComponentRef<TForm> | undefined;
|
|
7
|
+
declare const _default: {
|
|
8
|
+
<TForm extends object = Record<string, any>>(props: FormProps<TForm> & React.RefAttributes<FormComponentRef<TForm>>): React.ReactElement;
|
|
9
|
+
displayName: string;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InfiniteScrollActionSlotProps, InfiniteScrollComponentBaseProps, InfiniteScrollRef, InfiniteScrollSlotProps } from '@inertiajs/core';
|
|
1
|
+
import { InfiniteScrollActionSlotProps, InfiniteScrollComponentBaseProps, InfiniteScrollRef, InfiniteScrollSlotProps, ReloadOptions } from '@inertiajs/core';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
interface ComponentProps extends InfiniteScrollComponentBaseProps, Omit<React.HTMLAttributes<HTMLElement>, keyof InfiniteScrollComponentBaseProps | 'children'> {
|
|
4
4
|
children?: React.ReactNode | ((props: InfiniteScrollSlotProps) => React.ReactNode);
|
|
@@ -8,6 +8,7 @@ interface ComponentProps extends InfiniteScrollComponentBaseProps, Omit<React.HT
|
|
|
8
8
|
previous?: React.ReactNode | ((props: InfiniteScrollActionSlotProps) => React.ReactNode);
|
|
9
9
|
next?: React.ReactNode | ((props: InfiniteScrollActionSlotProps) => React.ReactNode);
|
|
10
10
|
loading?: React.ReactNode | ((props: InfiniteScrollActionSlotProps) => React.ReactNode);
|
|
11
|
+
params?: ReloadOptions;
|
|
11
12
|
onlyNext?: boolean;
|
|
12
13
|
onlyPrevious?: boolean;
|
|
13
14
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateInertiaAppOptionsForCSR, CreateInertiaAppOptionsForSSR, InertiaAppSSRResponse, PageProps } from '@inertiajs/core';
|
|
1
|
+
import { CreateInertiaAppOptions, CreateInertiaAppOptionsForCSR, CreateInertiaAppOptionsForSSR, InertiaAppSSRResponse, Page, PageProps } from '@inertiajs/core';
|
|
2
2
|
import { ReactElement } from 'react';
|
|
3
3
|
import { renderToString } from 'react-dom/server';
|
|
4
4
|
import { InertiaAppProps, type InertiaApp } from './App';
|
|
@@ -8,13 +8,24 @@ export type SetupOptions<ElementType, SharedProps extends PageProps> = {
|
|
|
8
8
|
App: InertiaApp;
|
|
9
9
|
props: InertiaAppProps<SharedProps>;
|
|
10
10
|
};
|
|
11
|
-
type ComponentResolver = (name: string) => ReactComponent | Promise<ReactComponent> | {
|
|
11
|
+
type ComponentResolver = (name: string, page?: Page) => ReactComponent | Promise<ReactComponent> | {
|
|
12
12
|
default: ReactComponent;
|
|
13
|
-
}
|
|
14
|
-
type InertiaAppOptionsForCSR<SharedProps extends PageProps> = CreateInertiaAppOptionsForCSR<SharedProps, ComponentResolver, SetupOptions<HTMLElement, SharedProps>, void, ReactInertiaAppConfig
|
|
13
|
+
};
|
|
14
|
+
type InertiaAppOptionsForCSR<SharedProps extends PageProps> = CreateInertiaAppOptionsForCSR<SharedProps, ComponentResolver, SetupOptions<HTMLElement, SharedProps>, void, ReactInertiaAppConfig> & {
|
|
15
|
+
strictMode?: undefined;
|
|
16
|
+
};
|
|
15
17
|
type InertiaAppOptionsForSSR<SharedProps extends PageProps> = CreateInertiaAppOptionsForSSR<SharedProps, ComponentResolver, SetupOptions<null, SharedProps>, ReactElement, ReactInertiaAppConfig> & {
|
|
16
18
|
render: typeof renderToString;
|
|
19
|
+
strictMode?: undefined;
|
|
20
|
+
};
|
|
21
|
+
type InertiaAppOptionsAuto<SharedProps extends PageProps> = CreateInertiaAppOptions<ComponentResolver, SetupOptions<HTMLElement | null, SharedProps>, ReactElement | void, ReactInertiaAppConfig> & {
|
|
22
|
+
page?: Page<SharedProps>;
|
|
23
|
+
render?: undefined;
|
|
24
|
+
strictMode?: boolean;
|
|
17
25
|
};
|
|
26
|
+
type RenderToString = (element: ReactElement) => string;
|
|
27
|
+
type RenderFunction<SharedProps extends PageProps> = (page: Page<SharedProps>, renderToString: RenderToString) => Promise<InertiaAppSSRResponse>;
|
|
18
28
|
export default function createInertiaApp<SharedProps extends PageProps = PageProps>(options: InertiaAppOptionsForCSR<SharedProps>): Promise<void>;
|
|
19
29
|
export default function createInertiaApp<SharedProps extends PageProps = PageProps>(options: InertiaAppOptionsForSSR<SharedProps>): Promise<InertiaAppSSRResponse>;
|
|
30
|
+
export default function createInertiaApp<SharedProps extends PageProps = PageProps>(options?: InertiaAppOptionsAuto<SharedProps>): Promise<void | RenderFunction<SharedProps>>;
|
|
20
31
|
export {};
|
package/types/index.d.ts
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
start(): void;
|
|
4
|
-
reveal(force?: boolean): void;
|
|
5
|
-
hide(): void;
|
|
6
|
-
set(status: number): void;
|
|
7
|
-
finish(): void;
|
|
8
|
-
reset(): void;
|
|
9
|
-
remove(): void;
|
|
10
|
-
isStarted(): boolean;
|
|
11
|
-
getStatus(): number | null;
|
|
12
|
-
};
|
|
13
|
-
export declare const router: import("@inertiajs/core").Router;
|
|
1
|
+
import type { ReactInertiaAppConfig } from './types';
|
|
2
|
+
export { http, progress, router } from '@inertiajs/core';
|
|
14
3
|
export { default as App } from './App';
|
|
15
4
|
export { default as createInertiaApp } from './createInertiaApp';
|
|
16
5
|
export { default as Deferred } from './Deferred';
|
|
17
6
|
export { default as Form, useFormContext } from './Form';
|
|
18
7
|
export { default as Head } from './Head';
|
|
19
8
|
export { default as InfiniteScroll } from './InfiniteScroll';
|
|
9
|
+
export { resetLayoutProps, setLayoutProps, setLayoutPropsFor, useLayoutProps } from './layoutProps';
|
|
20
10
|
export { InertiaLinkProps, default as Link } from './Link';
|
|
21
11
|
export { ReactComponent as ResolvedComponent } from './types';
|
|
22
|
-
export { InertiaFormProps, InertiaPrecognitiveFormProps, SetDataAction, SetDataByKeyValuePair, SetDataByMethod, SetDataByObject, default as useForm, } from './useForm';
|
|
12
|
+
export { InertiaForm, InertiaFormProps, InertiaPrecognitiveFormProps, SetDataAction, SetDataByKeyValuePair, SetDataByMethod, SetDataByObject, default as useForm, } from './useForm';
|
|
13
|
+
export { default as useHttp } from './useHttp';
|
|
23
14
|
export { default as usePage } from './usePage';
|
|
24
15
|
export { default as usePoll } from './usePoll';
|
|
25
16
|
export { default as usePrefetch } from './usePrefetch';
|
|
26
17
|
export { default as useRemember } from './useRemember';
|
|
27
18
|
export { default as WhenVisible } from './WhenVisible';
|
|
28
|
-
export declare const config: import("@inertiajs/core").Config<import("@inertiajs/core").InertiaAppConfig>;
|
|
19
|
+
export declare const config: import("@inertiajs/core").Config<import("@inertiajs/core").InertiaAppConfig & ReactInertiaAppConfig>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function setLayoutProps(props: Record<string, unknown>): void;
|
|
2
|
+
export declare function setLayoutPropsFor(name: string, props: Record<string, unknown>): void;
|
|
3
|
+
export declare function resetLayoutProps(): void;
|
|
4
|
+
export declare const LayoutPropsContext: import("react").Context<{
|
|
5
|
+
staticProps: Record<string, unknown>;
|
|
6
|
+
name?: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function useLayoutProps<T extends Record<string, unknown>>(defaults: T): T;
|
package/types/react.d.ts
CHANGED
package/types/types.d.ts
CHANGED
|
@@ -8,4 +8,6 @@ export type ReactComponent = ComponentType<any> & {
|
|
|
8
8
|
layout?: LayoutComponent | LayoutComponent[] | LayoutFunction;
|
|
9
9
|
};
|
|
10
10
|
export type ReactPageHandlerArgs = Parameters<PageHandler<ComponentType>>[0];
|
|
11
|
-
export type ReactInertiaAppConfig = {
|
|
11
|
+
export type ReactInertiaAppConfig = {
|
|
12
|
+
strictMode?: boolean;
|
|
13
|
+
};
|
package/types/useForm.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { ErrorValue, FormDataErrors, FormDataKeys, FormDataType, FormDataValues, Method, Progress, UrlMethodPair, UseFormSubmitArguments, UseFormSubmitOptions, UseFormTransformCallback, UseFormWithPrecognitionArguments } from '@inertiajs/core';
|
|
2
|
-
import { NamedInputEvent, PrecognitionPath, ValidationConfig, Validator } from 'laravel-precognition';
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export type SetDataByKeyValuePair<TForm> = <K extends FormDataKeys<TForm>>(key: K, value: FormDataValues<TForm, K>) => void;
|
|
6
|
-
export type SetDataAction<TForm extends Record<any, any>> = SetDataByObject<TForm> & SetDataByMethod<TForm> & SetDataByKeyValuePair<TForm>;
|
|
1
|
+
import { ErrorValue, FormDataErrors, FormDataKeys, FormDataType, FormDataValues, Method, OptimisticCallback, Progress, UrlMethodPair, UseFormSubmitArguments, UseFormSubmitOptions, UseFormTransformCallback, UseFormWithPrecognitionArguments } from '@inertiajs/core';
|
|
2
|
+
import type { NamedInputEvent, PrecognitionPath, ValidationConfig, Validator } from 'laravel-precognition';
|
|
3
|
+
import { SetDataAction, SetDataByKeyValuePair, SetDataByMethod, SetDataByObject } from './useFormState';
|
|
4
|
+
export { SetDataAction, SetDataByKeyValuePair, SetDataByMethod, SetDataByObject };
|
|
7
5
|
type PrecognitionValidationConfig<TKeys> = ValidationConfig & {
|
|
8
6
|
only?: TKeys[] | Iterable<TKeys> | ArrayLike<TKeys>;
|
|
9
7
|
};
|
|
10
|
-
export interface InertiaFormProps<TForm extends
|
|
8
|
+
export interface InertiaFormProps<TForm extends Record<string, any>> {
|
|
11
9
|
data: TForm;
|
|
12
10
|
isDirty: boolean;
|
|
13
11
|
errors: FormDataErrors<TForm>;
|
|
@@ -32,15 +30,16 @@ export interface InertiaFormProps<TForm extends object> {
|
|
|
32
30
|
};
|
|
33
31
|
submit: (...args: UseFormSubmitArguments) => void;
|
|
34
32
|
get: (url: string, options?: UseFormSubmitOptions) => void;
|
|
35
|
-
patch: (url: string, options?: UseFormSubmitOptions) => void;
|
|
36
33
|
post: (url: string, options?: UseFormSubmitOptions) => void;
|
|
37
34
|
put: (url: string, options?: UseFormSubmitOptions) => void;
|
|
35
|
+
patch: (url: string, options?: UseFormSubmitOptions) => void;
|
|
38
36
|
delete: (url: string, options?: UseFormSubmitOptions) => void;
|
|
39
37
|
cancel: () => void;
|
|
40
38
|
dontRemember: <K extends FormDataKeys<TForm>>(...fields: K[]) => InertiaFormProps<TForm>;
|
|
39
|
+
optimistic: <TProps>(callback: OptimisticCallback<TProps>) => InertiaFormProps<TForm>;
|
|
41
40
|
withPrecognition: (...args: UseFormWithPrecognitionArguments) => InertiaPrecognitiveFormProps<TForm>;
|
|
42
41
|
}
|
|
43
|
-
export interface InertiaFormValidationProps<TForm extends
|
|
42
|
+
export interface InertiaFormValidationProps<TForm extends Record<string, any>> {
|
|
44
43
|
invalid: <K extends FormDataKeys<TForm>>(field: K) => boolean;
|
|
45
44
|
setValidationTimeout: (duration: number) => InertiaPrecognitiveFormProps<TForm>;
|
|
46
45
|
touch: <K extends FormDataKeys<TForm>>(field: K | NamedInputEvent | Array<K>, ...fields: K[]) => InertiaPrecognitiveFormProps<TForm>;
|
|
@@ -55,11 +54,10 @@ export interface InertiaFormValidationProps<TForm extends object> {
|
|
|
55
54
|
setErrors: (errors: FormDataErrors<TForm>) => InertiaPrecognitiveFormProps<TForm>;
|
|
56
55
|
forgetError: <K extends FormDataKeys<TForm> | NamedInputEvent>(field: K) => InertiaPrecognitiveFormProps<TForm>;
|
|
57
56
|
}
|
|
58
|
-
export type InertiaForm<TForm extends
|
|
59
|
-
export type InertiaPrecognitiveFormProps<TForm extends
|
|
57
|
+
export type InertiaForm<TForm extends Record<string, any>> = InertiaFormProps<TForm>;
|
|
58
|
+
export type InertiaPrecognitiveFormProps<TForm extends Record<string, any>> = InertiaFormProps<TForm> & InertiaFormValidationProps<TForm>;
|
|
60
59
|
export default function useForm<TForm extends FormDataType<TForm>>(method: Method | (() => Method), url: string | (() => string), data: TForm | (() => TForm)): InertiaPrecognitiveFormProps<TForm>;
|
|
61
60
|
export default function useForm<TForm extends FormDataType<TForm>>(urlMethodPair: UrlMethodPair | (() => UrlMethodPair), data: TForm | (() => TForm)): InertiaPrecognitiveFormProps<TForm>;
|
|
62
61
|
export default function useForm<TForm extends FormDataType<TForm>>(rememberKey: string, data: TForm | (() => TForm)): InertiaFormProps<TForm>;
|
|
63
62
|
export default function useForm<TForm extends FormDataType<TForm>>(data: TForm | (() => TForm)): InertiaFormProps<TForm>;
|
|
64
63
|
export default function useForm<TForm extends FormDataType<TForm>>(): InertiaFormProps<TForm>;
|
|
65
|
-
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ErrorValue, FormDataErrors, FormDataKeys, FormDataValues, Progress, UrlMethodPair, UseFormTransformCallback, UseFormWithPrecognitionArguments } from '@inertiajs/core';
|
|
2
|
+
import { NamedInputEvent, ValidationConfig, Validator } from 'laravel-precognition';
|
|
3
|
+
export type SetDataByObject<TForm> = (data: Partial<TForm>) => void;
|
|
4
|
+
export type SetDataByMethod<TForm> = (data: (previousData: TForm) => TForm) => void;
|
|
5
|
+
export type SetDataByKeyValuePair<TForm> = <K extends FormDataKeys<TForm>>(key: K, value: FormDataValues<TForm, K>) => void;
|
|
6
|
+
export type SetDataAction<TForm extends Record<any, any>> = SetDataByObject<TForm> & SetDataByMethod<TForm> & SetDataByKeyValuePair<TForm>;
|
|
7
|
+
type PrecognitionValidationConfig<TKeys> = ValidationConfig & {
|
|
8
|
+
only?: TKeys[] | Iterable<TKeys> | ArrayLike<TKeys>;
|
|
9
|
+
};
|
|
10
|
+
export interface FormStateProps<TForm extends object> {
|
|
11
|
+
data: TForm;
|
|
12
|
+
isDirty: boolean;
|
|
13
|
+
errors: FormDataErrors<TForm>;
|
|
14
|
+
hasErrors: boolean;
|
|
15
|
+
processing: boolean;
|
|
16
|
+
progress: Progress | null;
|
|
17
|
+
wasSuccessful: boolean;
|
|
18
|
+
recentlySuccessful: boolean;
|
|
19
|
+
setData: SetDataAction<TForm>;
|
|
20
|
+
transform: (callback: UseFormTransformCallback<TForm>) => void;
|
|
21
|
+
setDefaults: {
|
|
22
|
+
(): void;
|
|
23
|
+
<T extends FormDataKeys<TForm>>(field: T, value: FormDataValues<TForm, T>): void;
|
|
24
|
+
(fields: Partial<TForm>): void;
|
|
25
|
+
};
|
|
26
|
+
reset: <K extends FormDataKeys<TForm>>(...fields: K[]) => void;
|
|
27
|
+
clearErrors: <K extends FormDataKeys<TForm>>(...fields: K[]) => void;
|
|
28
|
+
resetAndClearErrors: <K extends FormDataKeys<TForm>>(...fields: K[]) => void;
|
|
29
|
+
setError: {
|
|
30
|
+
<K extends FormDataKeys<TForm>>(field: K, value: ErrorValue): void;
|
|
31
|
+
(errors: FormDataErrors<TForm>): void;
|
|
32
|
+
};
|
|
33
|
+
withPrecognition: (...args: UseFormWithPrecognitionArguments) => FormStateWithPrecognition<TForm>;
|
|
34
|
+
}
|
|
35
|
+
export interface FormStateValidationProps<TForm extends object> {
|
|
36
|
+
invalid: <K extends FormDataKeys<TForm>>(field: K) => boolean;
|
|
37
|
+
setValidationTimeout: (duration: number) => FormStateWithPrecognition<TForm>;
|
|
38
|
+
touch: <K extends FormDataKeys<TForm>>(field: K | NamedInputEvent | Array<K>, ...fields: K[]) => FormStateWithPrecognition<TForm>;
|
|
39
|
+
touched: <K extends FormDataKeys<TForm>>(field?: K) => boolean;
|
|
40
|
+
valid: <K extends FormDataKeys<TForm>>(field: K) => boolean;
|
|
41
|
+
validate: <K extends FormDataKeys<TForm>>(field?: K | NamedInputEvent | PrecognitionValidationConfig<K>, config?: PrecognitionValidationConfig<K>) => FormStateWithPrecognition<TForm>;
|
|
42
|
+
validateFiles: () => FormStateWithPrecognition<TForm>;
|
|
43
|
+
validating: boolean;
|
|
44
|
+
validator: () => Validator;
|
|
45
|
+
withAllErrors: () => FormStateWithPrecognition<TForm>;
|
|
46
|
+
withoutFileValidation: () => FormStateWithPrecognition<TForm>;
|
|
47
|
+
setErrors: (errors: FormDataErrors<TForm>) => FormStateWithPrecognition<TForm>;
|
|
48
|
+
forgetError: <K extends FormDataKeys<TForm> | NamedInputEvent>(field: K) => FormStateWithPrecognition<TForm>;
|
|
49
|
+
}
|
|
50
|
+
export type FormState<TForm extends object> = FormStateProps<TForm>;
|
|
51
|
+
export type FormStateWithPrecognition<TForm extends object> = FormStateProps<TForm> & FormStateValidationProps<TForm>;
|
|
52
|
+
export interface UseFormStateOptions<TForm extends object> {
|
|
53
|
+
data: TForm | (() => TForm);
|
|
54
|
+
precognitionEndpoint?: (() => UrlMethodPair) | null;
|
|
55
|
+
useDataState?: () => [TForm, React.Dispatch<React.SetStateAction<TForm>>];
|
|
56
|
+
useErrorsState?: () => [FormDataErrors<TForm>, React.Dispatch<React.SetStateAction<FormDataErrors<TForm>>>];
|
|
57
|
+
}
|
|
58
|
+
export interface UseFormStateReturn<TForm extends object> {
|
|
59
|
+
form: FormState<TForm>;
|
|
60
|
+
setDefaultsState: React.Dispatch<React.SetStateAction<TForm>>;
|
|
61
|
+
transformRef: React.MutableRefObject<UseFormTransformCallback<TForm>>;
|
|
62
|
+
precognitionEndpointRef: React.MutableRefObject<(() => UrlMethodPair) | null>;
|
|
63
|
+
dataRef: React.MutableRefObject<TForm>;
|
|
64
|
+
isMounted: React.MutableRefObject<boolean>;
|
|
65
|
+
setProcessing: React.Dispatch<React.SetStateAction<boolean>>;
|
|
66
|
+
setProgress: React.Dispatch<React.SetStateAction<Progress | null>>;
|
|
67
|
+
markAsSuccessful: () => void;
|
|
68
|
+
clearErrors: (...fields: string[]) => void;
|
|
69
|
+
setError: (fieldOrFields: FormDataKeys<TForm> | FormDataErrors<TForm>, maybeValue?: ErrorValue) => void;
|
|
70
|
+
defaultsCalledInOnSuccessRef: React.MutableRefObject<boolean>;
|
|
71
|
+
resetBeforeSubmit: () => void;
|
|
72
|
+
finishProcessing: () => void;
|
|
73
|
+
withAllErrors: {
|
|
74
|
+
enabled: () => boolean;
|
|
75
|
+
enable: () => void;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export default function useFormState<TForm extends object>(options: UseFormStateOptions<TForm>): UseFormStateReturn<TForm>;
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ErrorValue, FormDataErrors, FormDataKeys, FormDataType, FormDataValues, Method, Progress, UrlMethodPair, UseFormTransformCallback, UseFormWithPrecognitionArguments, UseHttpSubmitArguments, UseHttpSubmitOptions } from '@inertiajs/core';
|
|
2
|
+
import { NamedInputEvent, ValidationConfig, Validator } from 'laravel-precognition';
|
|
3
|
+
import { SetDataAction } from './useFormState';
|
|
4
|
+
type PrecognitionValidationConfig<TKeys> = ValidationConfig & {
|
|
5
|
+
only?: TKeys[] | Iterable<TKeys> | ArrayLike<TKeys>;
|
|
6
|
+
};
|
|
7
|
+
export interface UseHttpProps<TForm extends object, TResponse = unknown> {
|
|
8
|
+
data: TForm;
|
|
9
|
+
isDirty: boolean;
|
|
10
|
+
errors: FormDataErrors<TForm>;
|
|
11
|
+
hasErrors: boolean;
|
|
12
|
+
processing: boolean;
|
|
13
|
+
progress: Progress | null;
|
|
14
|
+
wasSuccessful: boolean;
|
|
15
|
+
recentlySuccessful: boolean;
|
|
16
|
+
response: TResponse | null;
|
|
17
|
+
setData: SetDataAction<TForm>;
|
|
18
|
+
transform: (callback: UseFormTransformCallback<TForm>) => void;
|
|
19
|
+
setDefaults: {
|
|
20
|
+
(): void;
|
|
21
|
+
<T extends FormDataKeys<TForm>>(field: T, value: FormDataValues<TForm, T>): void;
|
|
22
|
+
(fields: Partial<TForm>): void;
|
|
23
|
+
};
|
|
24
|
+
reset: <K extends FormDataKeys<TForm>>(...fields: K[]) => void;
|
|
25
|
+
clearErrors: <K extends FormDataKeys<TForm>>(...fields: K[]) => void;
|
|
26
|
+
resetAndClearErrors: <K extends FormDataKeys<TForm>>(...fields: K[]) => void;
|
|
27
|
+
setError: {
|
|
28
|
+
<K extends FormDataKeys<TForm>>(field: K, value: ErrorValue): void;
|
|
29
|
+
(errors: FormDataErrors<TForm>): void;
|
|
30
|
+
};
|
|
31
|
+
submit: (...args: UseHttpSubmitArguments<TResponse, TForm>) => Promise<TResponse>;
|
|
32
|
+
get: (url: string, options?: UseHttpSubmitOptions<TResponse, TForm>) => Promise<TResponse>;
|
|
33
|
+
post: (url: string, options?: UseHttpSubmitOptions<TResponse, TForm>) => Promise<TResponse>;
|
|
34
|
+
put: (url: string, options?: UseHttpSubmitOptions<TResponse, TForm>) => Promise<TResponse>;
|
|
35
|
+
patch: (url: string, options?: UseHttpSubmitOptions<TResponse, TForm>) => Promise<TResponse>;
|
|
36
|
+
delete: (url: string, options?: UseHttpSubmitOptions<TResponse, TForm>) => Promise<TResponse>;
|
|
37
|
+
cancel: () => void;
|
|
38
|
+
dontRemember: <K extends FormDataKeys<TForm>>(...fields: K[]) => UseHttpProps<TForm, TResponse>;
|
|
39
|
+
optimistic: (callback: (currentData: TForm) => Partial<TForm>) => UseHttpProps<TForm, TResponse>;
|
|
40
|
+
withAllErrors: () => UseHttpProps<TForm, TResponse>;
|
|
41
|
+
withPrecognition: (...args: UseFormWithPrecognitionArguments) => UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
42
|
+
}
|
|
43
|
+
export interface UseHttpValidationProps<TForm extends object, TResponse = unknown> {
|
|
44
|
+
invalid: <K extends FormDataKeys<TForm>>(field: K) => boolean;
|
|
45
|
+
setValidationTimeout: (duration: number) => UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
46
|
+
touch: <K extends FormDataKeys<TForm>>(field: K | NamedInputEvent | Array<K>, ...fields: K[]) => UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
47
|
+
touched: <K extends FormDataKeys<TForm>>(field?: K) => boolean;
|
|
48
|
+
valid: <K extends FormDataKeys<TForm>>(field: K) => boolean;
|
|
49
|
+
validate: <K extends FormDataKeys<TForm>>(field?: K | NamedInputEvent | PrecognitionValidationConfig<K>, config?: PrecognitionValidationConfig<K>) => UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
50
|
+
validateFiles: () => UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
51
|
+
validating: boolean;
|
|
52
|
+
validator: () => Validator;
|
|
53
|
+
withAllErrors: () => UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
54
|
+
withoutFileValidation: () => UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
55
|
+
setErrors: (errors: FormDataErrors<TForm>) => UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
56
|
+
forgetError: <K extends FormDataKeys<TForm> | NamedInputEvent>(field: K) => UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
57
|
+
}
|
|
58
|
+
export type UseHttp<TForm extends object, TResponse = unknown> = UseHttpProps<TForm, TResponse>;
|
|
59
|
+
export type UseHttpPrecognitiveProps<TForm extends object, TResponse = unknown> = UseHttpProps<TForm, TResponse> & UseHttpValidationProps<TForm, TResponse>;
|
|
60
|
+
export default function useHttp<TForm extends FormDataType<TForm>, TResponse = unknown>(method: Method | (() => Method), url: string | (() => string), data: TForm | (() => TForm)): UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
61
|
+
export default function useHttp<TForm extends FormDataType<TForm>, TResponse = unknown>(urlMethodPair: UrlMethodPair | (() => UrlMethodPair), data: TForm | (() => TForm)): UseHttpPrecognitiveProps<TForm, TResponse>;
|
|
62
|
+
export default function useHttp<TForm extends FormDataType<TForm>, TResponse = unknown>(rememberKey: string, data: TForm | (() => TForm)): UseHttp<TForm, TResponse>;
|
|
63
|
+
export default function useHttp<TForm extends FormDataType<TForm>, TResponse = unknown>(data: TForm | (() => TForm)): UseHttp<TForm, TResponse>;
|
|
64
|
+
export default function useHttp<TForm extends FormDataType<TForm>, TResponse = unknown>(): UseHttp<TForm, TResponse>;
|
|
65
|
+
export {};
|