@inertiajs/svelte 2.0.6 → 2.0.7
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/useForm.d.ts +7 -7
- package/dist/useForm.js +16 -13
- package/package.json +5 -6
package/dist/useForm.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import type { Errors, FormDataConvertible, Method, Progress, VisitOptions } from '@inertiajs/core';
|
|
1
|
+
import type { Errors, FormDataConvertible, FormDataKeys, Method, Progress, VisitOptions } from '@inertiajs/core';
|
|
2
2
|
import { type Writable } from 'svelte/store';
|
|
3
3
|
type FormDataType = Record<string, FormDataConvertible>;
|
|
4
4
|
type FormOptions = Omit<VisitOptions, 'data'>;
|
|
5
5
|
export interface InertiaFormProps<TForm extends FormDataType> {
|
|
6
6
|
isDirty: boolean;
|
|
7
|
-
errors: Partial<Record<
|
|
7
|
+
errors: Partial<Record<FormDataKeys<TForm>, string>>;
|
|
8
8
|
hasErrors: boolean;
|
|
9
9
|
progress: Progress | null;
|
|
10
10
|
wasSuccessful: boolean;
|
|
11
11
|
recentlySuccessful: boolean;
|
|
12
12
|
processing: boolean;
|
|
13
13
|
setStore(data: TForm): void;
|
|
14
|
-
setStore(key:
|
|
14
|
+
setStore(key: FormDataKeys<TForm>, value?: FormDataConvertible): void;
|
|
15
15
|
data(): TForm;
|
|
16
16
|
transform(callback: (data: TForm) => object): this;
|
|
17
17
|
defaults(): this;
|
|
18
18
|
defaults(fields: Partial<TForm>): this;
|
|
19
|
-
defaults(field?:
|
|
20
|
-
reset(...fields:
|
|
21
|
-
clearErrors(...fields:
|
|
22
|
-
setError(field:
|
|
19
|
+
defaults(field?: FormDataKeys<TForm>, value?: FormDataConvertible): this;
|
|
20
|
+
reset(...fields: FormDataKeys<TForm>[]): this;
|
|
21
|
+
clearErrors(...fields: FormDataKeys<TForm>[]): this;
|
|
22
|
+
setError(field: FormDataKeys<TForm>, value: string): this;
|
|
23
23
|
setError(errors: Errors): this;
|
|
24
24
|
submit: (...args: [Method, string, FormOptions?] | [{
|
|
25
25
|
url: string;
|
package/dist/useForm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { router } from '@inertiajs/core';
|
|
2
|
-
import cloneDeep from '
|
|
3
|
-
import
|
|
2
|
+
import { cloneDeep, isEqual } from 'es-toolkit';
|
|
3
|
+
import { get, has, set } from 'es-toolkit/compat';
|
|
4
4
|
import { writable } from 'svelte/store';
|
|
5
5
|
export default function useForm(rememberKeyOrData, maybeData) {
|
|
6
6
|
const rememberKey = typeof rememberKeyOrData === 'string' ? rememberKeyOrData : null;
|
|
@@ -24,13 +24,12 @@ export default function useForm(rememberKeyOrData, maybeData) {
|
|
|
24
24
|
processing: false,
|
|
25
25
|
setStore(keyOrData, maybeValue = undefined) {
|
|
26
26
|
store.update((store) => {
|
|
27
|
-
return
|
|
27
|
+
return typeof keyOrData === 'string' ? set(store, keyOrData, maybeValue) : Object.assign(store, keyOrData);
|
|
28
28
|
});
|
|
29
29
|
},
|
|
30
30
|
data() {
|
|
31
31
|
return Object.keys(data).reduce((carry, key) => {
|
|
32
|
-
carry
|
|
33
|
-
return carry;
|
|
32
|
+
return set(carry, key, get(this, key));
|
|
34
33
|
}, {});
|
|
35
34
|
},
|
|
36
35
|
transform(callback) {
|
|
@@ -38,10 +37,15 @@ export default function useForm(rememberKeyOrData, maybeData) {
|
|
|
38
37
|
return this;
|
|
39
38
|
},
|
|
40
39
|
defaults(fieldOrFields, maybeValue) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
if (typeof fieldOrFields === 'undefined') {
|
|
41
|
+
defaults = cloneDeep(this.data());
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
defaults =
|
|
45
|
+
typeof fieldOrFields === 'string'
|
|
46
|
+
? set(cloneDeep(defaults), fieldOrFields, maybeValue)
|
|
47
|
+
: Object.assign(cloneDeep(defaults), fieldOrFields);
|
|
48
|
+
}
|
|
45
49
|
return this;
|
|
46
50
|
},
|
|
47
51
|
reset(...fields) {
|
|
@@ -50,11 +54,10 @@ export default function useForm(rememberKeyOrData, maybeData) {
|
|
|
50
54
|
this.setStore(clonedData);
|
|
51
55
|
}
|
|
52
56
|
else {
|
|
53
|
-
this.setStore(
|
|
54
|
-
.filter((key) =>
|
|
57
|
+
this.setStore(fields
|
|
58
|
+
.filter((key) => has(clonedData, key))
|
|
55
59
|
.reduce((carry, key) => {
|
|
56
|
-
carry
|
|
57
|
-
return carry;
|
|
60
|
+
return set(carry, key, get(clonedData, key));
|
|
58
61
|
}, {}));
|
|
59
62
|
}
|
|
60
63
|
return this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inertiajs/svelte",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The Svelte adapter for Inertia.js",
|
|
6
6
|
"contributors": [
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"svelte": "^4.0.0 || ^5.0.0 || ^5.0.0-next.244"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@inertiajs/core": "2.0.
|
|
47
|
-
"
|
|
48
|
-
"
|
|
46
|
+
"@inertiajs/core": "2.0.7",
|
|
47
|
+
"es-toolkit": "^1.33.0",
|
|
48
|
+
"html-escape": "^2.0.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@sveltejs/adapter-auto": "^3.2.0",
|
|
@@ -53,14 +53,13 @@
|
|
|
53
53
|
"@sveltejs/package": "^2.3.4",
|
|
54
54
|
"@sveltejs/vite-plugin-svelte": "^3.1.2",
|
|
55
55
|
"@types/html-escape": "^2.0.2",
|
|
56
|
-
"@types/lodash": "^4.17.7",
|
|
57
56
|
"axios": "^1.8.2",
|
|
58
57
|
"publint": "^0.2.10",
|
|
59
58
|
"svelte": "^4.2.16",
|
|
60
59
|
"svelte-check": "^4.0.0",
|
|
61
60
|
"tslib": "^2.7.0",
|
|
62
61
|
"typescript": "^5.5.4",
|
|
63
|
-
"vite": "^5.4.
|
|
62
|
+
"vite": "^5.4.17"
|
|
64
63
|
},
|
|
65
64
|
"svelte": "./dist/index.js",
|
|
66
65
|
"types": "./dist/index.d.ts",
|