@inertiajs/svelte 2.3.9 → 2.3.11
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/components/Form.svelte +4 -0
- package/dist/useForm.d.ts +9 -4
- package/dist/useForm.js +19 -0
- package/package.json +8 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script>import {
|
|
2
2
|
formDataToObject,
|
|
3
|
+
FormComponentResetSymbol,
|
|
3
4
|
resetFormFields,
|
|
4
5
|
mergeDataIntoQueryString,
|
|
5
6
|
isUrlMethodPair,
|
|
@@ -67,6 +68,9 @@ function getUrlAndData(submitter) {
|
|
|
67
68
|
return mergeDataIntoQueryString(_method, _action, getData(submitter), queryStringArrayFormat);
|
|
68
69
|
}
|
|
69
70
|
function updateDirtyState(event) {
|
|
71
|
+
if (event.type === "reset" && event.detail?.[FormComponentResetSymbol]) {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
}
|
|
70
74
|
isDirty = event.type === "reset" ? false : !isEqual(getData(), formDataToObject(defaultData));
|
|
71
75
|
}
|
|
72
76
|
export function submit(submitter) {
|
package/dist/useForm.d.ts
CHANGED
|
@@ -53,8 +53,13 @@ export interface InertiaFormValidationProps<TForm extends object> {
|
|
|
53
53
|
}
|
|
54
54
|
export type InertiaForm<TForm extends object> = InertiaFormProps<TForm> & TForm;
|
|
55
55
|
export type InertiaPrecognitiveForm<TForm extends object> = InertiaForm<TForm> & InertiaFormValidationProps<TForm>;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
type ReservedFormKeys = keyof InertiaFormProps<any>;
|
|
57
|
+
type ValidateFormData<T> = {
|
|
58
|
+
[K in keyof T]: K extends ReservedFormKeys ? ['Error: This field name is reserved by useForm:', K] : T[K];
|
|
59
|
+
};
|
|
60
|
+
export default function useForm<TForm extends FormDataType<TForm>>(method: Method | (() => Method), url: string | (() => string), data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaPrecognitiveFormStore<TForm>;
|
|
61
|
+
export default function useForm<TForm extends FormDataType<TForm>>(urlMethodPair: UrlMethodPair | (() => UrlMethodPair), data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaPrecognitiveFormStore<TForm>;
|
|
62
|
+
export default function useForm<TForm extends FormDataType<TForm>>(rememberKey: string, data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaFormStore<TForm>;
|
|
63
|
+
export default function useForm<TForm extends FormDataType<TForm>>(data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaFormStore<TForm>;
|
|
64
|
+
export default function useForm<TForm extends FormDataType<TForm>>(): InertiaFormStore<TForm>;
|
|
60
65
|
export {};
|
package/dist/useForm.js
CHANGED
|
@@ -3,6 +3,24 @@ import { createValidator, resolveName, toSimpleValidationErrors } from 'laravel-
|
|
|
3
3
|
import { cloneDeep, get, has, isEqual, set } from 'lodash-es';
|
|
4
4
|
import { get as getStore, writable } from 'svelte/store';
|
|
5
5
|
import { config } from '.';
|
|
6
|
+
let reservedFormKeys = null;
|
|
7
|
+
let bootstrapping = false;
|
|
8
|
+
function validateFormDataKeys(data) {
|
|
9
|
+
if (bootstrapping) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (reservedFormKeys === null) {
|
|
13
|
+
bootstrapping = true;
|
|
14
|
+
const store = useForm({});
|
|
15
|
+
reservedFormKeys = new Set(Object.keys(getStore(store)));
|
|
16
|
+
bootstrapping = false;
|
|
17
|
+
}
|
|
18
|
+
const conflicts = Object.keys(data).filter((key) => reservedFormKeys.has(key));
|
|
19
|
+
if (conflicts.length > 0) {
|
|
20
|
+
console.error(`[Inertia] useForm() data contains field(s) that conflict with form properties: ${conflicts.map((k) => `"${k}"`).join(', ')}. ` +
|
|
21
|
+
`These fields will be overwritten by form methods/properties. Please rename these fields.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
6
24
|
export default function useForm(...args) {
|
|
7
25
|
const parsedArgs = UseFormUtils.parseUseFormArguments(...args);
|
|
8
26
|
const { rememberKey, data: initialData } = parsedArgs;
|
|
@@ -12,6 +30,7 @@ export default function useForm(...args) {
|
|
|
12
30
|
? router.restore(rememberKey)
|
|
13
31
|
: null;
|
|
14
32
|
let defaults = cloneDeep(data);
|
|
33
|
+
validateFormDataKeys(defaults);
|
|
15
34
|
let cancelToken = null;
|
|
16
35
|
let recentlySuccessfulTimeoutId = null;
|
|
17
36
|
let transform = (data) => data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inertiajs/svelte",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The Svelte adapter for Inertia.js",
|
|
6
6
|
"contributors": [
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@sveltejs/adapter-auto": "^3.3.1",
|
|
39
|
-
"@sveltejs/kit": "^2.
|
|
40
|
-
"@sveltejs/package": "^2.5.
|
|
39
|
+
"@sveltejs/kit": "^2.49.5",
|
|
40
|
+
"@sveltejs/package": "^2.5.7",
|
|
41
41
|
"@sveltejs/vite-plugin-svelte": "^3.1.2",
|
|
42
42
|
"axios": "^1.13.2",
|
|
43
|
-
"es-check": "^9.
|
|
44
|
-
"publint": "^0.
|
|
43
|
+
"es-check": "^9.5.3",
|
|
44
|
+
"publint": "^0.3.16",
|
|
45
45
|
"svelte": "^4.2.20",
|
|
46
|
-
"svelte-check": "^4.3.
|
|
46
|
+
"svelte-check": "^4.3.5",
|
|
47
47
|
"tslib": "^2.8.1",
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"vite": "^5.4.21"
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@types/lodash-es": "^4.17.12",
|
|
56
56
|
"laravel-precognition": "^1.0.0",
|
|
57
|
-
"lodash-es": "^4.17.
|
|
58
|
-
"@inertiajs/core": "2.3.
|
|
57
|
+
"lodash-es": "^4.17.22",
|
|
58
|
+
"@inertiajs/core": "2.3.11"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "pnpm package && svelte-check --tsconfig ./tsconfig.json && publint",
|