@inertiajs/svelte 2.3.1 → 2.3.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/App.svelte +5 -1
- 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/index.d.ts +1 -1
- package/package.json +2 -2
|
@@ -9,7 +9,7 @@ export let initialPage;
|
|
|
9
9
|
export let resolveComponent;
|
|
10
10
|
let component = initialComponent;
|
|
11
11
|
let key = null;
|
|
12
|
-
let page = initialPage;
|
|
12
|
+
let page = { ...initialPage, flash: initialPage.flash ?? {} };
|
|
13
13
|
let renderProps = resolveRenderProps(component, page, key);
|
|
14
14
|
setPage(page);
|
|
15
15
|
const isServer = typeof window === "undefined";
|
|
@@ -23,6 +23,10 @@ if (!isServer) {
|
|
|
23
23
|
key = args.preserveState ? key : Date.now();
|
|
24
24
|
renderProps = resolveRenderProps(component, page, key);
|
|
25
25
|
setPage(page);
|
|
26
|
+
},
|
|
27
|
+
onFlash: (flash) => {
|
|
28
|
+
page = { ...page, flash };
|
|
29
|
+
setPage(page);
|
|
26
30
|
}
|
|
27
31
|
});
|
|
28
32
|
}
|
|
@@ -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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inertiajs/svelte",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.3",
|
|
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.3"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "pnpm package && svelte-check --tsconfig ./tsconfig.json && publint",
|