@inertiajs/svelte 3.1.1 → 3.3.0

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,6 +1,6 @@
1
1
  <script module lang="ts">
2
- import type { ComponentResolver, ResolvedComponent } from '../types'
3
2
  import { type Page, type PageProps } from '@inertiajs/core'
3
+ import type { ComponentResolver, ResolvedComponent } from '../types'
4
4
 
5
5
  export interface InertiaAppProps<SharedProps extends PageProps = PageProps> {
6
6
  initialComponent: ResolvedComponent
@@ -11,13 +11,13 @@
11
11
  </script>
12
12
 
13
13
  <script lang="ts">
14
- import type { Component } from 'svelte'
15
- import type { LayoutType, LayoutResolver } from '../types'
16
14
  import { isPropsObjectOrCallback, isPropsObject, normalizeLayouts } from '@inertiajs/core'
17
15
  import { router } from '@inertiajs/core'
18
- import Render, { h, type RenderProps } from './Render.svelte'
19
- import { setPage } from '../page.svelte'
16
+ import type { Component } from 'svelte'
20
17
  import { resetLayoutProps, storeState } from '../layoutProps.svelte'
18
+ import { setPage } from '../page.svelte'
19
+ import type { LayoutType, LayoutResolver } from '../types'
20
+ import Render, { h, type RenderProps } from './Render.svelte'
21
21
 
22
22
  interface Props {
23
23
  initialComponent: InertiaAppProps['initialComponent']
@@ -1,5 +1,5 @@
1
- import type { ComponentResolver, ResolvedComponent } from '../types';
2
1
  import { type Page, type PageProps } from '@inertiajs/core';
2
+ import type { ComponentResolver, ResolvedComponent } from '../types';
3
3
  export interface InertiaAppProps<SharedProps extends PageProps = PageProps> {
4
4
  initialComponent: ResolvedComponent;
5
5
  initialPage: Page<SharedProps>;
@@ -15,12 +15,12 @@
15
15
  resolveUrlMethodPairComponent,
16
16
  UseFormUtils,
17
17
  } from '@inertiajs/core'
18
- import { type NamedInputEvent, type ValidationConfig, type Validator } from 'laravel-precognition'
19
18
  import { isEqual } from 'es-toolkit'
19
+ import { type NamedInputEvent, type ValidationConfig, type Validator } from 'laravel-precognition'
20
20
  import { onMount } from 'svelte'
21
- import { setFormContext } from './formContext'
22
- import useForm from '../useForm.svelte'
23
21
  import { config } from '..'
22
+ import useForm from '../useForm.svelte'
23
+ import { setFormContext } from './formContext'
24
24
 
25
25
  const noop = () => undefined
26
26
 
@@ -174,10 +174,8 @@
174
174
  onProgress,
175
175
  onFinish,
176
176
  onCancel,
177
- onSuccess: (...args) => {
178
- if (onSuccess) {
179
- onSuccess(...args)
180
- }
177
+ onSuccess: async (...args) => {
178
+ const result = await onSuccess?.(...args)
181
179
 
182
180
  if (onSubmitComplete) {
183
181
  onSubmitComplete({
@@ -191,6 +189,8 @@
191
189
  if (setDefaultsOnSuccess === true) {
192
190
  defaults()
193
191
  }
192
+
193
+ return result
194
194
  },
195
195
  onError: (...args) => {
196
196
  if (onError) {
@@ -118,9 +118,7 @@
118
118
  return infiniteScrollInstance?.dataManager.hasNext() || false
119
119
  }
120
120
 
121
- onMount(() => {
122
- setTimeout(setupInfiniteScrollInstance)
123
- })
121
+ onMount(setupInfiniteScrollInstance)
124
122
 
125
123
  function syncStateFromDataManager() {
126
124
  requestCount = infiniteScrollInstance!.dataManager.getRequestCount()
@@ -152,13 +150,19 @@
152
150
  // Request callbacks
153
151
  onBeforePreviousRequest: () => (loadingPrevious = true),
154
152
  onBeforeNextRequest: () => (loadingNext = true),
155
- onCompletePreviousRequest: () => {
153
+ onCompletePreviousRequest: ({ completed }) => {
156
154
  loadingPrevious = false
157
- syncStateFromDataManager()
155
+
156
+ if (completed) {
157
+ syncStateFromDataManager()
158
+ }
158
159
  },
159
- onCompleteNextRequest: () => {
160
+ onCompleteNextRequest: ({ completed }) => {
160
161
  loadingNext = false
161
- syncStateFromDataManager()
162
+
163
+ if (completed) {
164
+ syncStateFromDataManager()
165
+ }
162
166
  },
163
167
  onDataReset: syncStateFromDataManager,
164
168
  })
@@ -10,8 +10,9 @@ type SetupOptions<SharedProps extends PageProps> = {
10
10
  App: typeof App;
11
11
  props: InertiaAppProps<SharedProps>;
12
12
  };
13
- type SvelteWithApp = (context: Map<any, any>, options: {
13
+ type SvelteWithApp<SharedProps extends PageProps> = (context: Map<any, any>, options: {
14
14
  ssr: boolean;
15
+ page: Page<SharedProps>;
15
16
  }) => void;
16
17
  type InertiaAppOptionsForCSR<SharedProps extends PageProps> = CreateInertiaAppOptionsForCSR<SharedProps, ComponentResolver, SetupOptions<SharedProps>, SvelteRenderResult | void, SvelteInertiaAppConfig> & {
17
18
  withApp?: never;
@@ -20,7 +21,7 @@ type InertiaAppOptionsAuto<SharedProps extends PageProps> = Omit<CreateInertiaAp
20
21
  page?: Page<SharedProps>;
21
22
  } & ({
22
23
  setup?: undefined;
23
- withApp?: SvelteWithApp;
24
+ withApp?: SvelteWithApp<SharedProps>;
24
25
  } | {
25
26
  setup: (options: SetupOptions<SharedProps>) => SvelteRenderResult | void;
26
27
  withApp?: never;
@@ -32,7 +32,7 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, pro
32
32
  else {
33
33
  const context = new Map();
34
34
  if (withApp) {
35
- withApp(context, { ssr: true });
35
+ withApp(context, { ssr: true, page });
36
36
  }
37
37
  svelteApp = render(App, { props, context });
38
38
  }
@@ -70,7 +70,7 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, pro
70
70
  else {
71
71
  const context = new Map();
72
72
  if (withApp) {
73
- withApp(context, { ssr: false });
73
+ withApp(context, { ssr: false, page: initialPage });
74
74
  }
75
75
  if (target.hasAttribute('data-server-rendered')) {
76
76
  hydrate(App, { target, props, context });
package/dist/usePoll.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type PollOptions, type ReloadOptions } from '@inertiajs/core';
2
- export default function usePoll(interval: number, requestOptions?: ReloadOptions, options?: PollOptions): {
2
+ export default function usePoll(interval: number, requestOptions?: ReloadOptions | (() => ReloadOptions), options?: PollOptions): {
3
3
  stop: VoidFunction;
4
4
  start: VoidFunction;
5
5
  };
package/dist/usePoll.js CHANGED
@@ -4,7 +4,7 @@ export default function usePoll(interval, requestOptions = {}, options = {
4
4
  keepAlive: false,
5
5
  autoStart: true,
6
6
  }) {
7
- const { stop, start } = router.poll(interval, requestOptions, {
7
+ const { stop, start, destroy } = router.poll(interval, requestOptions, {
8
8
  ...options,
9
9
  autoStart: false,
10
10
  });
@@ -14,7 +14,7 @@ export default function usePoll(interval, requestOptions = {}, options = {
14
14
  }
15
15
  });
16
16
  onDestroy(() => {
17
- stop();
17
+ destroy();
18
18
  });
19
19
  return { stop, start };
20
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertiajs/svelte",
3
- "version": "3.1.1",
3
+ "version": "3.3.0",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
@@ -37,16 +37,16 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@sveltejs/adapter-auto": "^7.0.1",
40
- "@sveltejs/kit": "^2.58.0",
40
+ "@sveltejs/kit": "^2.60.1",
41
41
  "@sveltejs/package": "^2.5.7",
42
42
  "@sveltejs/vite-plugin-svelte": "^7.0.0",
43
43
  "axios": "^1.15.2",
44
44
  "es-check": "9.5.3",
45
45
  "publint": "^0.3.17",
46
- "svelte": "^5.53.5",
47
- "svelte-check": "^4.4.3",
46
+ "svelte": "^5.55.7",
47
+ "svelte-check": "^4.4.8",
48
48
  "tslib": "^2.8.1",
49
- "typescript": "^5.9.3",
49
+ "typescript": "^6.0.3",
50
50
  "vite": "^8.0.10"
51
51
  },
52
52
  "peerDependencies": {
@@ -55,7 +55,7 @@
55
55
  "dependencies": {
56
56
  "es-toolkit": "^1.33.0",
57
57
  "laravel-precognition": "^2.0.0",
58
- "@inertiajs/core": "3.1.1"
58
+ "@inertiajs/core": "3.3.0"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "pnpm package && svelte-check --tsconfig ./tsconfig.json && publint",