1
- import Vue from 'vue'
1
+ import Vue , { VNodeData } from 'vue'
2
2
import { VNode , VNodeDirective , FunctionalComponentOptions } from 'vue/types'
3
3
import { VuetifyIcon } from 'vuetify/types/services/icons'
4
+ import mergeData from './mergeData'
4
5
5
6
export function createSimpleFunctional (
6
7
c : string ,
@@ -20,15 +21,6 @@ export function createSimpleFunctional (
20
21
} )
21
22
}
22
23
23
- function mergeTransitions (
24
- transitions : undefined | Function | Function [ ] ,
25
- array : Function [ ]
26
- ) {
27
- if ( Array . isArray ( transitions ) ) return transitions . concat ( array )
28
- if ( transitions ) array . push ( transitions )
29
- return array
30
- }
31
-
32
24
export function createSimpleTransition (
33
25
name : string ,
34
26
origin = 'top center 0' ,
@@ -64,38 +56,27 @@ export function createSimpleTransition (
64
56
65
57
render ( h , context ) : VNode {
66
58
const tag = `transition${ context . props . group ? '-group' : '' } `
67
- context . data = context . data || { }
68
- context . data . props = {
69
- name,
70
- mode : context . props . mode ,
71
- }
72
- context . data . on = context . data . on || { }
73
- if ( ! Object . isExtensible ( context . data . on ) ) {
74
- context . data . on = { ...context . data . on }
59
+ const data : VNodeData = {
60
+ props : {
61
+ name,
62
+ mode : context . props . mode ,
63
+ } ,
64
+ on : {
65
+ beforeEnter ( el : HTMLElement ) {
66
+ el . style . transformOrigin = context . props . origin
67
+ el . style . webkitTransformOrigin = context . props . origin
68
+ } ,
69
+ } ,
75
70
}
76
71
77
- const ourBeforeEnter : Function [ ] = [ ]
78
- const ourLeave : Function [ ] = [ ]
79
- const absolute = ( el : HTMLElement ) => ( el . style . position = 'absolute' )
80
-
81
- ourBeforeEnter . push ( ( el : HTMLElement ) => {
82
- el . style . transformOrigin = context . props . origin
83
- el . style . webkitTransformOrigin = context . props . origin
84
- } )
85
-
86
- if ( context . props . leaveAbsolute ) ourLeave . push ( absolute )
72
+ if ( context . props . leaveAbsolute ) {
73
+ data . on ! . leave = [ ...data . on ! . leave , ( el : HTMLElement ) => ( el . style . position = 'absolute' ) ]
74
+ }
87
75
if ( context . props . hideOnLeave ) {
88
- ourLeave . push ( ( el : HTMLElement ) => ( el . style . display = 'none' ) )
76
+ data . on ! . leave = [ ... data . on ! . leave , ( el : HTMLElement ) => ( el . style . display = 'none' ) ]
89
77
}
90
78
91
- const { beforeEnter, leave } = context . data . on
92
-
93
- // Type says Function | Function[] but
94
- // will only work if provided a function
95
- context . data . on . beforeEnter = ( ) => mergeTransitions ( beforeEnter , ourBeforeEnter )
96
- context . data . on . leave = mergeTransitions ( leave , ourLeave )
97
-
98
- return h ( tag , context . data , context . children )
79
+ return h ( tag , mergeData ( context . data , data ) , context . children )
99
80
} ,
100
81
}
101
82
}
@@ -118,15 +99,14 @@ export function createJavaScriptTransition (
118
99
} ,
119
100
120
101
render ( h , context ) : VNode {
121
- const data = {
122
- props : {
123
- ...context . props ,
124
- name,
125
- } ,
126
- on : functions ,
127
- }
128
-
129
- return h ( 'transition' , data , context . children )
102
+ return h (
103
+ 'transition' ,
104
+ mergeData ( context . data , {
105
+ props : { name } ,
106
+ on : functions ,
107
+ } ) ,
108
+ context . children
109
+ )
130
110
} ,
131
111
}
132
112
}
0 commit comments