forked from bootstrap-vue/bootstrap-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.js
126 lines (109 loc) · 3.92 KB
/
vue.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import Vue from 'vue'
import { mergeData } from 'vue-functional-data-merge'
// --- Constants ---
const COMPONENT_UID_KEY = '_uid'
const isVue3 = Vue.version.startsWith('3')
export const REF_FOR_KEY = isVue3 ? 'ref_for' : 'refInFor'
const ALLOWED_FIELDS_IN_DATA = [
'class',
'staticClass',
'style',
'attrs',
'props',
'domProps',
'on',
'nativeOn',
'directives',
'scopedSlots',
'slot',
'key',
'ref',
'refInFor'
]
let extend = Vue.extend.bind(Vue)
if (isVue3) {
const { extend: originalExtend } = Vue
const KNOWN_COMPONENTS = ['router-link', 'transition', 'transition-group']
const originalVModelDynamicCreated = Vue.vModelDynamic.created
const originalVModelDynamicBeforeUpdate = Vue.vModelDynamic.beforeUpdate
// See https://github.com/vuejs/vue-next/pull/4121 for details
Vue.vModelDynamic.created = function(el, binding, vnode) {
originalVModelDynamicCreated.call(this, el, binding, vnode)
if (!el._assign) {
el._assign = () => {}
}
}
Vue.vModelDynamic.beforeUpdate = function(el, binding, vnode) {
originalVModelDynamicBeforeUpdate.call(this, el, binding, vnode)
if (!el._assign) {
el._assign = () => {}
}
}
extend = function patchedBootstrapVueExtend(definition) {
if (typeof definition === 'object' && definition.render && !definition.__alreadyPatched) {
const originalRender = definition.render
definition.__alreadyPatched = true
definition.render = function(h) {
const patchedH = function(tag, dataObjOrChildren, rawSlots) {
const slots =
rawSlots === undefined
? []
: [Array.isArray(rawSlots) ? rawSlots.filter(Boolean) : rawSlots]
const isTag = typeof tag === 'string' && !KNOWN_COMPONENTS.includes(tag)
const isSecondArgumentDataObject =
dataObjOrChildren &&
typeof dataObjOrChildren === 'object' &&
!Array.isArray(dataObjOrChildren)
if (!isSecondArgumentDataObject) {
return h(tag, dataObjOrChildren, ...slots)
}
const { attrs, props, ...restData } = dataObjOrChildren
const normalizedData = {
...restData,
attrs,
props: isTag ? {} : props
}
if (tag === 'router-link' && !normalizedData.slots && !normalizedData.scopedSlots) {
// terrible workaround to fix router-link rendering with compat vue-router
normalizedData.scopedSlots = { $hasNormal: () => {} }
}
return h(tag, normalizedData, ...slots)
}
if (definition.functional) {
const ctx = arguments[1]
const patchedCtx = { ...ctx }
patchedCtx.data = {
attrs: { ...(ctx.data.attrs || {}) },
props: { ...(ctx.data.props || {}) }
}
Object.keys(ctx.data || {}).forEach(key => {
if (ALLOWED_FIELDS_IN_DATA.includes(key)) {
patchedCtx.data[key] = ctx.data[key]
} else if (key in ctx.props) {
patchedCtx.data.props[key] = ctx.data[key]
} else if (!key.startsWith('on')) {
patchedCtx.data.attrs[key] = ctx.data[key]
}
})
const IGNORED_CHILDREN_KEYS = ['_ctx']
const children = ctx.children?.default?.() || ctx.children
if (
children &&
Object.keys(patchedCtx.children).filter(k => !IGNORED_CHILDREN_KEYS.includes(k))
.length === 0
) {
delete patchedCtx.children
} else {
patchedCtx.children = children
}
patchedCtx.data.on = ctx.listeners
return originalRender.call(this, patchedH, patchedCtx)
}
return originalRender.call(this, patchedH)
}
}
return originalExtend.call(this, definition)
}.bind(Vue)
}
const nextTick = Vue.nextTick
export { COMPONENT_UID_KEY, Vue, mergeData, isVue3, nextTick, extend }