You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/_util/vnode.js

52 lines
1.3 KiB

7 years ago
import clonedeep from 'lodash.clonedeep'
7 years ago
export function cloneVNode (vnode, deep) {
const cloned = new vnode.constructor(
vnode.tag,
7 years ago
clonedeep(vnode.data),
7 years ago
vnode.children,
vnode.text,
vnode.elm,
vnode.context,
7 years ago
clonedeep(vnode.componentOptions),
7 years ago
vnode.asyncFactory
)
cloned.ns = vnode.ns
cloned.isStatic = vnode.isStatic
cloned.key = vnode.key
cloned.isComment = vnode.isComment
cloned.isCloned = true
if (deep && vnode.children) {
cloned.children = cloneVNodes(vnode.children)
}
return cloned
}
export function cloneVNodes (vnodes, deep) {
const len = vnodes.length
const res = new Array(len)
for (let i = 0; i < len; i++) {
res[i] = cloneVNode(vnodes[i], deep)
}
return res
}
export function cloneElement (node, nodeProps) {
7 years ago
const { props, key } = nodeProps
7 years ago
if (node.componentOptions) {
7 years ago
node.componentOptions.propsData = node.componentOptions.propsData || {}
7 years ago
Object.assign(node.componentOptions.propsData, props)
}
7 years ago
const data = node.data || {}
const { style = data.style,
class: cls = data.class,
attrs = data.attrs,
on = data.on,
} = nodeProps
7 years ago
node.data = Object.assign(data, { style, attrs, class: cls, on })
7 years ago
if (key !== undefined) {
node.key = key
7 years ago
node.data.key = key
7 years ago
}
return node
}