Skip to content

Commit 7cec3df

Browse files
authored
TS cleanup for <Link> component + View Transition prop in Svelte (#2667)
* Svelte * Vue
1 parent 6df29a8 commit 7cec3df

File tree

3 files changed

+50
-60
lines changed

3 files changed

+50
-60
lines changed

packages/svelte/src/components/Link.svelte

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
<script lang="ts">
22
import { isUrlMethodPair } from '@inertiajs/core'
3-
import type {
4-
CacheForOption,
5-
FormDataConvertible,
6-
LinkPrefetchOption,
7-
Method,
8-
PreserveStateOption,
9-
UrlMethodPair,
10-
} from '@inertiajs/core'
3+
import type { LinkComponentBaseProps } from '@inertiajs/core'
114
import { inertia } from '../index'
125
13-
export let href: string | UrlMethodPair = ''
6+
export let href: LinkComponentBaseProps['href'] = ''
147
export let as: keyof HTMLElementTagNameMap = 'a'
15-
export let data: Record<string, FormDataConvertible> = {}
16-
export let method: Method = 'get'
17-
export let replace: boolean = false
18-
export let preserveScroll: PreserveStateOption = false
19-
export let preserveState: PreserveStateOption | null = null
20-
export let preserveUrl: boolean = false
21-
export let only: string[] = []
22-
export let except: string[] = []
23-
export let headers: Record<string, string> = {}
24-
export let queryStringArrayFormat: 'brackets' | 'indices' = 'brackets'
25-
export let async: boolean = false
26-
export let prefetch: boolean | LinkPrefetchOption | LinkPrefetchOption[] = false
27-
export let cacheFor: CacheForOption | CacheForOption[] = 0
28-
export let cacheTags: string | string[] = []
8+
export let data: LinkComponentBaseProps['data'] = {}
9+
export let method: LinkComponentBaseProps['method'] = 'get'
10+
export let replace: LinkComponentBaseProps['replace'] = false
11+
export let preserveScroll: LinkComponentBaseProps['preserveScroll'] = false
12+
export let preserveState: LinkComponentBaseProps['preserveState'] | null = null
13+
export let preserveUrl: LinkComponentBaseProps['preserveUrl'] = false
14+
export let only: LinkComponentBaseProps['only'] = []
15+
export let except: LinkComponentBaseProps['except'] = []
16+
export let headers: LinkComponentBaseProps['headers'] = {}
17+
export let queryStringArrayFormat: LinkComponentBaseProps['queryStringArrayFormat'] = 'brackets'
18+
export let async: LinkComponentBaseProps['async'] = false
19+
export let prefetch: LinkComponentBaseProps['prefetch'] = false
20+
export let cacheFor: LinkComponentBaseProps['cacheFor'] = 0
21+
export let cacheTags: LinkComponentBaseProps['cacheTags'] = []
22+
export let viewTransition: LinkComponentBaseProps['viewTransition'] = false
2923
3024
$: _method = isUrlMethodPair(href) ? href.method : method
3125
$: _href = isUrlMethodPair(href) ? href.url : href
@@ -57,6 +51,7 @@
5751
prefetch,
5852
cacheFor,
5953
cacheTags,
54+
viewTransition,
6055
}}
6156
{...$$restProps}
6257
{...elProps}

