forked from vuejs/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:vuejs/vue into new-type
- Loading branch information
Showing
9 changed files
with
836 additions
and
13 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
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,95 @@ | ||
function getVNodeType (vnode) { | ||
if (!vnode.tag) { | ||
return '' | ||
} | ||
return vnode.tag.replace(/vue\-component\-(\d+\-)?/, '') | ||
} | ||
|
||
function isSimpleSpan (vnode) { | ||
return vnode.children && vnode.children.length === 1 && !vnode.children[0].tag | ||
} | ||
|
||
const cssLengthRE = /^([+-]?[0-9]+(\.[0-9]+)?)(px|em|ex|%|in|cm|mm|pt|pc)$/i | ||
function trimCSSUnit (prop) { | ||
const res = String(prop).match(cssLengthRE) | ||
if (res) { | ||
return Number(res[1]) | ||
} | ||
return prop | ||
} | ||
|
||
function parseStyle (vnode) { | ||
if (!vnode || !vnode.data) { | ||
return | ||
} | ||
|
||
const { staticStyle, staticClass } = vnode.data | ||
if (vnode.data.style || vnode.data.class || staticStyle || staticClass) { | ||
const styles = Object.assign({}, staticStyle, vnode.data.style) | ||
|
||
const cssMap = vnode.context.$options.style || {} | ||
const classList = [].concat(staticClass, vnode.data.class) | ||
classList.forEach(name => { | ||
if (name && cssMap[name]) { | ||
Object.assign(styles, cssMap[name]) | ||
} | ||
}) | ||
|
||
for (const key in styles) { | ||
styles[key] = trimCSSUnit(styles[key]) | ||
} | ||
return styles | ||
} | ||
} | ||
|
||
function convertVNodeChildren (children) { | ||
if (!children.length) { | ||
return | ||
} | ||
|
||
return children.map(vnode => { | ||
const type = getVNodeType(vnode) | ||
const props = { type } | ||
|
||
// convert raw text node | ||
if (!type) { | ||
props.type = 'span' | ||
props.attr = { | ||
value: (vnode.text || '').trim() | ||
} | ||
} else { | ||
props.style = parseStyle(vnode) | ||
if (vnode.data) { | ||
props.attr = vnode.data.attrs | ||
if (vnode.data.on) { | ||
props.events = vnode.data.on | ||
} | ||
} | ||
|
||
if (type === 'span' && isSimpleSpan(vnode)) { | ||
props.attr = props.attr || {} | ||
props.attr.value = vnode.children[0].text.trim() | ||
return props | ||
} | ||
} | ||
|
||
if (vnode.children && vnode.children.length) { | ||
props.children = convertVNodeChildren(vnode.children) | ||
} | ||
|
||
return props | ||
}) | ||
} | ||
|
||
export default { | ||
name: 'richtext', | ||
// abstract: true, | ||
render (h) { | ||
return h('weex:richtext', { | ||
on: this._events, | ||
attrs: { | ||
value: convertVNodeChildren(this.$options._renderChildren || []) | ||
} | ||
}) | ||
} | ||
} |
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
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
Oops, something went wrong.