2020-06-10 10:21:16 +00:00
|
|
|
|
import { filterEmpty } from './props-util';
|
2020-10-02 07:44:10 +00:00
|
|
|
|
import { cloneVNode } from 'vue';
|
2020-07-20 08:29:46 +00:00
|
|
|
|
import warning from './warning';
|
2019-07-24 11:21:27 +00:00
|
|
|
|
|
2020-10-07 14:49:01 +00:00
|
|
|
|
export function cloneElement(vnode, nodeProps = {}, override = true, mergeRef = false) {
|
2020-07-06 14:31:07 +00:00
|
|
|
|
let ele = vnode;
|
|
|
|
|
if (Array.isArray(vnode)) {
|
|
|
|
|
ele = filterEmpty(vnode)[0];
|
2018-01-29 10:57:20 +00:00
|
|
|
|
}
|
|
|
|
|
if (!ele) {
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return null;
|
2018-01-29 10:57:20 +00:00
|
|
|
|
}
|
2020-10-07 14:49:01 +00:00
|
|
|
|
const node = cloneVNode(ele, nodeProps, mergeRef);
|
2018-03-03 11:14:03 +00:00
|
|
|
|
|
2020-06-10 10:21:16 +00:00
|
|
|
|
// cloneVNode内部是合并属性,这里改成覆盖属性
|
|
|
|
|
node.props = override ? { ...node.props, ...nodeProps } : node.props;
|
2020-10-02 07:44:10 +00:00
|
|
|
|
warning(typeof node.props.class !== 'object', 'class must be string');
|
2019-01-12 03:33:27 +00:00
|
|
|
|
return node;
|
2017-12-14 04:13:15 +00:00
|
|
|
|
}
|
2020-07-06 14:31:07 +00:00
|
|
|
|
|
2020-10-02 07:44:10 +00:00
|
|
|
|
export function cloneVNodes(vnodes, nodeProps = {}, override = true) {
|
2020-07-06 14:31:07 +00:00
|
|
|
|
return vnodes.map(vnode => cloneElement(vnode, nodeProps, override));
|
|
|
|
|
}
|