@inertiajs/svelte 2.3.0 → 2.3.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.
- package/dist/components/Form.svelte +13 -12
- package/dist/components/Form.svelte.d.ts +9 -9
- package/dist/components/Link.svelte.d.ts +7 -7
- package/dist/components/WhenVisible.svelte +1 -1
- package/dist/components/WhenVisible.svelte.d.ts +3 -1
- package/dist/createInertiaApp.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/useForm.js +1 -1
- package/package.json +2 -2
|
@@ -35,10 +35,10 @@ export let setDefaultsOnSuccess = false;
|
|
|
35
35
|
export let validateFiles = false;
|
|
36
36
|
export let validationTimeout = 1500;
|
|
37
37
|
export let withAllErrors = false;
|
|
38
|
-
|
|
38
|
+
const getTransformedData = () => {
|
|
39
39
|
const [_url, data] = getUrlAndData();
|
|
40
40
|
return transform(data);
|
|
41
|
-
}
|
|
41
|
+
};
|
|
42
42
|
const form = useForm({}).withPrecognition(
|
|
43
43
|
() => _method,
|
|
44
44
|
() => getUrlAndData()[0]
|
|
@@ -55,20 +55,20 @@ let isDirty = false;
|
|
|
55
55
|
let defaultData = new FormData();
|
|
56
56
|
$: _method = isUrlMethodPair(action) ? action.method : (method ?? "get").toLowerCase();
|
|
57
57
|
$: _action = isUrlMethodPair(action) ? action.url : action;
|
|
58
|
-
export function getFormData() {
|
|
59
|
-
return new FormData(formElement);
|
|
58
|
+
export function getFormData(submitter) {
|
|
59
|
+
return new FormData(formElement, submitter);
|
|
60
60
|
}
|
|
61
|
-
export function getData() {
|
|
62
|
-
return formDataToObject(getFormData());
|
|
61
|
+
export function getData(submitter) {
|
|
62
|
+
return formDataToObject(getFormData(submitter));
|
|
63
63
|
}
|
|
64
|
-
function getUrlAndData() {
|
|
65
|
-
return mergeDataIntoQueryString(_method, _action, getData(), queryStringArrayFormat);
|
|
64
|
+
function getUrlAndData(submitter) {
|
|
65
|
+
return mergeDataIntoQueryString(_method, _action, getData(submitter), queryStringArrayFormat);
|
|
66
66
|
}
|
|
67
67
|
function updateDirtyState(event) {
|
|
68
68
|
isDirty = event.type === "reset" ? false : !isEqual(getData(), formDataToObject(defaultData));
|
|
69
69
|
}
|
|
70
|
-
export function submit() {
|
|
71
|
-
const [url,
|
|
70
|
+
export function submit(submitter) {
|
|
71
|
+
const [url, data] = getUrlAndData(submitter);
|
|
72
72
|
const maybeReset = (resetOption) => {
|
|
73
73
|
if (!resetOption) {
|
|
74
74
|
return;
|
|
@@ -114,11 +114,12 @@ export function submit() {
|
|
|
114
114
|
},
|
|
115
115
|
...options
|
|
116
116
|
};
|
|
117
|
-
$form.transform(() => transform(
|
|
117
|
+
$form.transform(() => transform(data)).submit(_method, url, submitOptions);
|
|
118
|
+
$form.transform(getTransformedData);
|
|
118
119
|
}
|
|
119
120
|
function handleSubmit(event) {
|
|
120
121
|
event.preventDefault();
|
|
121
|
-
submit();
|
|
122
|
+
submit(event.submitter);
|
|
122
123
|
}
|
|
123
124
|
function handleReset(event) {
|
|
124
125
|
if (event.isTrusted) {
|
|
@@ -29,9 +29,9 @@ declare const __propDef: {
|
|
|
29
29
|
validateFiles?: boolean | undefined;
|
|
30
30
|
validationTimeout?: number | undefined;
|
|
31
31
|
withAllErrors?: boolean | undefined;
|
|
32
|
-
getFormData?: (() => FormData) | undefined;
|
|
33
|
-
getData?: (() => Record<string, FormDataConvertible>) | undefined;
|
|
34
|
-
submit?: (() => void) | undefined;
|
|
32
|
+
getFormData?: ((submitter?: HTMLElement | null) => FormData) | undefined;
|
|
33
|
+
getData?: ((submitter?: HTMLElement | null) => Record<string, FormDataConvertible>) | undefined;
|
|
34
|
+
submit?: ((submitter?: HTMLElement | null) => void) | undefined;
|
|
35
35
|
reset?: ((...fields: string[]) => void) | undefined;
|
|
36
36
|
clearErrors?: ((...fields: string[]) => void) | undefined;
|
|
37
37
|
resetAndClearErrors?: ((...fields: string[]) => void) | undefined;
|
|
@@ -59,11 +59,11 @@ declare const __propDef: {
|
|
|
59
59
|
resetAndClearErrors: (...fields: string[]) => void;
|
|
60
60
|
setError: (fieldOrFields: string | Record<string, string>, maybeValue?: string) => void;
|
|
61
61
|
isDirty: boolean;
|
|
62
|
-
submit: () => void;
|
|
62
|
+
submit: (submitter?: HTMLElement | null) => void;
|
|
63
63
|
defaults: () => void;
|
|
64
64
|
reset: (...fields: string[]) => void;
|
|
65
|
-
getData: () => Record<string, FormDataConvertible>;
|
|
66
|
-
getFormData: () => FormData;
|
|
65
|
+
getData: (submitter?: HTMLElement | null) => Record<string, FormDataConvertible>;
|
|
66
|
+
getFormData: (submitter?: HTMLElement | null) => FormData;
|
|
67
67
|
validator: () => Validator;
|
|
68
68
|
validate: (field?: string | NamedInputEvent | ValidationConfig, config?: ValidationConfig) => import("svelte/store").Writable<import("../useForm").InertiaPrecognitiveForm<Record<string, any>>> & import("../useForm").InertiaFormProps<Record<string, any>> & Record<string, any> & import("../useForm").InertiaFormValidationProps<Record<string, any>>;
|
|
69
69
|
touch: (field: string | NamedInputEvent | string[], ...fields: string[]) => import("svelte/store").Writable<import("../useForm").InertiaPrecognitiveForm<Record<string, any>>> & import("../useForm").InertiaFormProps<Record<string, any>> & Record<string, any> & import("../useForm").InertiaFormValidationProps<Record<string, any>>;
|
|
@@ -80,9 +80,9 @@ export type FormProps = typeof __propDef.props;
|
|
|
80
80
|
export type FormEvents = typeof __propDef.events;
|
|
81
81
|
export type FormSlots = typeof __propDef.slots;
|
|
82
82
|
export default class Form extends SvelteComponent<FormProps, FormEvents, FormSlots> {
|
|
83
|
-
get getFormData(): () => FormData;
|
|
84
|
-
get getData(): () => Record<string, FormDataConvertible>;
|
|
85
|
-
get submit(): () => void;
|
|
83
|
+
get getFormData(): (submitter?: HTMLElement | null) => FormData;
|
|
84
|
+
get getData(): (submitter?: HTMLElement | null) => Record<string, FormDataConvertible>;
|
|
85
|
+
get submit(): (submitter?: HTMLElement | null) => void;
|
|
86
86
|
get reset(): (...fields: string[]) => void;
|
|
87
87
|
get clearErrors(): (...fields: string[]) => void;
|
|
88
88
|
get resetAndClearErrors(): (...fields: string[]) => void;
|
|
@@ -30,16 +30,16 @@ declare const __propDef: {
|
|
|
30
30
|
mouseout: MouseEvent;
|
|
31
31
|
mouseover: MouseEvent;
|
|
32
32
|
mouseup: MouseEvent;
|
|
33
|
-
'cancel-token': Event | InputEvent | UIEvent | ProgressEvent<EventTarget> |
|
|
34
|
-
before: Event | InputEvent | UIEvent | ProgressEvent<EventTarget> |
|
|
35
|
-
start: Event | InputEvent | UIEvent | ProgressEvent<EventTarget> |
|
|
33
|
+
'cancel-token': Event | InputEvent | UIEvent | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
34
|
+
before: Event | InputEvent | UIEvent | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
35
|
+
start: Event | InputEvent | UIEvent | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
36
36
|
progress: ProgressEvent<EventTarget>;
|
|
37
|
-
finish: Event | InputEvent | UIEvent | ProgressEvent<EventTarget> |
|
|
37
|
+
finish: Event | InputEvent | UIEvent | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
38
38
|
cancel: Event;
|
|
39
|
-
success: Event | InputEvent | UIEvent | ProgressEvent<EventTarget> |
|
|
39
|
+
success: Event | InputEvent | UIEvent | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
40
40
|
error: ErrorEvent;
|
|
41
|
-
prefetching: Event | InputEvent | UIEvent | ProgressEvent<EventTarget> |
|
|
42
|
-
prefetched: Event | InputEvent | UIEvent | ProgressEvent<EventTarget> |
|
|
41
|
+
prefetching: Event | InputEvent | UIEvent | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
42
|
+
prefetched: Event | InputEvent | UIEvent | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
43
43
|
} & {
|
|
44
44
|
[evt: string]: CustomEvent<any>;
|
|
45
45
|
};
|
package/dist/createInertiaApp.js
CHANGED
|
@@ -22,7 +22,7 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, pro
|
|
|
22
22
|
const { html, head, css } = svelteApp;
|
|
23
23
|
return {
|
|
24
24
|
body: useScriptElementForInitialPage
|
|
25
|
-
? `<script data-page="${id}" type="application/json">${JSON.stringify(initialPage)}</script><div data-server-rendered="true" id="${id}">${html}</div>`
|
|
25
|
+
? `<script data-page="${id}" type="application/json">${JSON.stringify(initialPage).replace(/\//g, '\\/')}</script><div data-server-rendered="true" id="${id}">${html}</div>`
|
|
26
26
|
: `<div data-server-rendered="true" id="${id}" data-page="${escape(JSON.stringify(initialPage))}">${html}</div>`,
|
|
27
27
|
head: [head, css ? `<style data-vite-css>${css.code}</style>` : ''],
|
|
28
28
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { default as createInertiaApp } from './createInertiaApp';
|
|
|
9
9
|
export { default as inertia } from './link';
|
|
10
10
|
export { default as page, usePage } from './page';
|
|
11
11
|
export { type ResolvedComponent, type SvelteInertiaAppConfig } from './types';
|
|
12
|
-
export { default as useForm, type InertiaForm, type InertiaFormProps } from './useForm';
|
|
12
|
+
export { default as useForm, type InertiaForm, type InertiaFormProps, type InertiaPrecognitiveForm } from './useForm';
|
|
13
13
|
export { default as usePoll } from './usePoll';
|
|
14
14
|
export { default as usePrefetch } from './usePrefetch';
|
|
15
15
|
export { default as useRemember } from './useRemember';
|
package/dist/useForm.js
CHANGED
|
@@ -26,7 +26,7 @@ export default function useForm(...args) {
|
|
|
26
26
|
const validator = createValidator((client) => {
|
|
27
27
|
const { method, url } = precognitionEndpoint();
|
|
28
28
|
const form = formWithPrecognition();
|
|
29
|
-
const transformedData = transform(form.data());
|
|
29
|
+
const transformedData = cloneDeep(transform(form.data()));
|
|
30
30
|
return client[method](url, transformedData);
|
|
31
31
|
}, cloneDeep(defaults));
|
|
32
32
|
validatorRef = validator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inertiajs/svelte",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The Svelte adapter for Inertia.js",
|
|
6
6
|
"contributors": [
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@types/lodash-es": "^4.17.12",
|
|
56
56
|
"laravel-precognition": "^1.0.0",
|
|
57
57
|
"lodash-es": "^4.17.21",
|
|
58
|
-
"@inertiajs/core": "2.3.
|
|
58
|
+
"@inertiajs/core": "2.3.2"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "pnpm package && svelte-check --tsconfig ./tsconfig.json && publint",
|