inertiax-svelte 2.3.3 → 2.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertiax-svelte",
3
- "version": "2.3.3",
3
+ "version": "2.4.1",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
package/src/Frame.svelte CHANGED
@@ -7,6 +7,7 @@
7
7
  const {children, src, hint, component, id = Math.random(), ...restProps} = $props()
8
8
 
9
9
  setContext('inertia:frame-id', id)
10
+
10
11
  const components = $derived($store.frames?.[id] && h($store.frames[id].component.default, Object.assign({}, restProps, $store.frames[id].props)))
11
12
 
12
13
  onMount(() => {
@@ -35,7 +35,7 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, pro
35
35
  const targetFrame = page.target
36
36
  if (targetFrame) store.update((current) => ({
37
37
  ...current,
38
- frames: { ...current.frames, [targetFrame]: {component, props: page.props} }
38
+ frames: { ...current.frames, [targetFrame]: {component, props: page.props, page} }
39
39
  }))
40
40
  else store.update((current) => ({
41
41
  component,
package/src/useForm.js CHANGED
@@ -1,15 +1,18 @@
1
1
  import { router } from 'inertiax-core'
2
2
  import isEqual from 'lodash.isequal'
3
3
  import cloneDeep from 'lodash.clonedeep'
4
- import { writable } from 'svelte/store'
4
+ import { get, writable } from 'svelte/store'
5
5
  import { getContext } from 'svelte'
6
+ import inertiaStore from './store'
6
7
 
7
8
  function useForm(...args) {
8
9
  const rememberKey = typeof args[0] === 'string' ? args[0] : null
9
10
  const data = (typeof args[0] === 'string' ? args[1] : args[0]) || {}
10
11
  const restored = rememberKey ? router.restore(rememberKey) : null
11
12
  const frameId = getContext('inertia:frame-id')
12
- const frameSrc = getContext('inertia:frame-src')
13
+
14
+ const frameSrc = frameId && get(inertiaStore).frames[frameId].page.url
15
+
13
16
  let defaults = cloneDeep(data)
14
17
  let cancelToken = null
15
18
  let recentlySuccessfulTimeoutId = null
@@ -95,6 +98,9 @@ function useForm(...args) {
95
98
 
96
99
  const _options = {
97
100
  ...options,
101
+ headers: {
102
+ 'X-Inertia-Frame-Src': frameSrc,
103
+ },
98
104
  target: typeof(options.target) !== 'undefined' ? options.target : frameId,
99
105
  onCancelToken: (token) => {
100
106
  cancelToken = token
@@ -107,7 +113,7 @@ function useForm(...args) {
107
113
  this.setStore('wasSuccessful', false)
108
114
  this.setStore('recentlySuccessful', false)
109
115
  clearTimeout(recentlySuccessfulTimeoutId)
110
-
116
+
111
117
  if (options.onBefore) {
112
118
  return options.onBefore(visit)
113
119
  }