@inertiajs/svelte 2.1.2 → 2.1.4
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 +14 -5
- package/dist/components/Link.svelte +4 -3
- package/dist/createInertiaApp.js +2 -2
- package/dist/link.js +15 -3
- package/dist/page.d.ts +7 -2
- package/dist/useForm.js +8 -4
- package/package.json +25 -23
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
<script>import {
|
|
2
2
|
formDataToObject,
|
|
3
3
|
resetFormFields,
|
|
4
|
-
mergeDataIntoQueryString
|
|
4
|
+
mergeDataIntoQueryString,
|
|
5
|
+
isUrlMethodPair
|
|
5
6
|
} from "@inertiajs/core";
|
|
6
|
-
import { isEqual } from "es
|
|
7
|
+
import { isEqual } from "lodash-es";
|
|
7
8
|
import { onMount } from "svelte";
|
|
8
9
|
import useForm from "../useForm";
|
|
9
10
|
const noop = () => void 0;
|
|
@@ -33,8 +34,8 @@ const form = useForm({});
|
|
|
33
34
|
let formElement;
|
|
34
35
|
let isDirty = false;
|
|
35
36
|
let defaultData = new FormData();
|
|
36
|
-
$: _method =
|
|
37
|
-
$: _action =
|
|
37
|
+
$: _method = isUrlMethodPair(action) ? action.method : method.toLowerCase();
|
|
38
|
+
$: _action = isUrlMethodPair(action) ? action.url : action;
|
|
38
39
|
function getFormData() {
|
|
39
40
|
return new FormData(formElement);
|
|
40
41
|
}
|
|
@@ -96,6 +97,12 @@ function handleSubmit(event) {
|
|
|
96
97
|
event.preventDefault();
|
|
97
98
|
submit();
|
|
98
99
|
}
|
|
100
|
+
function handleReset(event) {
|
|
101
|
+
if (event.isTrusted) {
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
reset();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
99
106
|
export function reset(...fields) {
|
|
100
107
|
resetFormFields(formElement, defaultData, fields);
|
|
101
108
|
}
|
|
@@ -132,7 +139,9 @@ $: slotErrors = $form.errors;
|
|
|
132
139
|
bind:this={formElement}
|
|
133
140
|
action={_action}
|
|
134
141
|
method={_method}
|
|
135
|
-
on:submit={handleSubmit}
|
|
142
|
+
on:submit={handleSubmit}
|
|
143
|
+
on:reset={handleReset}
|
|
144
|
+
{...$$restProps}
|
|
136
145
|
inert={disableWhileProcessing && $form.processing ? true : undefined}
|
|
137
146
|
>
|
|
138
147
|
<slot
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { isUrlMethodPair } from "@inertiajs/core";
|
|
2
|
+
import { inertia } from "../index";
|
|
2
3
|
export let href = "";
|
|
3
4
|
export let as = "a";
|
|
4
5
|
export let data = {};
|
|
@@ -14,8 +15,8 @@ export let async = false;
|
|
|
14
15
|
export let prefetch = false;
|
|
15
16
|
export let cacheFor = 0;
|
|
16
17
|
export let cacheTags = [];
|
|
17
|
-
$: _method =
|
|
18
|
-
$: _href =
|
|
18
|
+
$: _method = isUrlMethodPair(href) ? href.method : method;
|
|
19
|
+
$: _href = isUrlMethodPair(href) ? href.url : href;
|
|
19
20
|
$: asProp = _method !== "get" ? "button" : as.toLowerCase();
|
|
20
21
|
$: elProps = {
|
|
21
22
|
a: { href: _href },
|
package/dist/createInertiaApp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { router, setupProgress } from '@inertiajs/core';
|
|
2
|
-
import escape from '
|
|
2
|
+
import { escape } from 'lodash-es';
|
|
3
3
|
import App, {} from './components/App.svelte';
|
|
4
4
|
export default async function createInertiaApp({ id = 'app', resolve, setup, progress = {}, page, }) {
|
|
5
5
|
const isServer = typeof window === 'undefined';
|
|
@@ -14,7 +14,7 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, pro
|
|
|
14
14
|
const svelteApp = setup({
|
|
15
15
|
el,
|
|
16
16
|
App: App,
|
|
17
|
-
props
|
|
17
|
+
props,
|
|
18
18
|
});
|
|
19
19
|
if (isServer) {
|
|
20
20
|
const { html, head, css } = svelteApp;
|
package/dist/link.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mergeDataIntoQueryString, router, shouldIntercept, } from '@inertiajs/core';
|
|
1
|
+
import { isUrlMethodPair, mergeDataIntoQueryString, router, shouldIntercept, shouldNavigate, } from '@inertiajs/core';
|
|
2
2
|
function link(node, initialParams = {}) {
|
|
3
3
|
let inFlightCount = 0;
|
|
4
4
|
let hoverTimeout;
|
|
@@ -30,10 +30,22 @@ function link(node, initialParams = {}) {
|
|
|
30
30
|
prefetch();
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
+
keydown: (event) => {
|
|
34
|
+
if (shouldIntercept(event) && shouldNavigate(event)) {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
prefetch();
|
|
37
|
+
}
|
|
38
|
+
},
|
|
33
39
|
mouseup: (event) => {
|
|
34
40
|
event.preventDefault();
|
|
35
41
|
router.visit(href, visitParams);
|
|
36
42
|
},
|
|
43
|
+
keyup: (event) => {
|
|
44
|
+
if (shouldNavigate(event)) {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
router.visit(href, visitParams);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
37
49
|
click: (event) => {
|
|
38
50
|
if (shouldIntercept(event)) {
|
|
39
51
|
event.preventDefault();
|
|
@@ -60,7 +72,7 @@ function link(node, initialParams = {}) {
|
|
|
60
72
|
return 30_000;
|
|
61
73
|
})();
|
|
62
74
|
cacheTags = cacheTagValues;
|
|
63
|
-
method =
|
|
75
|
+
method = isUrlMethodPair(params.href) ? params.href.method : params.method?.toLowerCase() || 'get';
|
|
64
76
|
[href, data] = hrefAndData(method, params);
|
|
65
77
|
if (node.tagName === 'A') {
|
|
66
78
|
node.href = href;
|
|
@@ -103,7 +115,7 @@ function link(node, initialParams = {}) {
|
|
|
103
115
|
return node.dispatchEvent(new CustomEvent(type, detail));
|
|
104
116
|
}
|
|
105
117
|
function hrefAndData(method, params) {
|
|
106
|
-
return mergeDataIntoQueryString(method,
|
|
118
|
+
return mergeDataIntoQueryString(method, isUrlMethodPair(params.href) ? params.href.url : node.href || params.href || '', params.data || {}, params.queryStringArrayFormat || 'brackets');
|
|
107
119
|
}
|
|
108
120
|
function prefetch() {
|
|
109
121
|
router.prefetch(href, {
|
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.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
|
}
|
|
@@ -82,10 +83,11 @@ export default function useForm(rememberKeyOrData, maybeData) {
|
|
|
82
83
|
return this;
|
|
83
84
|
},
|
|
84
85
|
submit(...args) {
|
|
85
|
-
const objectPassed = typeof args[0] === 'object';
|
|
86
|
+
const objectPassed = args[0] !== null && typeof args[0] === 'object';
|
|
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.4",
|
|
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,13 @@
|
|
|
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.2"
|
|
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
|
-
"
|
|
48
|
-
"
|
|
42
|
+
"axios": "^1.11.0",
|
|
43
|
+
"es-check": "^9.3.1",
|
|
49
44
|
"publint": "^0.2.10",
|
|
50
45
|
"svelte": "^4.2.19",
|
|
51
46
|
"svelte-check": "^4.0.0",
|
|
@@ -53,14 +48,21 @@
|
|
|
53
48
|
"typescript": "^5.5.4",
|
|
54
49
|
"vite": "^5.4.19"
|
|
55
50
|
},
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"svelte": "^4.0.0 || ^5.0.0"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@types/lodash-es": "^4.17.12",
|
|
56
|
+
"lodash-es": "^4.17.21",
|
|
57
|
+
"@inertiajs/core": "2.1.4"
|
|
58
|
+
},
|
|
59
59
|
"scripts": {
|
|
60
|
-
"dev": "pnpm package --watch",
|
|
61
60
|
"build": "pnpm package && publint",
|
|
62
|
-
"
|
|
61
|
+
"build:with-deps": "svelte-kit sync && vite build --config vite-with-deps.config.js",
|
|
63
62
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
64
|
-
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
|
63
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
64
|
+
"dev": "pnpm package --watch",
|
|
65
|
+
"es2020-check": "pnpm build:with-deps && es-check es2020 \"dist/**/*.js\" --checkFeatures --module --noCache --verbose",
|
|
66
|
+
"package": "svelte-kit sync && svelte-package --input src"
|
|
65
67
|
}
|
|
66
68
|
}
|