-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(weex): add basic support of richtext
- Loading branch information
1 parent
82f03de
commit f1c96e7
Showing
4 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import Richtext from './richtext' | ||
import Transition from './transition' | ||
import TransitionGroup from './transition-group' | ||
|
||
export default { | ||
Richtext, | ||
Transition, | ||
TransitionGroup | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
function parseChildren (h, options) { | ||
const children = options._renderChildren | ||
if (!children) { | ||
return [] | ||
} | ||
|
||
return children.map(vnode => { | ||
if (!vnode.tag && vnode.text) { | ||
return h('span', vnode.text) | ||
} | ||
return vnode | ||
}) | ||
} | ||
|
||
function getVNodeType (vnode) { | ||
const tagName = vnode.tag | ||
if (!tagName) { | ||
return '' | ||
} | ||
return tagName.replace(/vue\-component\-(\d+\-)?/, '') | ||
} | ||
|
||
function convertVNodeChildren (children) { | ||
if (!children.length) { | ||
return | ||
} | ||
return children.map(vnode => { | ||
const type = getVNodeType(vnode) | ||
const props = { type } | ||
|
||
// TODO: filter | ||
if (vnode.data) { | ||
props.style = vnode.data.staticStyle | ||
props.attr = vnode.data.attrs | ||
} | ||
|
||
if (type === 'span') { | ||
props.attr = {} | ||
props.attr.value = vnode.text || vnode.children.map(c => c.text).join('').trim() | ||
} | ||
|
||
return props | ||
}) | ||
} | ||
|
||
export default { | ||
name: 'richtext', | ||
abstract: true, | ||
render (h) { | ||
const children = parseChildren(h, this.$options) | ||
const values = convertVNodeChildren(children) | ||
return h('weex:richtext', { | ||
attrs: { | ||
value: values | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters