@inertiajs/svelte 2.1.1 → 2.1.3
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 +35 -3
- package/dist/components/Form.svelte.d.ts +5 -4
- package/dist/components/Link.svelte +2 -0
- package/dist/components/Link.svelte.d.ts +3 -5
- package/dist/createInertiaApp.js +1 -1
- package/dist/link.d.ts +2 -7
- package/dist/link.js +17 -3
- package/dist/page.d.ts +7 -2
- package/dist/useForm.d.ts +2 -5
- package/dist/useForm.js +7 -3
- package/package.json +26 -22
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
resetFormFields,
|
|
4
4
|
mergeDataIntoQueryString
|
|
5
5
|
} from "@inertiajs/core";
|
|
6
|
-
import { isEqual } from "es
|
|
6
|
+
import { isEqual } from "lodash-es";
|
|
7
7
|
import { onMount } from "svelte";
|
|
8
8
|
import useForm from "../useForm";
|
|
9
9
|
const noop = () => void 0;
|
|
@@ -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);
|
|
@@ -72,6 +96,12 @@ function handleSubmit(event) {
|
|
|
72
96
|
event.preventDefault();
|
|
73
97
|
submit();
|
|
74
98
|
}
|
|
99
|
+
function handleReset(event) {
|
|
100
|
+
if (event.isTrusted) {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
reset();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
75
105
|
export function reset(...fields) {
|
|
76
106
|
resetFormFields(formElement, defaultData, fields);
|
|
77
107
|
}
|
|
@@ -108,7 +138,9 @@ $: slotErrors = $form.errors;
|
|
|
108
138
|
bind:this={formElement}
|
|
109
139
|
action={_action}
|
|
110
140
|
method={_method}
|
|
111
|
-
on:submit={handleSubmit}
|
|
141
|
+
on:submit={handleSubmit}
|
|
142
|
+
on:reset={handleReset}
|
|
143
|
+
{...$$restProps}
|
|
112
144
|
inert={disableWhileProcessing && $form.processing ? true : undefined}
|
|
113
145
|
>
|
|
114
146
|
<slot
|
|
@@ -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/createInertiaApp.js
CHANGED
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
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { mergeDataIntoQueryString, router, shouldIntercept, } from '@inertiajs/core';
|
|
1
|
+
import { mergeDataIntoQueryString, router, shouldIntercept, shouldNavigate, } from '@inertiajs/core';
|
|
2
2
|
function link(node, initialParams = {}) {
|
|
3
3
|
let inFlightCount = 0;
|
|
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;
|
|
@@ -29,17 +30,29 @@ function link(node, initialParams = {}) {
|
|
|
29
30
|
prefetch();
|
|
30
31
|
}
|
|
31
32
|
},
|
|
33
|
+
keydown: (event) => {
|
|
34
|
+
if (shouldIntercept(event) && shouldNavigate(event)) {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
prefetch();
|
|
37
|
+
}
|
|
38
|
+
},
|
|
32
39
|
mouseup: (event) => {
|
|
33
40
|
event.preventDefault();
|
|
34
41
|
router.visit(href, visitParams);
|
|
35
42
|
},
|
|
43
|
+
keyup: (event) => {
|
|
44
|
+
if (shouldNavigate(event)) {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
router.visit(href, visitParams);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
36
49
|
click: (event) => {
|
|
37
50
|
if (shouldIntercept(event)) {
|
|
38
51
|
event.preventDefault();
|
|
39
52
|
}
|
|
40
53
|
},
|
|
41
54
|
};
|
|
42
|
-
function update({ cacheFor = 0, prefetch = false, ...params }) {
|
|
55
|
+
function update({ cacheFor = 0, prefetch = false, cacheTags: cacheTagValues = [], ...params }) {
|
|
43
56
|
prefetchModes = (() => {
|
|
44
57
|
if (prefetch === true) {
|
|
45
58
|
return ['hover'];
|
|
@@ -58,6 +71,7 @@ function link(node, initialParams = {}) {
|
|
|
58
71
|
}
|
|
59
72
|
return 30_000;
|
|
60
73
|
})();
|
|
74
|
+
cacheTags = cacheTagValues;
|
|
61
75
|
method = typeof params.href === 'object' ? params.href.method : (params.method?.toLowerCase() || 'get');
|
|
62
76
|
[href, data] = hrefAndData(method, params);
|
|
63
77
|
if (node.tagName === 'A') {
|
|
@@ -108,7 +122,7 @@ function link(node, initialParams = {}) {
|
|
|
108
122
|
...baseParams,
|
|
109
123
|
onPrefetching: (visit) => dispatchEvent('prefetching', { detail: { visit } }),
|
|
110
124
|
onPrefetched: (response, visit) => dispatchEvent('prefetched', { detail: { response, visit } }),
|
|
111
|
-
}, { cacheFor: cacheForValue });
|
|
125
|
+
}, { cacheFor: cacheForValue, cacheTags });
|
|
112
126
|
}
|
|
113
127
|
function updateNodeAttributes() {
|
|
114
128
|
if (inFlightCount > 0) {
|
package/dist/page.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { type Page } from '@inertiajs/core';
|
|
2
|
-
|
|
2
|
+
type SveltePage = Omit<Page, 'props'> & {
|
|
3
|
+
props: Page['props'] & {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export declare const setPage: (this: void, value: SveltePage) => void;
|
|
3
8
|
declare const _default: {
|
|
4
|
-
subscribe: (this: void, run: import("svelte/store").Subscriber<
|
|
9
|
+
subscribe: (this: void, run: import("svelte/store").Subscriber<SveltePage>, invalidate?: import("svelte/store").Invalidator<SveltePage> | undefined) => import("svelte/store").Unsubscriber;
|
|
5
10
|
};
|
|
6
11
|
export default _default;
|
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/dist/useForm.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { router } from '@inertiajs/core';
|
|
2
|
-
import { cloneDeep, isEqual } from 'es
|
|
3
|
-
import { get, has, set } from 'es-toolkit/compat';
|
|
2
|
+
import { cloneDeep, get, has, isEqual, set } from 'lodash-es';
|
|
4
3
|
import { writable } from 'svelte/store';
|
|
5
4
|
export default function useForm(rememberKeyOrData, maybeData) {
|
|
6
5
|
const rememberKey = typeof rememberKeyOrData === 'string' ? rememberKeyOrData : null;
|
|
@@ -13,6 +12,7 @@ export default function useForm(rememberKeyOrData, maybeData) {
|
|
|
13
12
|
let cancelToken = null;
|
|
14
13
|
let recentlySuccessfulTimeoutId = null;
|
|
15
14
|
let transform = (data) => data;
|
|
15
|
+
let defaultsCalledInOnSuccess = false;
|
|
16
16
|
const store = writable({
|
|
17
17
|
...(restored ? restored.data : data),
|
|
18
18
|
isDirty: false,
|
|
@@ -37,6 +37,7 @@ export default function useForm(rememberKeyOrData, maybeData) {
|
|
|
37
37
|
return this;
|
|
38
38
|
},
|
|
39
39
|
defaults(fieldOrFields, maybeValue) {
|
|
40
|
+
defaultsCalledInOnSuccess = true;
|
|
40
41
|
if (typeof fieldOrFields === 'undefined') {
|
|
41
42
|
defaults = cloneDeep(this.data());
|
|
42
43
|
}
|
|
@@ -86,6 +87,7 @@ export default function useForm(rememberKeyOrData, maybeData) {
|
|
|
86
87
|
const method = objectPassed ? args[0].method : args[0];
|
|
87
88
|
const url = objectPassed ? args[0].url : args[1];
|
|
88
89
|
const options = (objectPassed ? args[1] : args[2]) ?? {};
|
|
90
|
+
defaultsCalledInOnSuccess = false;
|
|
89
91
|
const data = transform(this.data());
|
|
90
92
|
const _options = {
|
|
91
93
|
...options,
|
|
@@ -125,7 +127,9 @@ export default function useForm(rememberKeyOrData, maybeData) {
|
|
|
125
127
|
this.setStore('recentlySuccessful', true);
|
|
126
128
|
recentlySuccessfulTimeoutId = setTimeout(() => this.setStore('recentlySuccessful', false), 2000);
|
|
127
129
|
const onSuccess = options.onSuccess ? await options.onSuccess(page) : null;
|
|
128
|
-
|
|
130
|
+
if (!defaultsCalledInOnSuccess) {
|
|
131
|
+
this.defaults(cloneDeep(this.data()));
|
|
132
|
+
}
|
|
129
133
|
return onSuccess;
|
|
130
134
|
},
|
|
131
135
|
onError: (errors) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inertiajs/svelte",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The Svelte adapter for Inertia.js",
|
|
6
6
|
"contributors": [
|
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/inertiajs/inertia/issues"
|
|
18
18
|
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"!dist/**/*.test.*",
|
|
22
|
+
"!dist/**/*.spec.*"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"svelte": "./dist/index.js",
|
|
19
27
|
"exports": {
|
|
20
28
|
".": {
|
|
21
29
|
"types": "./dist/index.d.ts",
|
|
@@ -26,26 +34,14 @@
|
|
|
26
34
|
"svelte": "./dist/server.js"
|
|
27
35
|
}
|
|
28
36
|
},
|
|
29
|
-
"files": [
|
|
30
|
-
"dist",
|
|
31
|
-
"!dist/**/*.test.*",
|
|
32
|
-
"!dist/**/*.spec.*"
|
|
33
|
-
],
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"svelte": "^4.0.0 || ^5.0.0 || ^5.0.0-next.244"
|
|
36
|
-
},
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"es-toolkit": "^1.33.0",
|
|
39
|
-
"html-escape": "^2.0.0",
|
|
40
|
-
"@inertiajs/core": "2.1.1"
|
|
41
|
-
},
|
|
42
37
|
"devDependencies": {
|
|
43
38
|
"@sveltejs/adapter-auto": "^3.2.0",
|
|
44
|
-
"@sveltejs/kit": "^2.
|
|
39
|
+
"@sveltejs/kit": "^2.36.3",
|
|
45
40
|
"@sveltejs/package": "^2.3.4",
|
|
46
41
|
"@sveltejs/vite-plugin-svelte": "^3.1.2",
|
|
47
42
|
"@types/html-escape": "^2.0.2",
|
|
48
|
-
"axios": "^1.
|
|
43
|
+
"axios": "^1.11.0",
|
|
44
|
+
"es-check": "^9.3.1",
|
|
49
45
|
"publint": "^0.2.10",
|
|
50
46
|
"svelte": "^4.2.19",
|
|
51
47
|
"svelte-check": "^4.0.0",
|
|
@@ -53,14 +49,22 @@
|
|
|
53
49
|
"typescript": "^5.5.4",
|
|
54
50
|
"vite": "^5.4.19"
|
|
55
51
|
},
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"svelte": "^4.0.0 || ^5.0.0"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@types/lodash-es": "^4.17.12",
|
|
57
|
+
"html-escape": "^2.0.0",
|
|
58
|
+
"lodash-es": "^4.17.21",
|
|
59
|
+
"@inertiajs/core": "2.1.3"
|
|
60
|
+
},
|
|
59
61
|
"scripts": {
|
|
60
|
-
"dev": "pnpm package --watch",
|
|
61
62
|
"build": "pnpm package && publint",
|
|
62
|
-
"
|
|
63
|
+
"build:with-deps": "svelte-kit sync && vite build --config vite-with-deps.config.js",
|
|
63
64
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
64
|
-
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
|
65
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
66
|
+
"dev": "pnpm package --watch",
|
|
67
|
+
"es2020-check": "pnpm build:with-deps && es-check es2020 \"dist/**/*.js\" --checkFeatures --module --noCache --verbose",
|
|
68
|
+
"package": "svelte-kit sync && svelte-package --input src"
|
|
65
69
|
}
|
|
66
70
|
}
|