packages/svelte/test-app/Pages/ViewTransition/PageA.svelte

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { inertia, router } from '@inertiajs/svelte'
2+
import { Link, router } from '@inertiajs/svelte'
33
44
const transitionWithBoolean = () => {
55
router.visit('/view-transition/page-b', {
@@ -36,13 +36,11 @@
3636
<button on:click={transitionWithBoolean}>Transition with boolean</button>
3737
<button on:click={transitionWithCallback}>Transition with callback</button>
3838
<button on:click={clientSideReplace}>Client-side replace</button>
39-
<a
39+
<Link
4040
href="/view-transition/page-b"
41-
use:inertia={{
42-
viewTransition: (viewTransition) => {
43-
viewTransition.ready.then(() => console.log('ready'))
44-
viewTransition.updateCallbackDone.then(() => console.log('updateCallbackDone'))
45-
viewTransition.finished.then(() => console.log('finished'))
46-
},
47-
}}>Link to Page B</a
41+
viewTransition={(viewTransition) => {
42+
viewTransition.ready.then(() => console.log('ready'))
43+
viewTransition.updateCallbackDone.then(() => console.log('updateCallbackDone'))
44+
viewTransition.finished.then(() => console.log('finished'))
45+
}}>Link to Page B</Link
4846
>

packages/vue3/src/link.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import {
22
ActiveVisit,
3-
CacheForOption,
4-
CancelTokenCallback,
5-
GlobalEventCallback,
63
isUrlMethodPair,
74
LinkComponentBaseProps,
85
LinkPrefetchOption,
@@ -29,107 +26,107 @@ const Link: InertiaLink = defineComponent({
2926
name: 'Link',
3027
props: {
3128
as: {
32-
type: [String, Object] as PropType<string | Component>,
29+
type: [String, Object] as PropType<InertiaLinkProps['as']>,
3330
default: 'a',
3431
},
3532
data: {
36-
type: Object,
33+
type: Object as PropType<InertiaLinkProps['data']>,
3734
default: () => ({}),
3835
},
3936
href: {
4037
type: [String, Object] as PropType<InertiaLinkProps['href']>,
4138
default: '',
4239
},
4340
method: {
44-
type: String as PropType<Method>,
41+
type: String as PropType<InertiaLinkProps['method']>,
4542
default: 'get',
4643
},
4744
replace: {
48-
type: Boolean,
45+
type: Boolean as PropType<InertiaLinkProps['replace']>,
4946
default: false,
5047
},
5148
preserveScroll: {
52-
type: Boolean,
49+
type: [Boolean, String, Function] as PropType<InertiaLinkProps['preserveScroll']>,
5350
default: false,
5451
},
5552
preserveState: {
56-
type: Boolean,
53+
type: [Boolean, String, Function] as PropType<InertiaLinkProps['preserveState']>,
5754
default: null,
5855
},
5956
preserveUrl: {
60-
type: Boolean,
57+
type: Boolean as PropType<InertiaLinkProps['preserveUrl']>,
6158
default: false,
6259
},
6360
only: {
64-
type: Array<string>,
61+
type: Array as PropType<InertiaLinkProps['only']>,
6562
default: () => [],
6663
},
6764
except: {
68-
type: Array<string>,
65+
type: Array as PropType<InertiaLinkProps['except']>,
6966
default: () => [],
7067
},
7168
headers: {
72-
type: Object,
69+
type: Object as PropType<InertiaLinkProps['headers']>,
7370
default: () => ({}),
7471
},
7572
queryStringArrayFormat: {
76-
type: String as PropType<'brackets' | 'indices'>,
73+
type: String as PropType<InertiaLinkProps['queryStringArrayFormat']>,
7774
default: 'brackets',
7875
},
7976
async: {
80-
type: Boolean,
77+
type: Boolean as PropType<InertiaLinkProps['async']>,
8178
default: false,
8279
},
8380
prefetch: {
84-
type: [Boolean, String, Array] as PropType<boolean | LinkPrefetchOption | LinkPrefetchOption[]>,
81+
type: [Boolean, String, Array] as PropType<InertiaLinkProps['prefetch']>,
8582
default: false,
8683
},
8784
cacheFor: {
88-
type: [Number, String, Array] as PropType<CacheForOption | CacheForOption[]>,
85+
type: [Number, String, Array] as PropType<InertiaLinkProps['cacheFor']>,
8986
default: 0,
9087
},
9188
onStart: {
92-
type: Function as PropType<GlobalEventCallback<'start'>>,
89+
type: Function as PropType<InertiaLinkProps['onStart']>,
9390
default: noop,
9491
},
9592
onProgress: {
96-
type: Function as PropType<GlobalEventCallback<'progress'>>,
93+
type: Function as PropType<InertiaLinkProps['onProgress']>,
9794
default: noop,
9895
},
9996
onFinish: {
100-
type: Function as PropType<GlobalEventCallback<'finish'>>,
97+
type: Function as PropType<InertiaLinkProps['onFinish']>,
10198
default: noop,
10299
},
103100
onBefore: {
104-
type: Function as PropType<GlobalEventCallback<'before'>>,
101+
type: Function as PropType<InertiaLinkProps['onBefore']>,
105102
default: noop,
106103
},
107104
onCancel: {
108-
type: Function as PropType<GlobalEventCallback<'cancel'>>,
105+
type: Function as PropType<InertiaLinkProps['onCancel']>,
109106
default: noop,
110107
},
111108
onSuccess: {
112-
type: Function as PropType<GlobalEventCallback<'success'>>,
109+
type: Function as PropType<InertiaLinkProps['onSuccess']>,
113110
default: noop,
114111
},
115112
onError: {
116-
type: Function as PropType<GlobalEventCallback<'error'>>,
113+
type: Function as PropType<InertiaLinkProps['onError']>,
117114
default: noop,
118115
},
119116
onCancelToken: {
120-
type: Function as PropType<CancelTokenCallback>,
117+
type: Function as PropType<InertiaLinkProps['onCancelToken']>,
121118
default: noop,
122119
},
123120
onPrefetching: {
124-
type: Function as PropType<GlobalEventCallback<'prefetching'>>,
121+
type: Function as PropType<InertiaLinkProps['onPrefetching']>,
125122
default: noop,
126123
},
127124
onPrefetched: {
128-
type: Function as PropType<GlobalEventCallback<'prefetched'>>,
125+
type: Function as PropType<InertiaLinkProps['onPrefetched']>,
129126
default: noop,
130127
},
131128
cacheTags: {
132-
type: [String, Array] as PropType<string | string[]>,
129+
type: [String, Array] as PropType<InertiaLinkProps['cacheTags']>,
133130
default: () => [],
134131
},
135132
viewTransition: {

0 commit comments

Comments
 (0)