1- function getVNodeType ( vnode ) {
1+ /* @flow */
2+
3+ function getVNodeType ( vnode : VNode ) : string {
24 if ( ! vnode . tag ) {
35 return ''
46 }
57 return vnode . tag . replace ( / v u e \- c o m p o n e n t \- ( \d + \- ) ? / , '' )
68}
79
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
1014}
1115
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 {
2217 if ( ! vnode || ! vnode . data ) {
2318 return
2419 }
25-
2620 const { staticStyle, staticClass } = vnode . data
2721 if ( vnode . data . style || vnode . data . class || staticStyle || staticClass ) {
2822 const styles = Object . assign ( { } , staticStyle , vnode . data . style )
29-
3023 const cssMap = vnode . context . $options . style || { }
3124 const classList = [ ] . concat ( staticClass , vnode . data . class )
3225 classList . forEach ( name => {
3326 if ( name && cssMap [ name ] ) {
3427 Object . assign ( styles , cssMap [ name ] )
3528 }
3629 } )
37-
38- for ( const key in styles ) {
39- styles [ key ] = trimCSSUnit ( styles [ key ] )
40- }
4130 return styles
4231 }
4332}
4433
45- function convertVNodeChildren ( children ) {
34+ function convertVNodeChildren ( children : Array < VNode > ) : Array < VNode > | void {
4635 if ( ! children . length ) {
4736 return
4837 }
4938
5039 return children . map ( vnode => {
51- const type = getVNodeType ( vnode )
52- const props = { type }
40+ const type : string = getVNodeType ( vnode )
41+ const props : Object = { type }
5342
5443 // convert raw text node
5544 if ( ! type ) {
@@ -65,7 +54,6 @@ function convertVNodeChildren (children) {
6554 props . events = vnode . data . on
6655 }
6756 }
68-
6957 if ( type === 'span' && isSimpleSpan ( vnode ) ) {
7058 props . attr = props . attr || { }
7159 props . attr . value = vnode . children [ 0 ] . text . trim ( )
@@ -83,8 +71,7 @@ function convertVNodeChildren (children) {
8371
8472export default {
8573 name : 'richtext ',
86- // abstract: true,
87- render ( h ) {
74+ render ( h : Function ) {
8875 return h ( 'weex:richtext' , {
8976 on : this . _events ,
9077 attrs : {
0 commit comments