-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathh-demi.ts
35 lines (28 loc) · 828 Bytes
/
h-demi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { h as hDemi, isVue2 } from 'vue-demi'
interface Options {
props?: Object,
domProps?: Object
on?: Object
}
const adaptOnsV3 = (ons: Object) => {
if (!ons) return null
return Object.entries(ons).reduce((ret, [key, handler]) => {
key = key.charAt(0).toUpperCase() + key.slice(1)
key = `on${key}`
return { ...ret, [key]: handler }
}, {})
}
const h = (type: String | Object, options: Options & any = {}, chidren?: any) => {
if (isVue2)
return hDemi(type, options, chidren)
const { props, domProps, on, ...extraOptions } = options
let ons = adaptOnsV3(on)
const params = { ...extraOptions, ...props, ...domProps, ...ons }
return hDemi(type, params, chidren)
}
const slot = (s, attrs?) => {
if (typeof s == 'function') return s(attrs)
return s
}
export { slot }
export default h