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.
59 lines
1.4 KiB
59 lines
1.4 KiB
import { isNotNull, isArray, isFunction, isKey, extend } from "./2.base"; |
|
|
|
export function Fragment () {} |
|
|
|
export function h (type, props, children) { |
|
if (isNotNull(children)) { |
|
if (!isArray(children)) { |
|
children = [children]; |
|
} |
|
} else { |
|
children = []; |
|
} |
|
if (arguments.length > 3) { |
|
for (let i = 3; i < arguments.length; i++) { |
|
if (isArray(arguments[i])) { |
|
children = children.concat(arguments[i]); |
|
} else { |
|
children.push(arguments[i]); |
|
} |
|
} |
|
} |
|
if (type === Fragment) { |
|
return children; |
|
} |
|
if (isFunction(type)) { |
|
type = type.xtype || type; |
|
} |
|
if (type === "el") { |
|
return extend({ |
|
el: children[0], |
|
}, props); |
|
} |
|
if (type === "left") { |
|
return extend({ |
|
left: children, |
|
}, props); |
|
} |
|
if (type === "right") { |
|
return extend({ |
|
right: children, |
|
}, props); |
|
} |
|
if (children.length === 1) { |
|
if (isKey(children[0])) { |
|
return extend({ |
|
type, |
|
}, { text: children[0] }, props); |
|
} |
|
if (isFunction(children[0])) { |
|
return extend({ |
|
type, |
|
}, { items: children[0] }, props); |
|
} |
|
} |
|
|
|
return extend({ |
|
type, |
|
}, children.length > 0 ? { items: children } : {}, props); |
|
}
|
|
|