1
- function getVNodeType ( vnode ) {
1
+ /* @flow */
2
+
3
+ function getVNodeType ( vnode : VNode ) : string {
2
4
if ( ! vnode . tag ) {
3
5
return ''
4
6
}
5
7
return vnode . tag . replace ( / v u e \- c o m p o n e n t \- ( \d + \- ) ? / , '' )
6
8
}
7
9
8
- function isSimpleSpan ( vnode ) {
9
- return vnode . children && vnode . children . length === 1 && ! vnode . children [ 0 ] . tag
10
+ function isSimpleSpan ( vnode : VNode ) : boolean {
11
+ return vnode . children &&
12
+ vnode . children . length === 1 &&
13
+ ! vnode . children [ 0 ] . tag
10
14
}
11
15
12
- const cssLengthRE = / ^ ( [ + - ] ? [ 0 - 9 ] + ( \. [ 0 - 9 ] + ) ? ) ( p x | e m | e x | % | i n | c m | m m | p t | p c ) $ / i
13
- function trimCSSUnit ( prop ) {
14
- const res = String ( prop ) . match ( cssLengthRE )
15
- if ( res ) {
16
- return Number ( res [ 1 ] )
17
- }
18
- return prop
19
- }
20
-
21
- function parseStyle ( vnode ) {
16
+ function parseStyle ( vnode : VNode ) : Object | void {
22
17
if ( ! vnode || ! vnode . data ) {
23
18
return
24
19
}
25
-
26
20
const { staticStyle, staticClass } = vnode . data
27
21
if ( vnode . data . style || vnode . data . class || staticStyle || staticClass ) {
28
22
const styles = Object . assign ( { } , staticStyle , vnode . data . style )
29
-
30
23
const cssMap = vnode . context . $options . style || { }
31
24
const classList = [ ] . concat ( staticClass , vnode . data . class )
32
25
classList . forEach ( name => {
33
26
if ( name && cssMap [ name ] ) {
34
27
Object . assign ( styles , cssMap [ name ] )
35
28
}
36
29
} )
37
-
38
- for ( const key in styles ) {
39
- styles [ key ] = trimCSSUnit ( styles [ key ] )
40
- }
41
30
return styles
42
31
}
43
32
}
44
33
45
- function convertVNodeChildren ( children ) {
34
+ function convertVNodeChildren ( children : Array < VNode > ) : Array < VNode > | void {
46
35
if ( ! children . length ) {
47
36
return
48
37
}
49
38
50
39
return children . map ( vnode => {
51
- const type = getVNodeType ( vnode )
52
- const props = { type }
40
+ const type : string = getVNodeType ( vnode )
41
+ const props : Object = { type }
53
42
54
43
// convert raw text node
55
44
if ( ! type ) {
@@ -65,7 +54,6 @@ function convertVNodeChildren (children) {
65
54
props . events = vnode . data . on
66
55
}
67
56
}
68
-
69
57
if ( type === 'span' && isSimpleSpan ( vnode ) ) {
70
58
props . attr = props . attr || { }
71
59
props . attr . value = vnode . children [ 0 ] . text . trim ( )
@@ -83,8 +71,7 @@ function convertVNodeChildren (children) {
83
71
84
72
export default {
85
73
name : 'richtext ',
86
- // abstract: true,
87
- render ( h ) {
74
+ render ( h : Function ) {
88
75
return h ( 'weex:richtext' , {
89
76
on : this . _events ,
90
77
attrs : {
0 commit comments