@inertiajs/svelte 2.1.1 → 2.1.2
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.
|
@@ -25,6 +25,10 @@ export let onSuccess = noop;
|
|
|
25
25
|
export let onError = noop;
|
|
26
26
|
export let onSubmitComplete = noop;
|
|
27
27
|
export let disableWhileProcessing = false;
|
|
28
|
+
export let invalidateCacheTags = [];
|
|
29
|
+
export let resetOnError = false;
|
|
30
|
+
export let resetOnSuccess = false;
|
|
31
|
+
export let setDefaultsOnSuccess = false;
|
|
28
32
|
const form = useForm({});
|
|
29
33
|
let formElement;
|
|
30
34
|
let isDirty = false;
|
|
@@ -42,10 +46,21 @@ function updateDirtyState(event) {
|
|
|
42
46
|
}
|
|
43
47
|
export function submit() {
|
|
44
48
|
const [url, _data] = mergeDataIntoQueryString(_method, _action, getData(), queryStringArrayFormat);
|
|
49
|
+
const maybeReset = (resetOption) => {
|
|
50
|
+
if (!resetOption) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (resetOption === true) {
|
|
54
|
+
reset();
|
|
55
|
+
} else if (resetOption.length > 0) {
|
|
56
|
+
reset(...resetOption);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
45
59
|
const submitOptions = {
|
|
46
60
|
headers,
|
|
47
61
|
errorBag,
|
|
48
62
|
showProgress,
|
|
63
|
+
invalidateCacheTags,
|
|
49
64
|
onCancelToken,
|
|
50
65
|
onBefore,
|
|
51
66
|
onStart,
|
|
@@ -62,8 +77,17 @@ export function submit() {
|
|
|
62
77
|
defaults
|
|
63
78
|
});
|
|
64
79
|
}
|
|
80
|
+
maybeReset(resetOnSuccess);
|
|
81
|
+
if (setDefaultsOnSuccess === true) {
|
|
82
|
+
defaults();
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
onError: (...args) => {
|
|
86
|
+
if (onError) {
|
|
87
|
+
onError(...args);
|
|
88
|
+
}
|
|
89
|
+
maybeReset(resetOnError);
|
|
65
90
|
},
|
|
66
|
-
onError,
|
|
67
91
|
...options
|
|
68
92
|
};
|
|
69
93
|
$form.transform(() => transform(_data)).submit(_method, url, submitOptions);
|
|
@@ -3,10 +3,7 @@ import { type Errors, type FormDataConvertible } from '@inertiajs/core';
|
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: {
|
|
5
5
|
[x: string]: any;
|
|
6
|
-
action?: string |
|
|
7
|
-
url: string;
|
|
8
|
-
method: import("@inertiajs/core").Method;
|
|
9
|
-
} | undefined;
|
|
6
|
+
action?: string | import("@inertiajs/core").UrlMethodPair | undefined;
|
|
10
7
|
method?: import("@inertiajs/core").Method | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | undefined;
|
|
11
8
|
headers?: Record<string, string> | undefined;
|
|
12
9
|
queryStringArrayFormat?: "indices" | "brackets" | undefined;
|
|
@@ -26,6 +23,10 @@ declare const __propDef: {
|
|
|
26
23
|
onError?: import("@inertiajs/core").GlobalEventCallback<"error", import("@inertiajs/core").RequestPayload> | undefined;
|
|
27
24
|
onSubmitComplete?: ((props: import("@inertiajs/core").FormComponentonSubmitCompleteArguments) => void) | undefined;
|
|
28
25
|
disableWhileProcessing?: boolean | undefined;
|
|
26
|
+
invalidateCacheTags?: string | string[] | undefined;
|
|
27
|
+
resetOnError?: boolean | string[] | undefined;
|
|
28
|
+
resetOnSuccess?: boolean | string[] | undefined;
|
|
29
|
+
setDefaultsOnSuccess?: boolean | undefined;
|
|
29
30
|
submit?: (() => void) | undefined;
|
|
30
31
|
reset?: ((...fields: string[]) => void) | undefined;
|
|
31
32
|
clearErrors?: ((...fields: string[]) => void) | undefined;
|
|
@@ -13,6 +13,7 @@ export let queryStringArrayFormat = "brackets";
|
|
|
13
13
|
export let async = false;
|
|
14
14
|
export let prefetch = false;
|
|
15
15
|
export let cacheFor = 0;
|
|
16
|
+
export let cacheTags = [];
|
|
16
17
|
$: _method = typeof href === "object" ? href.method : method;
|
|
17
18
|
$: _href = typeof href === "object" ? href.url : href;
|
|
18
19
|
$: asProp = _method !== "get" ? "button" : as.toLowerCase();
|
|
@@ -39,6 +40,7 @@ $: elProps = {
|
|
|
39
40
|
async,
|
|
40
41
|
prefetch,
|
|
41
42
|
cacheFor,
|
|
43
|
+
cacheTags,
|
|
42
44
|
}}
|
|
43
45
|
{...$$restProps}
|
|
44
46
|
{...elProps}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type { CacheForOption, FormDataConvertible, LinkPrefetchOption, Method, PreserveStateOption } from '@inertiajs/core';
|
|
2
|
+
import type { CacheForOption, FormDataConvertible, LinkPrefetchOption, Method, PreserveStateOption, UrlMethodPair } from '@inertiajs/core';
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: {
|
|
5
5
|
[x: string]: any;
|
|
6
|
-
href?: string |
|
|
7
|
-
url: string;
|
|
8
|
-
method: Method;
|
|
9
|
-
} | undefined;
|
|
6
|
+
href?: (string | UrlMethodPair) | undefined;
|
|
10
7
|
as?: keyof HTMLElementTagNameMap | undefined;
|
|
11
8
|
data?: Record<string, FormDataConvertible> | undefined;
|
|
12
9
|
method?: Method | undefined;
|
|
@@ -20,6 +17,7 @@ declare const __propDef: {
|
|
|
20
17
|
async?: boolean | undefined;
|
|
21
18
|
prefetch?: (boolean | LinkPrefetchOption | LinkPrefetchOption[]) | undefined;
|
|
22
19
|
cacheFor?: (CacheForOption | CacheForOption[]) | undefined;
|
|
20
|
+
cacheTags?: string | string[] | undefined;
|
|
23
21
|
};
|
|
24
22
|
events: {
|
|
25
23
|
focus: FocusEvent;
|
package/dist/link.d.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { type GlobalEventsMap, type LinkComponentBaseProps, type
|
|
1
|
+
import { type GlobalEventsMap, type LinkComponentBaseProps, type VisitOptions } from '@inertiajs/core';
|
|
2
2
|
import type { CancelTokenSource } from 'axios';
|
|
3
3
|
import type { ActionReturn } from 'svelte/action';
|
|
4
4
|
interface ActionElement extends HTMLElement {
|
|
5
5
|
href?: string;
|
|
6
6
|
}
|
|
7
|
-
type ActionParameters = Omit<LinkComponentBaseProps, 'onCancelToken'> & Omit<VisitOptions, keyof LinkComponentBaseProps
|
|
8
|
-
href?: string | {
|
|
9
|
-
url: string;
|
|
10
|
-
method: Method;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
7
|
+
type ActionParameters = Omit<LinkComponentBaseProps, 'onCancelToken'> & Omit<VisitOptions, keyof LinkComponentBaseProps>;
|
|
13
8
|
type SelectedEventKeys = 'start' | 'progress' | 'finish' | 'before' | 'cancel' | 'success' | 'error' | 'prefetching' | 'prefetched';
|
|
14
9
|
type SelectedGlobalEventsMap = Pick<GlobalEventsMap, SelectedEventKeys>;
|
|
15
10
|
type ActionAttributes = {
|
package/dist/link.js
CHANGED
|
@@ -4,6 +4,7 @@ function link(node, initialParams = {}) {
|
|
|
4
4
|
let hoverTimeout;
|
|
5
5
|
let prefetchModes = [];
|
|
6
6
|
let cacheForValue;
|
|
7
|
+
let cacheTags = [];
|
|
7
8
|
let method;
|
|
8
9
|
let href;
|
|
9
10
|
let data;
|
|
@@ -39,7 +40,7 @@ function link(node, initialParams = {}) {
|
|
|
39
40
|
}
|
|
40
41
|
},
|
|
41
42
|
};
|
|
42
|
-
function update({ cacheFor = 0, prefetch = false, ...params }) {
|
|
43
|
+
function update({ cacheFor = 0, prefetch = false, cacheTags: cacheTagValues = [], ...params }) {
|
|
43
44
|
prefetchModes = (() => {
|
|
44
45
|
if (prefetch === true) {
|
|
45
46
|
return ['hover'];
|
|
@@ -58,6 +59,7 @@ function link(node, initialParams = {}) {
|
|
|
58
59
|
}
|
|
59
60
|
return 30_000;
|
|
60
61
|
})();
|
|
62
|
+
cacheTags = cacheTagValues;
|
|
61
63
|
method = typeof params.href === 'object' ? params.href.method : (params.method?.toLowerCase() || 'get');
|
|
62
64
|
[href, data] = hrefAndData(method, params);
|
|
63
65
|
if (node.tagName === 'A') {
|
|
@@ -108,7 +110,7 @@ function link(node, initialParams = {}) {
|
|
|
108
110
|
...baseParams,
|
|
109
111
|
onPrefetching: (visit) => dispatchEvent('prefetching', { detail: { visit } }),
|
|
110
112
|
onPrefetched: (response, visit) => dispatchEvent('prefetched', { detail: { response, visit } }),
|
|
111
|
-
}, { cacheFor: cacheForValue });
|
|
113
|
+
}, { cacheFor: cacheForValue, cacheTags });
|
|
112
114
|
}
|
|
113
115
|
function updateNodeAttributes() {
|
|
114
116
|
if (inFlightCount > 0) {
|
package/dist/useForm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ErrorValue, FormDataErrors, FormDataKeys, FormDataType, FormDataValues, Method, Progress, VisitOptions } from '@inertiajs/core';
|
|
1
|
+
import type { ErrorValue, FormDataErrors, FormDataKeys, FormDataType, FormDataValues, Method, Progress, UrlMethodPair, VisitOptions } from '@inertiajs/core';
|
|
2
2
|
import { type Writable } from 'svelte/store';
|
|
3
3
|
type InertiaFormStore<TForm extends object> = Writable<InertiaForm<TForm>> & InertiaForm<TForm>;
|
|
4
4
|
type FormOptions = Omit<VisitOptions, 'data'>;
|
|
@@ -22,10 +22,7 @@ export interface InertiaFormProps<TForm extends object> {
|
|
|
22
22
|
resetAndClearErrors<K extends FormDataKeys<TForm>>(...fields: K[]): this;
|
|
23
23
|
setError<K extends FormDataKeys<TForm>>(field: K, value: ErrorValue): this;
|
|
24
24
|
setError(errors: FormDataErrors<TForm>): this;
|
|
25
|
-
submit: (...args: [Method, string, FormOptions?] | [
|
|
26
|
-
url: string;
|
|
27
|
-
method: Method;
|
|
28
|
-
}, FormOptions?]) => void;
|
|
25
|
+
submit: (...args: [Method, string, FormOptions?] | [UrlMethodPair, FormOptions?]) => void;
|
|
29
26
|
get(url: string, options?: FormOptions): void;
|
|
30
27
|
post(url: string, options?: FormOptions): void;
|
|
31
28
|
put(url: string, options?: FormOptions): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inertiajs/svelte",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The Svelte adapter for Inertia.js",
|
|
6
6
|
"contributors": [
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"es-toolkit": "^1.33.0",
|
|
39
39
|
"html-escape": "^2.0.0",
|
|
40
|
-
"@inertiajs/core": "2.1.
|
|
40
|
+
"@inertiajs/core": "2.1.2"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@sveltejs/adapter-auto": "^3.2.0",
|