@@ -7,13 +7,19 @@ import {
7
7
} from './component'
8
8
import { createComment , createTextNode } from './dom/node'
9
9
import { EffectScope , pauseTracking , resetTracking } from '@vue/reactivity'
10
+ import {
11
+ type TransitionHooks ,
12
+ applyTransitionEnter ,
13
+ applyTransitionLeave ,
14
+ } from '@vue/runtime-dom'
10
15
11
- export type Block =
16
+ export type Block = (
12
17
| Node
13
18
| VaporFragment
14
19
| DynamicFragment
15
20
| VaporComponentInstance
16
21
| Block [ ]
22
+ ) & { transition ?: TransitionHooks }
17
23
18
24
export type BlockFn = ( ...args : any [ ] ) => Block
19
25
@@ -22,6 +28,7 @@ export class VaporFragment {
22
28
anchor ?: Node
23
29
insert ?: ( parent : ParentNode , anchor : Node | null ) => void
24
30
remove ?: ( parent ?: ParentNode ) => void
31
+ transition ?: TransitionHooks
25
32
26
33
constructor ( nodes : Block ) {
27
34
this . nodes = nodes
@@ -52,13 +59,13 @@ export class DynamicFragment extends VaporFragment {
52
59
// teardown previous branch
53
60
if ( this . scope ) {
54
61
this . scope . stop ( )
55
- parent && remove ( this . nodes , parent )
62
+ parent && remove ( this . nodes , parent , this . transition )
56
63
}
57
64
58
65
if ( render ) {
59
66
this . scope = new EffectScope ( )
60
67
this . nodes = this . scope . run ( render ) || [ ]
61
- if ( parent ) insert ( this . nodes , parent , this . anchor )
68
+ if ( parent ) insert ( this . nodes , parent , this . anchor , this . transition )
62
69
} else {
63
70
this . scope = undefined
64
71
this . nodes = [ ]
@@ -69,7 +76,7 @@ export class DynamicFragment extends VaporFragment {
69
76
this . nodes =
70
77
( this . scope || ( this . scope = new EffectScope ( ) ) ) . run ( this . fallback ) ||
71
78
[ ]
72
- parent && insert ( this . nodes , parent , this . anchor )
79
+ parent && insert ( this . nodes , parent , this . anchor , this . transition )
73
80
}
74
81
75
82
resetTracking ( )
@@ -106,12 +113,23 @@ export function insert(
106
113
block : Block ,
107
114
parent : ParentNode ,
108
115
anchor : Node | null | 0 = null , // 0 means prepend
116
+ transition : TransitionHooks | undefined = block . transition ,
117
+ parentSuspense ?: any , // TODO Suspense
109
118
) : void {
110
119
anchor = anchor === 0 ? parent . firstChild : anchor
111
120
if ( block instanceof Node ) {
112
- parent . insertBefore ( block , anchor )
121
+ if ( transition ) {
122
+ applyTransitionEnter (
123
+ block ,
124
+ transition ,
125
+ ( ) => parent . insertBefore ( block , anchor ) ,
126
+ parentSuspense ,
127
+ )
128
+ } else {
129
+ parent . insertBefore ( block , anchor )
130
+ }
113
131
} else if ( isVaporComponent ( block ) ) {
114
- mountComponent ( block , parent , anchor )
132
+ mountComponent ( block , parent , anchor , transition )
115
133
} else if ( isArray ( block ) ) {
116
134
for ( let i = 0 ; i < block . length ; i ++ ) {
117
135
insert ( block [ i ] , parent , anchor )
@@ -121,7 +139,7 @@ export function insert(
121
139
if ( block . insert ) {
122
140
block . insert ( parent , anchor )
123
141
} else {
124
- insert ( block . nodes , parent , anchor )
142
+ insert ( block . nodes , parent , anchor , block . transition )
125
143
}
126
144
if ( block . anchor ) insert ( block . anchor , parent , anchor )
127
145
}
@@ -132,11 +150,23 @@ export function prepend(parent: ParentNode, ...blocks: Block[]): void {
132
150
while ( i -- ) insert ( blocks [ i ] , parent , 0 )
133
151
}
134
152
135
- export function remove ( block : Block , parent ?: ParentNode ) : void {
153
+ export function remove (
154
+ block : Block ,
155
+ parent ?: ParentNode ,
156
+ transition : TransitionHooks | undefined = block . transition ,
157
+ ) : void {
136
158
if ( block instanceof Node ) {
137
- parent && parent . removeChild ( block )
159
+ if ( transition ) {
160
+ applyTransitionLeave (
161
+ block ,
162
+ transition ,
163
+ ( ) => parent && parent . removeChild ( block ) ,
164
+ )
165
+ } else {
166
+ parent && parent . removeChild ( block )
167
+ }
138
168
} else if ( isVaporComponent ( block ) ) {
139
- unmountComponent ( block , parent )
169
+ unmountComponent ( block , parent , transition )
140
170
} else if ( isArray ( block ) ) {
141
171
for ( let i = 0 ; i < block . length ; i ++ ) {
142
172
remove ( block [ i ] , parent )
@@ -146,7 +176,7 @@ export function remove(block: Block, parent?: ParentNode): void {
146
176
if ( block . remove ) {
147
177
block . remove ( parent )
148
178
} else {
149
- remove ( block . nodes , parent )
179
+ remove ( block . nodes , parent , block . transition )
150
180
}
151
181
if ( block . anchor ) remove ( block . anchor , parent )
152
182
if ( ( block as DynamicFragment ) . scope ) {
0 commit comments