-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
65 lines (64 loc) · 1.55 KB
/
index.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { defineComponent, h } from 'vue'
import { hasOwn, hyphenate } from '@vue/shared'
export default defineComponent({
name: 'github-button',
props: {
href: String,
ariaLabel: String,
title: String,
dataIcon: String,
dataColorScheme: String,
dataSize: String,
dataShowCount: String,
dataText: String
},
render: function () {
const props = { ref: '_' }
for (const key in this.$props) {
props[hyphenate(key)] = this.$props[key]
}
return h('span', [
hasOwn(this.$slots, 'default')
? h('a', props, this.$slots.default())
: h('a', props)
])
},
mounted: function () {
this.paint()
},
beforeUpdate: function () {
this.reset()
},
updated: function () {
this.paint()
},
beforeUnmount: function () {
this.reset()
},
methods: {
paint: function () {
if (this.$el.lastChild !== this.$refs._) {
return
}
const _ = this.$el.appendChild(document.createElement('span'))
const _this = this
import(/* webpackMode: "eager" */ 'github-buttons').then(function (module) {
if (_this.$el.lastChild !== _) {
return
}
module.render(_.appendChild(_this.$refs._), function (el) {
if (_this.$el.lastChild !== _) {
return
}
_.parentNode.replaceChild(el, _)
})
})
},
reset: function () {
if (this.$refs._ == null) {
return
}
this.$el.replaceChild(/** @type {HTMLAnchorElement} */ (this.$refs._), this.$el.lastChild)
}
}
})