@@ -9,9 +9,15 @@ import { createComment, createTextNode } from './dom/node'
9
9
import { EffectScope , pauseTracking , resetTracking } from '@vue/reactivity'
10
10
import {
11
11
type TransitionHooks ,
12
- applyTransitionEnter ,
13
- applyTransitionLeave ,
12
+ type TransitionProps ,
13
+ type TransitionState ,
14
+ performTransitionEnter ,
15
+ performTransitionLeave ,
14
16
} from '@vue/runtime-dom'
17
+ import {
18
+ applyTransitionEnterHooks ,
19
+ applyTransitionLeaveHooks ,
20
+ } from './components/Transition'
15
21
16
22
export type Block = (
17
23
| Node
@@ -22,13 +28,14 @@ export type Block = (
22
28
) &
23
29
TransitionBlock
24
30
31
+ export interface VaporTransitionHooks extends TransitionHooks {
32
+ state ?: TransitionState
33
+ props ?: TransitionProps
34
+ }
35
+
25
36
export type TransitionBlock = {
26
37
key ?: any
27
- transition ?: TransitionHooks
28
- applyTransitionLeavingHooks ?: (
29
- block : Block ,
30
- afterLeaveCb : ( ) => void ,
31
- ) => TransitionHooks | undefined
38
+ transition ?: VaporTransitionHooks
32
39
}
33
40
34
41
export type BlockFn = ( ...args : any [ ] ) => Block
@@ -38,11 +45,7 @@ export class VaporFragment {
38
45
anchor ?: Node
39
46
insert ?: ( parent : ParentNode , anchor : Node | null ) => void
40
47
remove ?: ( parent ?: ParentNode ) => void
41
- transition ?: TransitionHooks
42
- applyTransitionLeavingHooks ?: (
43
- block : Block ,
44
- afterLeaveCb : ( ) => void ,
45
- ) => TransitionHooks | undefined
48
+ transitionChild ?: TransitionBlock | undefined
46
49
47
50
constructor ( nodes : Block ) {
48
51
this . nodes = nodes
@@ -54,6 +57,7 @@ export class DynamicFragment extends VaporFragment {
54
57
scope : EffectScope | undefined
55
58
current ?: BlockFn
56
59
fallback ?: BlockFn
60
+ transitionChild ?: Block
57
61
58
62
constructor ( anchorLabel ?: string ) {
59
63
super ( [ ] )
@@ -72,9 +76,18 @@ export class DynamicFragment extends VaporFragment {
72
76
73
77
const renderBranch = ( ) => {
74
78
if ( render ) {
79
+ const transition = this . transition
75
80
this . scope = new EffectScope ( )
76
81
this . nodes = this . scope . run ( render ) || [ ]
77
- if ( parent ) insert ( this . nodes , parent , this . anchor , this . transition )
82
+ if ( transition ) {
83
+ this . transitionChild = applyTransitionEnterHooks (
84
+ this . nodes ,
85
+ transition . state ! ,
86
+ transition . props ! ,
87
+ transition ,
88
+ )
89
+ }
90
+ if ( parent ) insert ( this . nodes , parent , this . anchor )
78
91
} else {
79
92
this . scope = undefined
80
93
this . nodes = [ ]
@@ -86,32 +99,39 @@ export class DynamicFragment extends VaporFragment {
86
99
this . scope . stop ( )
87
100
const mode = this . transition && this . transition . mode
88
101
if ( mode ) {
89
- const transition = this . applyTransitionLeavingHooks ! (
102
+ applyTransitionLeaveHooks (
90
103
this . nodes ,
104
+ this . transition ! . state ! ,
105
+ this . transition ! . props ! ,
91
106
renderBranch ,
107
+ this . transition ,
92
108
)
93
- parent && remove ( this . nodes , parent , transition )
109
+ parent && remove ( this . nodes , parent )
94
110
if ( mode === 'out-in' ) {
95
111
resetTracking ( )
96
112
return
97
113
}
98
114
} else {
99
- parent && remove ( this . nodes , parent , this . transition )
115
+ parent && remove ( this . nodes , parent )
100
116
}
101
117
}
102
118
103
119
renderBranch ( )
104
120
105
121
if ( this . fallback && ! isValidBlock ( this . nodes ) ) {
106
- parent && remove ( this . nodes , parent , this . transition )
122
+ parent && remove ( this . nodes , parent )
107
123
this . nodes =
108
124
( this . scope || ( this . scope = new EffectScope ( ) ) ) . run ( this . fallback ) ||
109
125
[ ]
110
- parent && insert ( this . nodes , parent , this . anchor , this . transition )
126
+ parent && insert ( this . nodes , parent , this . anchor )
111
127
}
112
128
113
129
resetTracking ( )
114
130
}
131
+
132
+ get transition ( ) : VaporTransitionHooks | undefined {
133
+ return this . transitionChild && this . transitionChild . transition
134
+ }
115
135
}
116
136
117
137
export function isFragment ( val : NonNullable < unknown > ) : val is VaporFragment {
@@ -144,24 +164,24 @@ export function insert(
144
164
block : Block ,
145
165
parent : ParentNode ,
146
166
anchor : Node | null | 0 = null , // 0 means prepend
147
- transition : TransitionHooks | undefined = block . transition ,
148
167
parentSuspense ?: any , // TODO Suspense
149
168
) : void {
150
169
anchor = anchor === 0 ? parent . firstChild : anchor
151
170
if ( block instanceof Node ) {
152
171
// don't apply transition on text or comment nodes
153
- if ( transition && block instanceof Element ) {
154
- applyTransitionEnter (
172
+ if ( block . transition && block instanceof Element ) {
173
+ performTransitionEnter (
155
174
block ,
156
- transition ,
175
+ // @ts -expect-error
176
+ block . transition ,
157
177
( ) => parent . insertBefore ( block , anchor ) ,
158
178
parentSuspense ,
159
179
)
160
180
} else {
161
181
parent . insertBefore ( block , anchor )
162
182
}
163
183
} else if ( isVaporComponent ( block ) ) {
164
- mountComponent ( block , parent , anchor , transition )
184
+ mountComponent ( block , parent , anchor )
165
185
} else if ( isArray ( block ) ) {
166
186
for ( let i = 0 ; i < block . length ; i ++ ) {
167
187
insert ( block [ i ] , parent , anchor )
@@ -171,7 +191,7 @@ export function insert(
171
191
if ( block . insert ) {
172
192
block . insert ( parent , anchor )
173
193
} else {
174
- insert ( block . nodes , parent , anchor , block . transition )
194
+ insert ( block . nodes , parent , anchor , parentSuspense )
175
195
}
176
196
if ( block . anchor ) insert ( block . anchor , parent , anchor )
177
197
}
@@ -182,23 +202,20 @@ export function prepend(parent: ParentNode, ...blocks: Block[]): void {
182
202
while ( i -- ) insert ( blocks [ i ] , parent , 0 )
183
203
}
184
204
185
- export function remove (
186
- block : Block ,
187
- parent ?: ParentNode ,
188
- transition : TransitionHooks | undefined = block . transition ,
189
- ) : void {
205
+ export function remove ( block : Block , parent ?: ParentNode ) : void {
190
206
if ( block instanceof Node ) {
191
- if ( transition && block instanceof Element ) {
192
- applyTransitionLeave (
207
+ if ( block . transition && block instanceof Element ) {
208
+ performTransitionLeave (
193
209
block ,
194
- transition ,
210
+ // @ts -expect-error
211
+ block . transition ,
195
212
( ) => parent && parent . removeChild ( block ) ,
196
213
)
197
214
} else {
198
215
parent && parent . removeChild ( block )
199
216
}
200
217
} else if ( isVaporComponent ( block ) ) {
201
- unmountComponent ( block , parent , transition )
218
+ unmountComponent ( block , parent )
202
219
} else if ( isArray ( block ) ) {
203
220
for ( let i = 0 ; i < block . length ; i ++ ) {
204
221
remove ( block [ i ] , parent )
@@ -208,7 +225,7 @@ export function remove(
208
225
if ( block . remove ) {
209
226
block . remove ( parent )
210
227
} else {
211
- remove ( block . nodes , parent , block . transition )
228
+ remove ( block . nodes , parent )
212
229
}
213
230
if ( block . anchor ) remove ( block . anchor , parent )
214
231
if ( ( block as DynamicFragment ) . scope ) {
0 commit comments