@inertiajs/svelte 2.0.5 → 2.0.7

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,5 +1,5 @@
1
1
  <script>import { inertia } from "../index";
2
- export let href;
2
+ export let href = "";
3
3
  export let as = "a";
4
4
  export let data = {};
5
5
  export let method = "get";
@@ -13,6 +13,8 @@ export let queryStringArrayFormat = "brackets";
13
13
  export let async = false;
14
14
  export let prefetch = false;
15
15
  export let cacheFor = 0;
16
+ method = typeof href === "object" ? href.method : method;
17
+ href = typeof href === "object" ? href.url : href;
16
18
  $: asProp = method !== "get" ? "button" : as.toLowerCase();
17
19
  $: elProps = {
18
20
  a: { href },
@@ -3,7 +3,10 @@ import type { CacheForOption, FormDataConvertible, LinkPrefetchOption, Method, P
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  [x: string]: any;
6
- href: string;
6
+ href?: string | {
7
+ url: string;
8
+ method: Method;
9
+ } | undefined;
7
10
  as?: keyof HTMLElementTagNameMap | undefined;
8
11
  data?: Record<string, FormDataConvertible> | undefined;
9
12
  method?: Method | undefined;
package/dist/link.d.ts CHANGED
@@ -1,11 +1,14 @@
1
- import { type CacheForOption, type FormDataConvertible, type GlobalEventsMap, type LinkPrefetchOption, type VisitOptions } from '@inertiajs/core';
1
+ import { type CacheForOption, type FormDataConvertible, type GlobalEventsMap, type LinkPrefetchOption, type Method, 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
7
  type ActionParameters = Omit<VisitOptions, 'data' | 'prefetch'> & {
8
- href?: string;
8
+ href?: string | {
9
+ url: string;
10
+ method: Method;
11
+ };
9
12
  data?: Record<string, FormDataConvertible>;
10
13
  prefetch?: boolean | LinkPrefetchOption | LinkPrefetchOption[];
11
14
  cacheFor?: CacheForOption | CacheForOption[];
package/dist/link.js CHANGED
@@ -58,7 +58,7 @@ function link(node, initialParams = {}) {
58
58
  }
59
59
  return 30_000;
60
60
  })();
61
- method = (params.method?.toLowerCase() || 'get');
61
+ method = typeof params.href === 'object' ? params.href.method : (params.method?.toLowerCase() || 'get');
62
62
  [href, data] = hrefAndData(method, params);
63
63
  if (node.tagName === 'A') {
64
64
  node.href = href;
@@ -99,7 +99,7 @@ function link(node, initialParams = {}) {
99
99
  return node.dispatchEvent(new CustomEvent(type, detail));
100
100
  }
101
101
  function hrefAndData(method, params) {
102
- return mergeDataIntoQueryString(method, node.href || params.href || '', params.data || {}, params.queryStringArrayFormat || 'brackets');
102
+ return mergeDataIntoQueryString(method, typeof params.href === 'object' ? params.href.url : node.href || params.href || '', params.data || {}, params.queryStringArrayFormat || 'brackets');
103
103
  }
104
104
  function prefetch() {
105
105
  router.prefetch(href, baseParams, { cacheFor: cacheForValue });
package/dist/useForm.d.ts CHANGED
@@ -1,27 +1,30 @@
1
- import type { Errors, FormDataConvertible, Method, Progress, VisitOptions } from '@inertiajs/core';
1
+ import type { Errors, FormDataConvertible, FormDataKeys, Method, Progress, VisitOptions } from '@inertiajs/core';
2
2
  import { type Writable } from 'svelte/store';
3
3
  type FormDataType = Record<string, FormDataConvertible>;
4
4
  type FormOptions = Omit<VisitOptions, 'data'>;
5
5
  export interface InertiaFormProps<TForm extends FormDataType> {
6
6
  isDirty: boolean;
7
- errors: Partial<Record<keyof TForm, string>>;
7
+ errors: Partial<Record<FormDataKeys<TForm>, string>>;
8
8
  hasErrors: boolean;
9
9
  progress: Progress | null;
10
10
  wasSuccessful: boolean;
11
11
  recentlySuccessful: boolean;
12
12
  processing: boolean;
13
13
  setStore(data: TForm): void;
14
- setStore(key: keyof TForm, value?: FormDataConvertible): void;
14
+ setStore(key: FormDataKeys<TForm>, value?: FormDataConvertible): void;
15
15
  data(): TForm;
16
16
  transform(callback: (data: TForm) => object): this;
17
17
  defaults(): this;
18
18
  defaults(fields: Partial<TForm>): this;
19
- defaults(field?: keyof TForm, value?: FormDataConvertible): this;
20
- reset(...fields: (keyof TForm)[]): this;
21
- clearErrors(...fields: (keyof TForm)[]): this;
22
- setError(field: keyof TForm, value: string): this;
19
+ defaults(field?: FormDataKeys<TForm>, value?: FormDataConvertible): this;
20
+ reset(...fields: FormDataKeys<TForm>[]): this;
21
+ clearErrors(...fields: FormDataKeys<TForm>[]): this;
22
+ setError(field: FormDataKeys<TForm>, value: string): this;
23
23
  setError(errors: Errors): this;
24
- submit(method: Method, url: string, options?: FormOptions): void;
24
+ submit: (...args: [Method, string, FormOptions?] | [{
25
+ url: string;
26
+ method: Method;
27
+ }, FormOptions?]) => void;
25
28
  get(url: string, options?: FormOptions): void;
26
29
  post(url: string, options?: FormOptions): void;
27
30
  put(url: string, options?: FormOptions): void;
package/dist/useForm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { router } from '@inertiajs/core';
2
- import cloneDeep from 'lodash/cloneDeep';
3
- import isEqual from 'lodash/isEqual';
2
+ import { cloneDeep, isEqual } from 'es-toolkit';
3
+ import { get, has, set } from 'es-toolkit/compat';
4
4
  import { writable } from 'svelte/store';
5
5
  export default function useForm(rememberKeyOrData, maybeData) {
6
6
  const rememberKey = typeof rememberKeyOrData === 'string' ? rememberKeyOrData : null;
@@ -24,13 +24,12 @@ export default function useForm(rememberKeyOrData, maybeData) {
24
24
  processing: false,
25
25
  setStore(keyOrData, maybeValue = undefined) {
26
26
  store.update((store) => {
27
- return Object.assign(store, typeof keyOrData === 'string' ? { [keyOrData]: maybeValue } : keyOrData);
27
+ return typeof keyOrData === 'string' ? set(store, keyOrData, maybeValue) : Object.assign(store, keyOrData);
28
28
  });
29
29
  },
30
30
  data() {
31
31
  return Object.keys(data).reduce((carry, key) => {
32
- carry[key] = this[key];
33
- return carry;
32
+ return set(carry, key, get(this, key));
34
33
  }, {});
35
34
  },
36
35
  transform(callback) {
@@ -38,10 +37,15 @@ export default function useForm(rememberKeyOrData, maybeData) {
38
37
  return this;
39
38
  },
40
39
  defaults(fieldOrFields, maybeValue) {
41
- defaults =
42
- typeof fieldOrFields === 'undefined'
43
- ? cloneDeep(this.data())
44
- : Object.assign(cloneDeep(defaults), typeof fieldOrFields === 'string' ? { [fieldOrFields]: maybeValue } : fieldOrFields);
40
+ if (typeof fieldOrFields === 'undefined') {
41
+ defaults = cloneDeep(this.data());
42
+ }
43
+ else {
44
+ defaults =
45
+ typeof fieldOrFields === 'string'
46
+ ? set(cloneDeep(defaults), fieldOrFields, maybeValue)
47
+ : Object.assign(cloneDeep(defaults), fieldOrFields);
48
+ }
45
49
  return this;
46
50
  },
47
51
  reset(...fields) {
@@ -50,11 +54,10 @@ export default function useForm(rememberKeyOrData, maybeData) {
50
54
  this.setStore(clonedData);
51
55
  }
52
56
  else {
53
- this.setStore(Object.keys(clonedData)
54
- .filter((key) => fields.includes(key))
57
+ this.setStore(fields
58
+ .filter((key) => has(clonedData, key))
55
59
  .reduce((carry, key) => {
56
- carry[key] = clonedData[key];
57
- return carry;
60
+ return set(carry, key, get(clonedData, key));
58
61
  }, {}));
59
62
  }
60
63
  return this;
@@ -73,7 +76,11 @@ export default function useForm(rememberKeyOrData, maybeData) {
73
76
  }), {}));
74
77
  return this;
75
78
  },
76
- submit(method, url, options = {}) {
79
+ submit(...args) {
80
+ const objectPassed = typeof args[0] === 'object';
81
+ const method = objectPassed ? args[0].method : args[0];
82
+ const url = objectPassed ? args[0].url : args[1];
83
+ const options = (objectPassed ? args[1] : args[2]) ?? {};
77
84
  const data = transform(this.data());
78
85
  const _options = {
79
86
  ...options,
@@ -111,6 +118,7 @@ export default function useForm(rememberKeyOrData, maybeData) {
111
118
  this.clearErrors();
112
119
  this.setStore('wasSuccessful', true);
113
120
  this.setStore('recentlySuccessful', true);
121
+ this.defaults(cloneDeep(this.data()));
114
122
  recentlySuccessfulTimeoutId = setTimeout(() => this.setStore('recentlySuccessful', false), 2000);
115
123
  if (options.onSuccess) {
116
124
  return options.onSuccess(page);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertiajs/svelte",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
@@ -43,9 +43,9 @@
43
43
  "svelte": "^4.0.0 || ^5.0.0 || ^5.0.0-next.244"
44
44
  },
45
45
  "dependencies": {
46
- "@inertiajs/core": "2.0.5",
47
- "html-escape": "^2.0.0",
48
- "lodash": "^4.5.0"
46
+ "@inertiajs/core": "2.0.7",
47
+ "es-toolkit": "^1.33.0",
48
+ "html-escape": "^2.0.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@sveltejs/adapter-auto": "^3.2.0",
@@ -53,14 +53,13 @@
53
53
  "@sveltejs/package": "^2.3.4",
54
54
  "@sveltejs/vite-plugin-svelte": "^3.1.2",
55
55
  "@types/html-escape": "^2.0.2",
56
- "@types/lodash": "^4.17.7",
57
56
  "axios": "^1.8.2",
58
57
  "publint": "^0.2.10",
59
58
  "svelte": "^4.2.16",
60
59
  "svelte-check": "^4.0.0",
61
60
  "tslib": "^2.7.0",
62
61
  "typescript": "^5.5.4",
63
- "vite": "^5.4.12"
62
+ "vite": "^5.4.17"
64
63
  },
65
64
  "svelte": "./dist/index.js",
66
65
  "types": "./dist/index.d.ts",