@inertiajs/svelte 2.3.10 → 2.3.12

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.
@@ -1,19 +1,7 @@
1
1
  <script>import { page } from "../index";
2
- import { onDestroy } from "svelte";
3
2
  export let data;
4
3
  const keys = Array.isArray(data) ? data : [data];
5
- let loaded = false;
6
- const isServer = typeof window === "undefined";
7
- if (!isServer) {
8
- const unsubscribe = page.subscribe(({ props }) => {
9
- window.queueMicrotask(() => {
10
- loaded = keys.every((key) => typeof props[key] !== "undefined");
11
- });
12
- });
13
- onDestroy(() => {
14
- unsubscribe();
15
- });
16
- }
4
+ $: loaded = keys.every((key) => typeof $page.props[key] !== "undefined");
17
5
  if (!$$slots.fallback) {
18
6
  throw new Error('`<Deferred>` requires a `<svelte:fragment slot="fallback">` slot');
19
7
  }
@@ -75,6 +75,11 @@ function updateDirtyState(event) {
75
75
  }
76
76
  export function submit(submitter) {
77
77
  const [url, data] = getUrlAndData(submitter);
78
+ const formTarget = submitter?.getAttribute("formtarget");
79
+ if (formTarget === "_blank" && _method === "get") {
80
+ window.open(url, "_blank");
81
+ return;
82
+ }
78
83
  const maybeReset = (resetOption) => {
79
84
  if (!resetOption) {
80
85
  return;
@@ -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 | 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;
33
+ 'cancel-token': InputEvent | UIEvent | Event | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
34
+ before: InputEvent | UIEvent | Event | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
35
+ start: InputEvent | UIEvent | Event | 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 | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
37
+ finish: InputEvent | UIEvent | Event | 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 | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
39
+ success: InputEvent | UIEvent | Event | 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 | 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;
41
+ prefetching: InputEvent | UIEvent | Event | SubmitEvent | ProgressEvent<EventTarget> | ErrorEvent | FormDataEvent | AnimationEvent | PointerEvent | MouseEvent | ToggleEvent | FocusEvent | CompositionEvent | ClipboardEvent | DragEvent | KeyboardEvent | SecurityPolicyViolationEvent | TouchEvent | TransitionEvent | WheelEvent;
42
+ prefetched: InputEvent | UIEvent | Event | 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/useForm.d.ts CHANGED
@@ -53,8 +53,13 @@ export interface InertiaFormValidationProps<TForm extends object> {
53
53
  }
54
54
  export type InertiaForm<TForm extends object> = InertiaFormProps<TForm> & TForm;
55
55
  export type InertiaPrecognitiveForm<TForm extends object> = InertiaForm<TForm> & InertiaFormValidationProps<TForm>;
56
- export default function useForm<TForm extends FormDataType<TForm>>(method: Method | (() => Method), url: string | (() => string), data: TForm | (() => TForm)): InertiaPrecognitiveFormStore<TForm>;
57
- export default function useForm<TForm extends FormDataType<TForm>>(urlMethodPair: UrlMethodPair | (() => UrlMethodPair), data: TForm | (() => TForm)): InertiaPrecognitiveFormStore<TForm>;
58
- export default function useForm<TForm extends FormDataType<TForm>>(rememberKey: string, data: TForm | (() => TForm)): InertiaFormStore<TForm>;
59
- export default function useForm<TForm extends FormDataType<TForm>>(data: TForm | (() => TForm)): InertiaFormStore<TForm>;
56
+ type ReservedFormKeys = keyof InertiaFormProps<any>;
57
+ type ValidateFormData<T> = {
58
+ [K in keyof T]: K extends ReservedFormKeys ? ['Error: This field name is reserved by useForm:', K] : T[K];
59
+ };
60
+ export default function useForm<TForm extends FormDataType<TForm>>(method: Method | (() => Method), url: string | (() => string), data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaPrecognitiveFormStore<TForm>;
61
+ export default function useForm<TForm extends FormDataType<TForm>>(urlMethodPair: UrlMethodPair | (() => UrlMethodPair), data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaPrecognitiveFormStore<TForm>;
62
+ export default function useForm<TForm extends FormDataType<TForm>>(rememberKey: string, data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaFormStore<TForm>;
63
+ export default function useForm<TForm extends FormDataType<TForm>>(data: ValidateFormData<TForm> | (() => ValidateFormData<TForm>)): InertiaFormStore<TForm>;
64
+ export default function useForm<TForm extends FormDataType<TForm>>(): InertiaFormStore<TForm>;
60
65
  export {};
package/dist/useForm.js CHANGED
@@ -3,6 +3,24 @@ import { createValidator, resolveName, toSimpleValidationErrors } from 'laravel-
3
3
  import { cloneDeep, get, has, isEqual, set } from 'lodash-es';
4
4
  import { get as getStore, writable } from 'svelte/store';
5
5
  import { config } from '.';
6
+ let reservedFormKeys = null;
7
+ let bootstrapping = false;
8
+ function validateFormDataKeys(data) {
9
+ if (bootstrapping) {
10
+ return;
11
+ }
12
+ if (reservedFormKeys === null) {
13
+ bootstrapping = true;
14
+ const store = useForm({});
15
+ reservedFormKeys = new Set(Object.keys(getStore(store)));
16
+ bootstrapping = false;
17
+ }
18
+ const conflicts = Object.keys(data).filter((key) => reservedFormKeys.has(key));
19
+ if (conflicts.length > 0) {
20
+ console.error(`[Inertia] useForm() data contains field(s) that conflict with form properties: ${conflicts.map((k) => `"${k}"`).join(', ')}. ` +
21
+ `These fields will be overwritten by form methods/properties. Please rename these fields.`);
22
+ }
23
+ }
6
24
  export default function useForm(...args) {
7
25
  const parsedArgs = UseFormUtils.parseUseFormArguments(...args);
8
26
  const { rememberKey, data: initialData } = parsedArgs;
@@ -12,6 +30,7 @@ export default function useForm(...args) {
12
30
  ? router.restore(rememberKey)
13
31
  : null;
14
32
  let defaults = cloneDeep(data);
33
+ validateFormDataKeys(defaults);
15
34
  let cancelToken = null;
16
35
  let recentlySuccessfulTimeoutId = null;
17
36
  let transform = (data) => data;
@@ -244,7 +263,8 @@ export default function useForm(...args) {
244
263
  onError: (errors) => {
245
264
  setFormState('processing', false);
246
265
  setFormState('progress', null);
247
- this.clearErrors().setError(errors);
266
+ setFormState('errors', errors);
267
+ validatorRef?.setErrors(errors);
248
268
  if (options.onError) {
249
269
  return options.onError(errors);
250
270
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertiajs/svelte",
3
- "version": "2.3.10",
3
+ "version": "2.3.12",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
@@ -36,14 +36,14 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@sveltejs/adapter-auto": "^3.3.1",
39
- "@sveltejs/kit": "^2.48.5",
40
- "@sveltejs/package": "^2.5.4",
39
+ "@sveltejs/kit": "^2.49.5",
40
+ "@sveltejs/package": "^2.5.7",
41
41
  "@sveltejs/vite-plugin-svelte": "^3.1.2",
42
42
  "axios": "^1.13.2",
43
- "es-check": "^9.4.5",
44
- "publint": "^0.2.12",
43
+ "es-check": "^9.5.3",
44
+ "publint": "^0.3.16",
45
45
  "svelte": "^4.2.20",
46
- "svelte-check": "^4.3.4",
46
+ "svelte-check": "^4.3.5",
47
47
  "tslib": "^2.8.1",
48
48
  "typescript": "^5.9.3",
49
49
  "vite": "^5.4.21"
@@ -54,8 +54,8 @@
54
54
  "dependencies": {
55
55
  "@types/lodash-es": "^4.17.12",
56
56
  "laravel-precognition": "^1.0.0",
57
- "lodash-es": "^4.17.21",
58
- "@inertiajs/core": "2.3.10"
57
+ "lodash-es": "^4.17.23",
58
+ "@inertiajs/core": "2.3.12"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "pnpm package && svelte-check --tsconfig ./tsconfig.json && publint",