@vue/runtime-dom 3.2.39 → 3.2.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime-dom.cjs.js +1575 -1607
- package/dist/runtime-dom.cjs.prod.js +1469 -1502
- package/dist/runtime-dom.esm-browser.js +10720 -10724
- package/dist/runtime-dom.esm-browser.prod.js +1 -1
- package/dist/runtime-dom.esm-bundler.js +1630 -1662
- package/dist/runtime-dom.global.js +10702 -10706
- package/dist/runtime-dom.global.prod.js +1 -1
- package/package.json +3 -3
|
@@ -2,1698 +2,1666 @@ import { camelize, warn, callWithAsyncErrorHandling, defineComponent, nextTick,
|
|
|
2
2
|
export * from '@vue/runtime-core';
|
|
3
3
|
import { isString, isArray, hyphenate, capitalize, isSpecialBooleanAttr, includeBooleanAttr, isOn, isModelListener, isFunction, toNumber, camelize as camelize$1, extend, EMPTY_OBJ, isObject, invokeArrayFns, looseIndexOf, isSet, looseEqual, isHTMLTag, isSVGTag } from '@vue/shared';
|
|
4
4
|
|
|
5
|
-
const svgNS = 'http://www.w3.org/2000/svg';
|
|
6
|
-
const doc = (typeof document !== 'undefined' ? document : null);
|
|
7
|
-
const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
|
|
8
|
-
const nodeOps = {
|
|
9
|
-
insert: (child, parent, anchor) => {
|
|
10
|
-
parent.insertBefore(child, anchor || null);
|
|
11
|
-
},
|
|
12
|
-
remove: child => {
|
|
13
|
-
const parent = child.parentNode;
|
|
14
|
-
if (parent) {
|
|
15
|
-
parent.removeChild(child);
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
createElement: (tag, isSVG, is, props) => {
|
|
19
|
-
const el = isSVG
|
|
20
|
-
? doc.createElementNS(svgNS, tag)
|
|
21
|
-
: doc.createElement(tag, is ? { is } : undefined);
|
|
22
|
-
if (tag === 'select' && props && props.multiple != null) {
|
|
23
|
-
el.setAttribute('multiple', props.multiple);
|
|
24
|
-
}
|
|
25
|
-
return el;
|
|
26
|
-
},
|
|
27
|
-
createText: text => doc.createTextNode(text),
|
|
28
|
-
createComment: text => doc.createComment(text),
|
|
29
|
-
setText: (node, text) => {
|
|
30
|
-
node.nodeValue = text;
|
|
31
|
-
},
|
|
32
|
-
setElementText: (el, text) => {
|
|
33
|
-
el.textContent = text;
|
|
34
|
-
},
|
|
35
|
-
parentNode: node => node.parentNode,
|
|
36
|
-
nextSibling: node => node.nextSibling,
|
|
37
|
-
querySelector: selector => doc.querySelector(selector),
|
|
38
|
-
setScopeId(el, id) {
|
|
39
|
-
el.setAttribute(id, '');
|
|
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
|
-
// remove outer svg wrapper
|
|
81
|
-
const wrapper = template.firstChild;
|
|
82
|
-
while (wrapper.firstChild) {
|
|
83
|
-
template.appendChild(wrapper.firstChild);
|
|
84
|
-
}
|
|
85
|
-
template.removeChild(wrapper);
|
|
86
|
-
}
|
|
87
|
-
parent.insertBefore(template, anchor);
|
|
88
|
-
}
|
|
89
|
-
return [
|
|
90
|
-
// first
|
|
91
|
-
before ? before.nextSibling : parent.firstChild,
|
|
92
|
-
// last
|
|
93
|
-
anchor ? anchor.previousSibling : parent.lastChild
|
|
94
|
-
];
|
|
95
|
-
}
|
|
5
|
+
const svgNS = 'http://www.w3.org/2000/svg';
|
|
6
|
+
const doc = (typeof document !== 'undefined' ? document : null);
|
|
7
|
+
const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
|
|
8
|
+
const nodeOps = {
|
|
9
|
+
insert: (child, parent, anchor) => {
|
|
10
|
+
parent.insertBefore(child, anchor || null);
|
|
11
|
+
},
|
|
12
|
+
remove: child => {
|
|
13
|
+
const parent = child.parentNode;
|
|
14
|
+
if (parent) {
|
|
15
|
+
parent.removeChild(child);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
createElement: (tag, isSVG, is, props) => {
|
|
19
|
+
const el = isSVG
|
|
20
|
+
? doc.createElementNS(svgNS, tag)
|
|
21
|
+
: doc.createElement(tag, is ? { is } : undefined);
|
|
22
|
+
if (tag === 'select' && props && props.multiple != null) {
|
|
23
|
+
el.setAttribute('multiple', props.multiple);
|
|
24
|
+
}
|
|
25
|
+
return el;
|
|
26
|
+
},
|
|
27
|
+
createText: text => doc.createTextNode(text),
|
|
28
|
+
createComment: text => doc.createComment(text),
|
|
29
|
+
setText: (node, text) => {
|
|
30
|
+
node.nodeValue = text;
|
|
31
|
+
},
|
|
32
|
+
setElementText: (el, text) => {
|
|
33
|
+
el.textContent = text;
|
|
34
|
+
},
|
|
35
|
+
parentNode: node => node.parentNode,
|
|
36
|
+
nextSibling: node => node.nextSibling,
|
|
37
|
+
querySelector: selector => doc.querySelector(selector),
|
|
38
|
+
setScopeId(el, id) {
|
|
39
|
+
el.setAttribute(id, '');
|
|
40
|
+
},
|
|
41
|
+
// __UNSAFE__
|
|
42
|
+
// Reason: innerHTML.
|
|
43
|
+
// Static content here can only come from compiled templates.
|
|
44
|
+
// As long as the user only uses trusted templates, this is safe.
|
|
45
|
+
insertStaticContent(content, parent, anchor, isSVG, start, end) {
|
|
46
|
+
// <parent> before | first ... last | anchor </parent>
|
|
47
|
+
const before = anchor ? anchor.previousSibling : parent.lastChild;
|
|
48
|
+
// #5308 can only take cached path if:
|
|
49
|
+
// - has a single root node
|
|
50
|
+
// - nextSibling info is still available
|
|
51
|
+
if (start && (start === end || start.nextSibling)) {
|
|
52
|
+
// cached
|
|
53
|
+
while (true) {
|
|
54
|
+
parent.insertBefore(start.cloneNode(true), anchor);
|
|
55
|
+
if (start === end || !(start = start.nextSibling))
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// fresh insert
|
|
61
|
+
templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
|
|
62
|
+
const template = templateContainer.content;
|
|
63
|
+
if (isSVG) {
|
|
64
|
+
// remove outer svg wrapper
|
|
65
|
+
const wrapper = template.firstChild;
|
|
66
|
+
while (wrapper.firstChild) {
|
|
67
|
+
template.appendChild(wrapper.firstChild);
|
|
68
|
+
}
|
|
69
|
+
template.removeChild(wrapper);
|
|
70
|
+
}
|
|
71
|
+
parent.insertBefore(template, anchor);
|
|
72
|
+
}
|
|
73
|
+
return [
|
|
74
|
+
// first
|
|
75
|
+
before ? before.nextSibling : parent.firstChild,
|
|
76
|
+
// last
|
|
77
|
+
anchor ? anchor.previousSibling : parent.lastChild
|
|
78
|
+
];
|
|
79
|
+
}
|
|
96
80
|
};
|
|
97
81
|
|
|
98
|
-
// compiler should normalize class + :class bindings on the same element
|
|
99
|
-
// into a single binding ['staticClass', dynamic]
|
|
100
|
-
function patchClass(el, value, isSVG) {
|
|
101
|
-
// directly setting className should be faster than setAttribute in theory
|
|
102
|
-
// if this is an element during a transition, take the temporary transition
|
|
103
|
-
// classes into account.
|
|
104
|
-
const transitionClasses = el._vtc;
|
|
105
|
-
if (transitionClasses) {
|
|
106
|
-
value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
|
|
107
|
-
}
|
|
108
|
-
if (value == null) {
|
|
109
|
-
el.removeAttribute('class');
|
|
110
|
-
}
|
|
111
|
-
else if (isSVG) {
|
|
112
|
-
el.setAttribute('class', value);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
el.className = value;
|
|
116
|
-
}
|
|
82
|
+
// compiler should normalize class + :class bindings on the same element
|
|
83
|
+
// into a single binding ['staticClass', dynamic]
|
|
84
|
+
function patchClass(el, value, isSVG) {
|
|
85
|
+
// directly setting className should be faster than setAttribute in theory
|
|
86
|
+
// if this is an element during a transition, take the temporary transition
|
|
87
|
+
// classes into account.
|
|
88
|
+
const transitionClasses = el._vtc;
|
|
89
|
+
if (transitionClasses) {
|
|
90
|
+
value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
|
|
91
|
+
}
|
|
92
|
+
if (value == null) {
|
|
93
|
+
el.removeAttribute('class');
|
|
94
|
+
}
|
|
95
|
+
else if (isSVG) {
|
|
96
|
+
el.setAttribute('class', value);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
el.className = value;
|
|
100
|
+
}
|
|
117
101
|
}
|
|
118
102
|
|
|
119
|
-
function patchStyle(el, prev, next) {
|
|
120
|
-
const style = el.style;
|
|
121
|
-
const isCssString = isString(next);
|
|
122
|
-
if (next && !isCssString) {
|
|
123
|
-
for (const key in next) {
|
|
124
|
-
setStyle(style, key, next[key]);
|
|
125
|
-
}
|
|
126
|
-
if (prev && !isString(prev)) {
|
|
127
|
-
for (const key in prev) {
|
|
128
|
-
if (next[key] == null) {
|
|
129
|
-
setStyle(style, key, '');
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
const currentDisplay = style.display;
|
|
136
|
-
if (isCssString) {
|
|
137
|
-
if (prev !== next) {
|
|
138
|
-
style.cssText = next;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else if (prev) {
|
|
142
|
-
el.removeAttribute('style');
|
|
143
|
-
}
|
|
144
|
-
// indicates that the `display` of the element is controlled by `v-show`,
|
|
145
|
-
// so we always keep the current `display` value regardless of the `style`
|
|
146
|
-
// value, thus handing over control to `v-show`.
|
|
147
|
-
if ('_vod' in el) {
|
|
148
|
-
style.display = currentDisplay;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const importantRE = /\s*!important$/;
|
|
153
|
-
function setStyle(style, name, val) {
|
|
154
|
-
if (isArray(val)) {
|
|
155
|
-
val.forEach(v => setStyle(style, name, v));
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
if (val == null)
|
|
159
|
-
val = '';
|
|
160
|
-
if (name.startsWith('--')) {
|
|
161
|
-
// custom property definition
|
|
162
|
-
style.setProperty(name, val);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
const prefixed = autoPrefix(style, name);
|
|
166
|
-
if (importantRE.test(val)) {
|
|
167
|
-
// !important
|
|
168
|
-
style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
style[prefixed] = val;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const prefixes = ['Webkit', 'Moz', 'ms'];
|
|
177
|
-
const prefixCache = {};
|
|
178
|
-
function autoPrefix(style, rawName) {
|
|
179
|
-
const cached = prefixCache[rawName];
|
|
180
|
-
if (cached) {
|
|
181
|
-
return cached;
|
|
182
|
-
}
|
|
183
|
-
let name = camelize(rawName);
|
|
184
|
-
if (name !== 'filter' && name in style) {
|
|
185
|
-
return (prefixCache[rawName] = name);
|
|
186
|
-
}
|
|
187
|
-
name = capitalize(name);
|
|
188
|
-
for (let i = 0; i < prefixes.length; i++) {
|
|
189
|
-
const prefixed = prefixes[i] + name;
|
|
190
|
-
if (prefixed in style) {
|
|
191
|
-
return (prefixCache[rawName] = prefixed);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return rawName;
|
|
103
|
+
function patchStyle(el, prev, next) {
|
|
104
|
+
const style = el.style;
|
|
105
|
+
const isCssString = isString(next);
|
|
106
|
+
if (next && !isCssString) {
|
|
107
|
+
for (const key in next) {
|
|
108
|
+
setStyle(style, key, next[key]);
|
|
109
|
+
}
|
|
110
|
+
if (prev && !isString(prev)) {
|
|
111
|
+
for (const key in prev) {
|
|
112
|
+
if (next[key] == null) {
|
|
113
|
+
setStyle(style, key, '');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const currentDisplay = style.display;
|
|
120
|
+
if (isCssString) {
|
|
121
|
+
if (prev !== next) {
|
|
122
|
+
style.cssText = next;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if (prev) {
|
|
126
|
+
el.removeAttribute('style');
|
|
127
|
+
}
|
|
128
|
+
// indicates that the `display` of the element is controlled by `v-show`,
|
|
129
|
+
// so we always keep the current `display` value regardless of the `style`
|
|
130
|
+
// value, thus handing over control to `v-show`.
|
|
131
|
+
if ('_vod' in el) {
|
|
132
|
+
style.display = currentDisplay;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const importantRE = /\s*!important$/;
|
|
137
|
+
function setStyle(style, name, val) {
|
|
138
|
+
if (isArray(val)) {
|
|
139
|
+
val.forEach(v => setStyle(style, name, v));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
if (val == null)
|
|
143
|
+
val = '';
|
|
144
|
+
if (name.startsWith('--')) {
|
|
145
|
+
// custom property definition
|
|
146
|
+
style.setProperty(name, val);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const prefixed = autoPrefix(style, name);
|
|
150
|
+
if (importantRE.test(val)) {
|
|
151
|
+
// !important
|
|
152
|
+
style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
style[prefixed] = val;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const prefixes = ['Webkit', 'Moz', 'ms'];
|
|
161
|
+
const prefixCache = {};
|
|
162
|
+
function autoPrefix(style, rawName) {
|
|
163
|
+
const cached = prefixCache[rawName];
|
|
164
|
+
if (cached) {
|
|
165
|
+
return cached;
|
|
166
|
+
}
|
|
167
|
+
let name = camelize(rawName);
|
|
168
|
+
if (name !== 'filter' && name in style) {
|
|
169
|
+
return (prefixCache[rawName] = name);
|
|
170
|
+
}
|
|
171
|
+
name = capitalize(name);
|
|
172
|
+
for (let i = 0; i < prefixes.length; i++) {
|
|
173
|
+
const prefixed = prefixes[i] + name;
|
|
174
|
+
if (prefixed in style) {
|
|
175
|
+
return (prefixCache[rawName] = prefixed);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return rawName;
|
|
195
179
|
}
|
|
196
180
|
|
|
197
|
-
const xlinkNS = 'http://www.w3.org/1999/xlink';
|
|
198
|
-
function patchAttr(el, key, value, isSVG, instance) {
|
|
199
|
-
if (isSVG && key.startsWith('xlink:')) {
|
|
200
|
-
if (value == null) {
|
|
201
|
-
el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
el.setAttributeNS(xlinkNS, key, value);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
// note we are only checking boolean attributes that don't have a
|
|
209
|
-
// corresponding dom prop of the same name here.
|
|
210
|
-
const isBoolean = isSpecialBooleanAttr(key);
|
|
211
|
-
if (value == null || (isBoolean && !includeBooleanAttr(value))) {
|
|
212
|
-
el.removeAttribute(key);
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
el.setAttribute(key, isBoolean ? '' : value);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
181
|
+
const xlinkNS = 'http://www.w3.org/1999/xlink';
|
|
182
|
+
function patchAttr(el, key, value, isSVG, instance) {
|
|
183
|
+
if (isSVG && key.startsWith('xlink:')) {
|
|
184
|
+
if (value == null) {
|
|
185
|
+
el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
el.setAttributeNS(xlinkNS, key, value);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// note we are only checking boolean attributes that don't have a
|
|
193
|
+
// corresponding dom prop of the same name here.
|
|
194
|
+
const isBoolean = isSpecialBooleanAttr(key);
|
|
195
|
+
if (value == null || (isBoolean && !includeBooleanAttr(value))) {
|
|
196
|
+
el.removeAttribute(key);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
el.setAttribute(key, isBoolean ? '' : value);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
218
202
|
}
|
|
219
203
|
|
|
220
|
-
// __UNSAFE__
|
|
221
|
-
// functions. The user is responsible for using them with only trusted content.
|
|
222
|
-
function patchDOMProp(el, key, value,
|
|
223
|
-
// the following args are passed only due to potential innerHTML/textContent
|
|
224
|
-
// overriding existing VNodes, in which case the old tree must be properly
|
|
225
|
-
// unmounted.
|
|
226
|
-
prevChildren, parentComponent, parentSuspense, unmountChildren) {
|
|
227
|
-
if (key === 'innerHTML' || key === 'textContent') {
|
|
228
|
-
if (prevChildren) {
|
|
229
|
-
unmountChildren(prevChildren, parentComponent, parentSuspense);
|
|
230
|
-
}
|
|
231
|
-
el[key] = value == null ? '' : value;
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
if (key === 'value' &&
|
|
235
|
-
el.tagName !== 'PROGRESS' &&
|
|
236
|
-
// custom elements may use _value internally
|
|
237
|
-
!el.tagName.includes('-')) {
|
|
238
|
-
// store value as _value as well since
|
|
239
|
-
// non-string values will be stringified.
|
|
240
|
-
el._value = value;
|
|
241
|
-
const newValue = value == null ? '' : value;
|
|
242
|
-
if (el.value !== newValue ||
|
|
243
|
-
// #4956: always set for OPTION elements because its value falls back to
|
|
244
|
-
// textContent if no value attribute is present. And setting .value for
|
|
245
|
-
// OPTION has no side effect
|
|
246
|
-
el.tagName === 'OPTION') {
|
|
247
|
-
el.value = newValue;
|
|
248
|
-
}
|
|
249
|
-
if (value == null) {
|
|
250
|
-
el.removeAttribute(key);
|
|
251
|
-
}
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
let needRemove = false;
|
|
255
|
-
if (value === '' || value == null) {
|
|
256
|
-
const type = typeof el[key];
|
|
257
|
-
if (type === 'boolean') {
|
|
258
|
-
// e.g. <select multiple> compiles to { multiple: '' }
|
|
259
|
-
value = includeBooleanAttr(value);
|
|
260
|
-
}
|
|
261
|
-
else if (value == null && type === 'string') {
|
|
262
|
-
// e.g. <div :id="null">
|
|
263
|
-
value = '';
|
|
264
|
-
needRemove = true;
|
|
265
|
-
}
|
|
266
|
-
else if (type === 'number') {
|
|
267
|
-
// e.g. <img :width="null">
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
// some properties
|
|
274
|
-
//
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if ((process.env.NODE_ENV !== 'production')) {
|
|
281
|
-
warn(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
|
|
282
|
-
`value ${value} is invalid.`, e);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
needRemove && el.removeAttribute(key);
|
|
204
|
+
// __UNSAFE__
|
|
205
|
+
// functions. The user is responsible for using them with only trusted content.
|
|
206
|
+
function patchDOMProp(el, key, value,
|
|
207
|
+
// the following args are passed only due to potential innerHTML/textContent
|
|
208
|
+
// overriding existing VNodes, in which case the old tree must be properly
|
|
209
|
+
// unmounted.
|
|
210
|
+
prevChildren, parentComponent, parentSuspense, unmountChildren) {
|
|
211
|
+
if (key === 'innerHTML' || key === 'textContent') {
|
|
212
|
+
if (prevChildren) {
|
|
213
|
+
unmountChildren(prevChildren, parentComponent, parentSuspense);
|
|
214
|
+
}
|
|
215
|
+
el[key] = value == null ? '' : value;
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (key === 'value' &&
|
|
219
|
+
el.tagName !== 'PROGRESS' &&
|
|
220
|
+
// custom elements may use _value internally
|
|
221
|
+
!el.tagName.includes('-')) {
|
|
222
|
+
// store value as _value as well since
|
|
223
|
+
// non-string values will be stringified.
|
|
224
|
+
el._value = value;
|
|
225
|
+
const newValue = value == null ? '' : value;
|
|
226
|
+
if (el.value !== newValue ||
|
|
227
|
+
// #4956: always set for OPTION elements because its value falls back to
|
|
228
|
+
// textContent if no value attribute is present. And setting .value for
|
|
229
|
+
// OPTION has no side effect
|
|
230
|
+
el.tagName === 'OPTION') {
|
|
231
|
+
el.value = newValue;
|
|
232
|
+
}
|
|
233
|
+
if (value == null) {
|
|
234
|
+
el.removeAttribute(key);
|
|
235
|
+
}
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
let needRemove = false;
|
|
239
|
+
if (value === '' || value == null) {
|
|
240
|
+
const type = typeof el[key];
|
|
241
|
+
if (type === 'boolean') {
|
|
242
|
+
// e.g. <select multiple> compiles to { multiple: '' }
|
|
243
|
+
value = includeBooleanAttr(value);
|
|
244
|
+
}
|
|
245
|
+
else if (value == null && type === 'string') {
|
|
246
|
+
// e.g. <div :id="null">
|
|
247
|
+
value = '';
|
|
248
|
+
needRemove = true;
|
|
249
|
+
}
|
|
250
|
+
else if (type === 'number') {
|
|
251
|
+
// e.g. <img :width="null">
|
|
252
|
+
value = 0;
|
|
253
|
+
needRemove = true;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// some properties perform value validation and throw,
|
|
257
|
+
// some properties has getter, no setter, will error in 'use strict'
|
|
258
|
+
// eg. <select :type="null"></select> <select :willValidate="null"></select>
|
|
259
|
+
try {
|
|
260
|
+
el[key] = value;
|
|
261
|
+
}
|
|
262
|
+
catch (e) {
|
|
263
|
+
// do not warn if value is auto-coerced from nullish values
|
|
264
|
+
if ((process.env.NODE_ENV !== 'production') && !needRemove) {
|
|
265
|
+
warn(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
|
|
266
|
+
`value ${value} is invalid.`, e);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
needRemove && el.removeAttribute(key);
|
|
286
270
|
}
|
|
287
271
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
//
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
invoker.value = initialValue;
|
|
374
|
-
invoker.attached = getNow();
|
|
375
|
-
return invoker;
|
|
376
|
-
}
|
|
377
|
-
function patchStopImmediatePropagation(e, value) {
|
|
378
|
-
if (isArray(value)) {
|
|
379
|
-
const originalStop = e.stopImmediatePropagation;
|
|
380
|
-
e.stopImmediatePropagation = () => {
|
|
381
|
-
originalStop.call(e);
|
|
382
|
-
e._stopped = true;
|
|
383
|
-
};
|
|
384
|
-
return value.map(fn => (e) => !e._stopped && fn && fn(e));
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
return value;
|
|
388
|
-
}
|
|
272
|
+
function addEventListener(el, event, handler, options) {
|
|
273
|
+
el.addEventListener(event, handler, options);
|
|
274
|
+
}
|
|
275
|
+
function removeEventListener(el, event, handler, options) {
|
|
276
|
+
el.removeEventListener(event, handler, options);
|
|
277
|
+
}
|
|
278
|
+
function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
|
|
279
|
+
// vei = vue event invokers
|
|
280
|
+
const invokers = el._vei || (el._vei = {});
|
|
281
|
+
const existingInvoker = invokers[rawName];
|
|
282
|
+
if (nextValue && existingInvoker) {
|
|
283
|
+
// patch
|
|
284
|
+
existingInvoker.value = nextValue;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
const [name, options] = parseName(rawName);
|
|
288
|
+
if (nextValue) {
|
|
289
|
+
// add
|
|
290
|
+
const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
|
|
291
|
+
addEventListener(el, name, invoker, options);
|
|
292
|
+
}
|
|
293
|
+
else if (existingInvoker) {
|
|
294
|
+
// remove
|
|
295
|
+
removeEventListener(el, name, existingInvoker, options);
|
|
296
|
+
invokers[rawName] = undefined;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const optionsModifierRE = /(?:Once|Passive|Capture)$/;
|
|
301
|
+
function parseName(name) {
|
|
302
|
+
let options;
|
|
303
|
+
if (optionsModifierRE.test(name)) {
|
|
304
|
+
options = {};
|
|
305
|
+
let m;
|
|
306
|
+
while ((m = name.match(optionsModifierRE))) {
|
|
307
|
+
name = name.slice(0, name.length - m[0].length);
|
|
308
|
+
options[m[0].toLowerCase()] = true;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const event = name[2] === ':' ? name.slice(3) : hyphenate(name.slice(2));
|
|
312
|
+
return [event, options];
|
|
313
|
+
}
|
|
314
|
+
// To avoid the overhead of repeatedly calling Date.now(), we cache
|
|
315
|
+
// and use the same timestamp for all event listeners attached in the same tick.
|
|
316
|
+
let cachedNow = 0;
|
|
317
|
+
const p = /*#__PURE__*/ Promise.resolve();
|
|
318
|
+
const getNow = () => cachedNow || (p.then(() => (cachedNow = 0)), (cachedNow = Date.now()));
|
|
319
|
+
function createInvoker(initialValue, instance) {
|
|
320
|
+
const invoker = (e) => {
|
|
321
|
+
// async edge case vuejs/vue#6566
|
|
322
|
+
// inner click event triggers patch, event handler
|
|
323
|
+
// attached to outer element during patch, and triggered again. This
|
|
324
|
+
// happens because browsers fire microtask ticks between event propagation.
|
|
325
|
+
// this no longer happens for templates in Vue 3, but could still be
|
|
326
|
+
// theoretically possible for hand-written render functions.
|
|
327
|
+
// the solution: we save the timestamp when a handler is attached,
|
|
328
|
+
// and also attach the timestamp to any event that was handled by vue
|
|
329
|
+
// for the first time (to avoid inconsistent event timestamp implementations
|
|
330
|
+
// or events fired from iframes, e.g. #2513)
|
|
331
|
+
// The handler would only fire if the event passed to it was fired
|
|
332
|
+
// AFTER it was attached.
|
|
333
|
+
if (!e._vts) {
|
|
334
|
+
e._vts = Date.now();
|
|
335
|
+
}
|
|
336
|
+
else if (e._vts <= invoker.attached) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* ErrorCodes.NATIVE_EVENT_HANDLER */, [e]);
|
|
340
|
+
};
|
|
341
|
+
invoker.value = initialValue;
|
|
342
|
+
invoker.attached = getNow();
|
|
343
|
+
return invoker;
|
|
344
|
+
}
|
|
345
|
+
function patchStopImmediatePropagation(e, value) {
|
|
346
|
+
if (isArray(value)) {
|
|
347
|
+
const originalStop = e.stopImmediatePropagation;
|
|
348
|
+
e.stopImmediatePropagation = () => {
|
|
349
|
+
originalStop.call(e);
|
|
350
|
+
e._stopped = true;
|
|
351
|
+
};
|
|
352
|
+
return value.map(fn => (e) => !e._stopped && fn && fn(e));
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
return value;
|
|
356
|
+
}
|
|
389
357
|
}
|
|
390
358
|
|
|
391
|
-
const nativeOnRE = /^on[a-z]/;
|
|
392
|
-
const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
|
|
393
|
-
if (key === 'class') {
|
|
394
|
-
patchClass(el, nextValue, isSVG);
|
|
395
|
-
}
|
|
396
|
-
else if (key === 'style') {
|
|
397
|
-
patchStyle(el, prevValue, nextValue);
|
|
398
|
-
}
|
|
399
|
-
else if (isOn(key)) {
|
|
400
|
-
// ignore v-model listeners
|
|
401
|
-
if (!isModelListener(key)) {
|
|
402
|
-
patchEvent(el, key, prevValue, nextValue, parentComponent);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
else if (key[0] === '.'
|
|
406
|
-
? ((key = key.slice(1)), true)
|
|
407
|
-
: key[0] === '^'
|
|
408
|
-
? ((key = key.slice(1)), false)
|
|
409
|
-
: shouldSetAsProp(el, key, nextValue, isSVG)) {
|
|
410
|
-
patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
// special case for <input v-model type="checkbox"> with
|
|
414
|
-
// :true-value & :false-value
|
|
415
|
-
// store value as dom properties since non-string values will be
|
|
416
|
-
// stringified.
|
|
417
|
-
if (key === 'true-value') {
|
|
418
|
-
el._trueValue = nextValue;
|
|
419
|
-
}
|
|
420
|
-
else if (key === 'false-value') {
|
|
421
|
-
el._falseValue = nextValue;
|
|
422
|
-
}
|
|
423
|
-
patchAttr(el, key, nextValue, isSVG);
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
function shouldSetAsProp(el, key, value, isSVG) {
|
|
427
|
-
if (isSVG) {
|
|
428
|
-
// most keys must be set as attribute on svg elements to work
|
|
429
|
-
// ...except innerHTML & textContent
|
|
430
|
-
if (key === 'innerHTML' || key === 'textContent') {
|
|
431
|
-
return true;
|
|
432
|
-
}
|
|
433
|
-
// or native onclick with function values
|
|
434
|
-
if (key in el && nativeOnRE.test(key) && isFunction(value)) {
|
|
435
|
-
return true;
|
|
436
|
-
}
|
|
437
|
-
return false;
|
|
438
|
-
}
|
|
439
|
-
// these are enumerated attrs, however their corresponding DOM properties
|
|
440
|
-
// are actually booleans - this leads to setting it with a string "false"
|
|
441
|
-
// value leading it to be coerced to `true`, so we need to always treat
|
|
442
|
-
// them as attributes.
|
|
443
|
-
// Note that `contentEditable` doesn't have this problem: its DOM
|
|
444
|
-
// property is also enumerated string values.
|
|
445
|
-
if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
|
|
446
|
-
return false;
|
|
447
|
-
}
|
|
448
|
-
// #1787, #2840 form property on form elements is readonly and must be set as
|
|
449
|
-
// attribute.
|
|
450
|
-
if (key === 'form') {
|
|
451
|
-
return false;
|
|
452
|
-
}
|
|
453
|
-
// #1526 <input list> must be set as attribute
|
|
454
|
-
if (key === 'list' && el.tagName === 'INPUT') {
|
|
455
|
-
return false;
|
|
456
|
-
}
|
|
457
|
-
// #2766 <textarea type> must be set as attribute
|
|
458
|
-
if (key === 'type' && el.tagName === 'TEXTAREA') {
|
|
459
|
-
return false;
|
|
460
|
-
}
|
|
461
|
-
// native onclick with string value, must be set as attribute
|
|
462
|
-
if (nativeOnRE.test(key) && isString(value)) {
|
|
463
|
-
return false;
|
|
464
|
-
}
|
|
465
|
-
return key in el;
|
|
359
|
+
const nativeOnRE = /^on[a-z]/;
|
|
360
|
+
const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
|
|
361
|
+
if (key === 'class') {
|
|
362
|
+
patchClass(el, nextValue, isSVG);
|
|
363
|
+
}
|
|
364
|
+
else if (key === 'style') {
|
|
365
|
+
patchStyle(el, prevValue, nextValue);
|
|
366
|
+
}
|
|
367
|
+
else if (isOn(key)) {
|
|
368
|
+
// ignore v-model listeners
|
|
369
|
+
if (!isModelListener(key)) {
|
|
370
|
+
patchEvent(el, key, prevValue, nextValue, parentComponent);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
else if (key[0] === '.'
|
|
374
|
+
? ((key = key.slice(1)), true)
|
|
375
|
+
: key[0] === '^'
|
|
376
|
+
? ((key = key.slice(1)), false)
|
|
377
|
+
: shouldSetAsProp(el, key, nextValue, isSVG)) {
|
|
378
|
+
patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
// special case for <input v-model type="checkbox"> with
|
|
382
|
+
// :true-value & :false-value
|
|
383
|
+
// store value as dom properties since non-string values will be
|
|
384
|
+
// stringified.
|
|
385
|
+
if (key === 'true-value') {
|
|
386
|
+
el._trueValue = nextValue;
|
|
387
|
+
}
|
|
388
|
+
else if (key === 'false-value') {
|
|
389
|
+
el._falseValue = nextValue;
|
|
390
|
+
}
|
|
391
|
+
patchAttr(el, key, nextValue, isSVG);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
function shouldSetAsProp(el, key, value, isSVG) {
|
|
395
|
+
if (isSVG) {
|
|
396
|
+
// most keys must be set as attribute on svg elements to work
|
|
397
|
+
// ...except innerHTML & textContent
|
|
398
|
+
if (key === 'innerHTML' || key === 'textContent') {
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
// or native onclick with function values
|
|
402
|
+
if (key in el && nativeOnRE.test(key) && isFunction(value)) {
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
// these are enumerated attrs, however their corresponding DOM properties
|
|
408
|
+
// are actually booleans - this leads to setting it with a string "false"
|
|
409
|
+
// value leading it to be coerced to `true`, so we need to always treat
|
|
410
|
+
// them as attributes.
|
|
411
|
+
// Note that `contentEditable` doesn't have this problem: its DOM
|
|
412
|
+
// property is also enumerated string values.
|
|
413
|
+
if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
// #1787, #2840 form property on form elements is readonly and must be set as
|
|
417
|
+
// attribute.
|
|
418
|
+
if (key === 'form') {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
// #1526 <input list> must be set as attribute
|
|
422
|
+
if (key === 'list' && el.tagName === 'INPUT') {
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
// #2766 <textarea type> must be set as attribute
|
|
426
|
+
if (key === 'type' && el.tagName === 'TEXTAREA') {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
// native onclick with string value, must be set as attribute
|
|
430
|
+
if (nativeOnRE.test(key) && isString(value)) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
return key in el;
|
|
466
434
|
}
|
|
467
435
|
|
|
468
|
-
function defineCustomElement(options, hydrate) {
|
|
469
|
-
const Comp = defineComponent(options);
|
|
470
|
-
class VueCustomElement extends VueElement {
|
|
471
|
-
constructor(initialProps) {
|
|
472
|
-
super(Comp, initialProps, hydrate);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
VueCustomElement.def = Comp;
|
|
476
|
-
return VueCustomElement;
|
|
477
|
-
}
|
|
478
|
-
const defineSSRCustomElement = ((options) => {
|
|
479
|
-
// @ts-ignore
|
|
480
|
-
return defineCustomElement(options, hydrate);
|
|
481
|
-
});
|
|
482
|
-
const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
|
|
483
|
-
});
|
|
484
|
-
class VueElement extends BaseClass {
|
|
485
|
-
constructor(_def, _props = {}, hydrate) {
|
|
486
|
-
super();
|
|
487
|
-
this._def = _def;
|
|
488
|
-
this._props = _props;
|
|
489
|
-
/**
|
|
490
|
-
* @internal
|
|
491
|
-
*/
|
|
492
|
-
this._instance = null;
|
|
493
|
-
this._connected = false;
|
|
494
|
-
this._resolved = false;
|
|
495
|
-
this._numberProps = null;
|
|
496
|
-
if (this.shadowRoot && hydrate) {
|
|
497
|
-
hydrate(this._createVNode(), this.shadowRoot);
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
if ((process.env.NODE_ENV !== 'production') && this.shadowRoot) {
|
|
501
|
-
warn(`Custom element has pre-rendered declarative shadow root but is not ` +
|
|
502
|
-
`defined as hydratable. Use \`defineSSRCustomElement\`.`);
|
|
503
|
-
}
|
|
504
|
-
this.attachShadow({ mode: 'open' });
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
connectedCallback() {
|
|
508
|
-
this._connected = true;
|
|
509
|
-
if (!this._instance) {
|
|
510
|
-
this._resolveDef();
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
disconnectedCallback() {
|
|
514
|
-
this._connected = false;
|
|
515
|
-
nextTick(() => {
|
|
516
|
-
if (!this._connected) {
|
|
517
|
-
render(null, this.shadowRoot);
|
|
518
|
-
this._instance = null;
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* resolve inner component definition (handle possible async component)
|
|
524
|
-
*/
|
|
525
|
-
_resolveDef() {
|
|
526
|
-
if (this._resolved) {
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
this._resolved = true;
|
|
530
|
-
// set initial attrs
|
|
531
|
-
for (let i = 0; i < this.attributes.length; i++) {
|
|
532
|
-
this._setAttr(this.attributes[i].name);
|
|
533
|
-
}
|
|
534
|
-
// watch future attr changes
|
|
535
|
-
new MutationObserver(mutations => {
|
|
536
|
-
for (const m of mutations) {
|
|
537
|
-
this._setAttr(m.attributeName);
|
|
538
|
-
}
|
|
539
|
-
}).observe(this, { attributes: true });
|
|
540
|
-
const resolve = (def) => {
|
|
541
|
-
const { props, styles } = def;
|
|
542
|
-
const hasOptions = !isArray(props);
|
|
543
|
-
const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
|
|
544
|
-
// cast Number-type props set before resolve
|
|
545
|
-
let numberProps;
|
|
546
|
-
if (hasOptions) {
|
|
547
|
-
for (const key in this._props) {
|
|
548
|
-
const opt = props[key];
|
|
549
|
-
if (opt === Number || (opt && opt.type === Number)) {
|
|
550
|
-
this._props[key] = toNumber(this._props[key]);
|
|
551
|
-
(numberProps || (numberProps = Object.create(null)))[key] = true;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
this._numberProps = numberProps;
|
|
556
|
-
// check if there are props set pre-upgrade or connect
|
|
557
|
-
for (const key of Object.keys(this)) {
|
|
558
|
-
if (key[0] !== '_') {
|
|
559
|
-
this._setProp(key, this[key], true, false);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
// defining getter/setters on prototype
|
|
563
|
-
for (const key of rawKeys.map(camelize$1)) {
|
|
564
|
-
Object.defineProperty(this, key, {
|
|
565
|
-
get() {
|
|
566
|
-
return this._getProp(key);
|
|
567
|
-
},
|
|
568
|
-
set(val) {
|
|
569
|
-
this._setProp(key, val);
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
// apply CSS
|
|
574
|
-
this._applyStyles(styles);
|
|
575
|
-
// initial render
|
|
576
|
-
this._update();
|
|
577
|
-
};
|
|
578
|
-
const asyncDef = this._def.__asyncLoader;
|
|
579
|
-
if (asyncDef) {
|
|
580
|
-
asyncDef().then(resolve);
|
|
581
|
-
}
|
|
582
|
-
else {
|
|
583
|
-
resolve(this._def);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
_setAttr(key) {
|
|
587
|
-
let value = this.getAttribute(key);
|
|
588
|
-
if (this._numberProps && this._numberProps[key]) {
|
|
589
|
-
value = toNumber(value);
|
|
590
|
-
}
|
|
591
|
-
this._setProp(camelize$1(key), value, false);
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* @internal
|
|
595
|
-
*/
|
|
596
|
-
_getProp(key) {
|
|
597
|
-
return this._props[key];
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* @internal
|
|
601
|
-
*/
|
|
602
|
-
_setProp(key, val, shouldReflect = true, shouldUpdate = true) {
|
|
603
|
-
if (val !== this._props[key]) {
|
|
604
|
-
this._props[key] = val;
|
|
605
|
-
if (shouldUpdate && this._instance) {
|
|
606
|
-
this._update();
|
|
607
|
-
}
|
|
608
|
-
// reflect
|
|
609
|
-
if (shouldReflect) {
|
|
610
|
-
if (val === true) {
|
|
611
|
-
this.setAttribute(hyphenate(key), '');
|
|
612
|
-
}
|
|
613
|
-
else if (typeof val === 'string' || typeof val === 'number') {
|
|
614
|
-
this.setAttribute(hyphenate(key), val + '');
|
|
615
|
-
}
|
|
616
|
-
else if (!val) {
|
|
617
|
-
this.removeAttribute(hyphenate(key));
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
_update() {
|
|
623
|
-
render(this._createVNode(), this.shadowRoot);
|
|
624
|
-
}
|
|
625
|
-
_createVNode() {
|
|
626
|
-
const vnode = createVNode(this._def, extend({}, this._props));
|
|
627
|
-
if (!this._instance) {
|
|
628
|
-
vnode.ce = instance => {
|
|
629
|
-
this._instance = instance;
|
|
630
|
-
instance.isCE = true;
|
|
631
|
-
// HMR
|
|
632
|
-
if ((process.env.NODE_ENV !== 'production')) {
|
|
633
|
-
instance.ceReload = newStyles => {
|
|
634
|
-
// always reset styles
|
|
635
|
-
if (this._styles) {
|
|
636
|
-
this._styles.forEach(s => this.shadowRoot.removeChild(s));
|
|
637
|
-
this._styles.length = 0;
|
|
638
|
-
}
|
|
639
|
-
this._applyStyles(newStyles);
|
|
640
|
-
// if this is an async component, ceReload is called from the inner
|
|
641
|
-
// component so no need to reload the async wrapper
|
|
642
|
-
if (!this._def.__asyncLoader) {
|
|
643
|
-
// reload
|
|
644
|
-
this._instance = null;
|
|
645
|
-
this._update();
|
|
646
|
-
}
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
// intercept emit
|
|
650
|
-
instance.emit = (event, ...args) => {
|
|
651
|
-
this.dispatchEvent(new CustomEvent(event, {
|
|
652
|
-
detail: args
|
|
653
|
-
}));
|
|
654
|
-
};
|
|
655
|
-
// locate nearest Vue custom element parent for provide/inject
|
|
656
|
-
let parent = this;
|
|
657
|
-
while ((parent =
|
|
658
|
-
parent && (parent.parentNode || parent.host))) {
|
|
659
|
-
if (parent instanceof VueElement) {
|
|
660
|
-
instance.parent = parent._instance;
|
|
661
|
-
break;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
return vnode;
|
|
667
|
-
}
|
|
668
|
-
_applyStyles(styles) {
|
|
669
|
-
if (styles) {
|
|
670
|
-
styles.forEach(css => {
|
|
671
|
-
const s = document.createElement('style');
|
|
672
|
-
s.textContent = css;
|
|
673
|
-
this.shadowRoot.appendChild(s);
|
|
674
|
-
// record for HMR
|
|
675
|
-
if ((process.env.NODE_ENV !== 'production')) {
|
|
676
|
-
(this._styles || (this._styles = [])).push(s);
|
|
677
|
-
}
|
|
678
|
-
});
|
|
679
|
-
}
|
|
680
|
-
}
|
|
436
|
+
function defineCustomElement(options, hydrate) {
|
|
437
|
+
const Comp = defineComponent(options);
|
|
438
|
+
class VueCustomElement extends VueElement {
|
|
439
|
+
constructor(initialProps) {
|
|
440
|
+
super(Comp, initialProps, hydrate);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
VueCustomElement.def = Comp;
|
|
444
|
+
return VueCustomElement;
|
|
445
|
+
}
|
|
446
|
+
const defineSSRCustomElement = ((options) => {
|
|
447
|
+
// @ts-ignore
|
|
448
|
+
return defineCustomElement(options, hydrate);
|
|
449
|
+
});
|
|
450
|
+
const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
|
|
451
|
+
});
|
|
452
|
+
class VueElement extends BaseClass {
|
|
453
|
+
constructor(_def, _props = {}, hydrate) {
|
|
454
|
+
super();
|
|
455
|
+
this._def = _def;
|
|
456
|
+
this._props = _props;
|
|
457
|
+
/**
|
|
458
|
+
* @internal
|
|
459
|
+
*/
|
|
460
|
+
this._instance = null;
|
|
461
|
+
this._connected = false;
|
|
462
|
+
this._resolved = false;
|
|
463
|
+
this._numberProps = null;
|
|
464
|
+
if (this.shadowRoot && hydrate) {
|
|
465
|
+
hydrate(this._createVNode(), this.shadowRoot);
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
if ((process.env.NODE_ENV !== 'production') && this.shadowRoot) {
|
|
469
|
+
warn(`Custom element has pre-rendered declarative shadow root but is not ` +
|
|
470
|
+
`defined as hydratable. Use \`defineSSRCustomElement\`.`);
|
|
471
|
+
}
|
|
472
|
+
this.attachShadow({ mode: 'open' });
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
connectedCallback() {
|
|
476
|
+
this._connected = true;
|
|
477
|
+
if (!this._instance) {
|
|
478
|
+
this._resolveDef();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
disconnectedCallback() {
|
|
482
|
+
this._connected = false;
|
|
483
|
+
nextTick(() => {
|
|
484
|
+
if (!this._connected) {
|
|
485
|
+
render(null, this.shadowRoot);
|
|
486
|
+
this._instance = null;
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* resolve inner component definition (handle possible async component)
|
|
492
|
+
*/
|
|
493
|
+
_resolveDef() {
|
|
494
|
+
if (this._resolved) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
this._resolved = true;
|
|
498
|
+
// set initial attrs
|
|
499
|
+
for (let i = 0; i < this.attributes.length; i++) {
|
|
500
|
+
this._setAttr(this.attributes[i].name);
|
|
501
|
+
}
|
|
502
|
+
// watch future attr changes
|
|
503
|
+
new MutationObserver(mutations => {
|
|
504
|
+
for (const m of mutations) {
|
|
505
|
+
this._setAttr(m.attributeName);
|
|
506
|
+
}
|
|
507
|
+
}).observe(this, { attributes: true });
|
|
508
|
+
const resolve = (def) => {
|
|
509
|
+
const { props, styles } = def;
|
|
510
|
+
const hasOptions = !isArray(props);
|
|
511
|
+
const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
|
|
512
|
+
// cast Number-type props set before resolve
|
|
513
|
+
let numberProps;
|
|
514
|
+
if (hasOptions) {
|
|
515
|
+
for (const key in this._props) {
|
|
516
|
+
const opt = props[key];
|
|
517
|
+
if (opt === Number || (opt && opt.type === Number)) {
|
|
518
|
+
this._props[key] = toNumber(this._props[key]);
|
|
519
|
+
(numberProps || (numberProps = Object.create(null)))[key] = true;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
this._numberProps = numberProps;
|
|
524
|
+
// check if there are props set pre-upgrade or connect
|
|
525
|
+
for (const key of Object.keys(this)) {
|
|
526
|
+
if (key[0] !== '_') {
|
|
527
|
+
this._setProp(key, this[key], true, false);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
// defining getter/setters on prototype
|
|
531
|
+
for (const key of rawKeys.map(camelize$1)) {
|
|
532
|
+
Object.defineProperty(this, key, {
|
|
533
|
+
get() {
|
|
534
|
+
return this._getProp(key);
|
|
535
|
+
},
|
|
536
|
+
set(val) {
|
|
537
|
+
this._setProp(key, val);
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
// apply CSS
|
|
542
|
+
this._applyStyles(styles);
|
|
543
|
+
// initial render
|
|
544
|
+
this._update();
|
|
545
|
+
};
|
|
546
|
+
const asyncDef = this._def.__asyncLoader;
|
|
547
|
+
if (asyncDef) {
|
|
548
|
+
asyncDef().then(resolve);
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
resolve(this._def);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
_setAttr(key) {
|
|
555
|
+
let value = this.getAttribute(key);
|
|
556
|
+
if (this._numberProps && this._numberProps[key]) {
|
|
557
|
+
value = toNumber(value);
|
|
558
|
+
}
|
|
559
|
+
this._setProp(camelize$1(key), value, false);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* @internal
|
|
563
|
+
*/
|
|
564
|
+
_getProp(key) {
|
|
565
|
+
return this._props[key];
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* @internal
|
|
569
|
+
*/
|
|
570
|
+
_setProp(key, val, shouldReflect = true, shouldUpdate = true) {
|
|
571
|
+
if (val !== this._props[key]) {
|
|
572
|
+
this._props[key] = val;
|
|
573
|
+
if (shouldUpdate && this._instance) {
|
|
574
|
+
this._update();
|
|
575
|
+
}
|
|
576
|
+
// reflect
|
|
577
|
+
if (shouldReflect) {
|
|
578
|
+
if (val === true) {
|
|
579
|
+
this.setAttribute(hyphenate(key), '');
|
|
580
|
+
}
|
|
581
|
+
else if (typeof val === 'string' || typeof val === 'number') {
|
|
582
|
+
this.setAttribute(hyphenate(key), val + '');
|
|
583
|
+
}
|
|
584
|
+
else if (!val) {
|
|
585
|
+
this.removeAttribute(hyphenate(key));
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
_update() {
|
|
591
|
+
render(this._createVNode(), this.shadowRoot);
|
|
592
|
+
}
|
|
593
|
+
_createVNode() {
|
|
594
|
+
const vnode = createVNode(this._def, extend({}, this._props));
|
|
595
|
+
if (!this._instance) {
|
|
596
|
+
vnode.ce = instance => {
|
|
597
|
+
this._instance = instance;
|
|
598
|
+
instance.isCE = true;
|
|
599
|
+
// HMR
|
|
600
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
601
|
+
instance.ceReload = newStyles => {
|
|
602
|
+
// always reset styles
|
|
603
|
+
if (this._styles) {
|
|
604
|
+
this._styles.forEach(s => this.shadowRoot.removeChild(s));
|
|
605
|
+
this._styles.length = 0;
|
|
606
|
+
}
|
|
607
|
+
this._applyStyles(newStyles);
|
|
608
|
+
// if this is an async component, ceReload is called from the inner
|
|
609
|
+
// component so no need to reload the async wrapper
|
|
610
|
+
if (!this._def.__asyncLoader) {
|
|
611
|
+
// reload
|
|
612
|
+
this._instance = null;
|
|
613
|
+
this._update();
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
// intercept emit
|
|
618
|
+
instance.emit = (event, ...args) => {
|
|
619
|
+
this.dispatchEvent(new CustomEvent(event, {
|
|
620
|
+
detail: args
|
|
621
|
+
}));
|
|
622
|
+
};
|
|
623
|
+
// locate nearest Vue custom element parent for provide/inject
|
|
624
|
+
let parent = this;
|
|
625
|
+
while ((parent =
|
|
626
|
+
parent && (parent.parentNode || parent.host))) {
|
|
627
|
+
if (parent instanceof VueElement) {
|
|
628
|
+
instance.parent = parent._instance;
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
return vnode;
|
|
635
|
+
}
|
|
636
|
+
_applyStyles(styles) {
|
|
637
|
+
if (styles) {
|
|
638
|
+
styles.forEach(css => {
|
|
639
|
+
const s = document.createElement('style');
|
|
640
|
+
s.textContent = css;
|
|
641
|
+
this.shadowRoot.appendChild(s);
|
|
642
|
+
// record for HMR
|
|
643
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
644
|
+
(this._styles || (this._styles = [])).push(s);
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
}
|
|
681
649
|
}
|
|
682
650
|
|
|
683
|
-
function useCssModule(name = '$style') {
|
|
684
|
-
/* istanbul ignore else */
|
|
685
|
-
{
|
|
686
|
-
const instance = getCurrentInstance();
|
|
687
|
-
if (!instance) {
|
|
688
|
-
(process.env.NODE_ENV !== 'production') && warn(`useCssModule must be called inside setup()`);
|
|
689
|
-
return EMPTY_OBJ;
|
|
690
|
-
}
|
|
691
|
-
const modules = instance.type.__cssModules;
|
|
692
|
-
if (!modules) {
|
|
693
|
-
(process.env.NODE_ENV !== 'production') && warn(`Current instance does not have CSS modules injected.`);
|
|
694
|
-
return EMPTY_OBJ;
|
|
695
|
-
}
|
|
696
|
-
const mod = modules[name];
|
|
697
|
-
if (!mod) {
|
|
698
|
-
(process.env.NODE_ENV !== 'production') &&
|
|
699
|
-
warn(`Current instance does not have CSS module named "${name}".`);
|
|
700
|
-
return EMPTY_OBJ;
|
|
701
|
-
}
|
|
702
|
-
return mod;
|
|
703
|
-
}
|
|
651
|
+
function useCssModule(name = '$style') {
|
|
652
|
+
/* istanbul ignore else */
|
|
653
|
+
{
|
|
654
|
+
const instance = getCurrentInstance();
|
|
655
|
+
if (!instance) {
|
|
656
|
+
(process.env.NODE_ENV !== 'production') && warn(`useCssModule must be called inside setup()`);
|
|
657
|
+
return EMPTY_OBJ;
|
|
658
|
+
}
|
|
659
|
+
const modules = instance.type.__cssModules;
|
|
660
|
+
if (!modules) {
|
|
661
|
+
(process.env.NODE_ENV !== 'production') && warn(`Current instance does not have CSS modules injected.`);
|
|
662
|
+
return EMPTY_OBJ;
|
|
663
|
+
}
|
|
664
|
+
const mod = modules[name];
|
|
665
|
+
if (!mod) {
|
|
666
|
+
(process.env.NODE_ENV !== 'production') &&
|
|
667
|
+
warn(`Current instance does not have CSS module named "${name}".`);
|
|
668
|
+
return EMPTY_OBJ;
|
|
669
|
+
}
|
|
670
|
+
return mod;
|
|
671
|
+
}
|
|
704
672
|
}
|
|
705
673
|
|
|
706
|
-
/**
|
|
707
|
-
* Runtime helper for SFC's CSS variable injection feature.
|
|
708
|
-
* @private
|
|
709
|
-
*/
|
|
710
|
-
function useCssVars(getter) {
|
|
711
|
-
const instance = getCurrentInstance();
|
|
712
|
-
/* istanbul ignore next */
|
|
713
|
-
if (!instance) {
|
|
714
|
-
(process.env.NODE_ENV !== 'production') &&
|
|
715
|
-
warn(`useCssVars is called without current active component instance.`);
|
|
716
|
-
return;
|
|
717
|
-
}
|
|
718
|
-
const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
|
|
719
|
-
watchPostEffect(setVars);
|
|
720
|
-
onMounted(() => {
|
|
721
|
-
const ob = new MutationObserver(setVars);
|
|
722
|
-
ob.observe(instance.subTree.el.parentNode, { childList: true });
|
|
723
|
-
onUnmounted(() => ob.disconnect());
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
function setVarsOnVNode(vnode, vars) {
|
|
727
|
-
if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
|
|
728
|
-
const suspense = vnode.suspense;
|
|
729
|
-
vnode = suspense.activeBranch;
|
|
730
|
-
if (suspense.pendingBranch && !suspense.isHydrating) {
|
|
731
|
-
suspense.effects.push(() => {
|
|
732
|
-
setVarsOnVNode(suspense.activeBranch, vars);
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
// drill down HOCs until it's a non-component vnode
|
|
737
|
-
while (vnode.component) {
|
|
738
|
-
vnode = vnode.component.subTree;
|
|
739
|
-
}
|
|
740
|
-
if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && vnode.el) {
|
|
741
|
-
setVarsOnNode(vnode.el, vars);
|
|
742
|
-
}
|
|
743
|
-
else if (vnode.type === Fragment) {
|
|
744
|
-
vnode.children.forEach(c => setVarsOnVNode(c, vars));
|
|
745
|
-
}
|
|
746
|
-
else if (vnode.type === Static) {
|
|
747
|
-
let { el, anchor } = vnode;
|
|
748
|
-
while (el) {
|
|
749
|
-
setVarsOnNode(el, vars);
|
|
750
|
-
if (el === anchor)
|
|
751
|
-
break;
|
|
752
|
-
el = el.nextSibling;
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
function setVarsOnNode(el, vars) {
|
|
757
|
-
if (el.nodeType === 1) {
|
|
758
|
-
const style = el.style;
|
|
759
|
-
for (const key in vars) {
|
|
760
|
-
style.setProperty(`--${key}`, vars[key]);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
674
|
+
/**
|
|
675
|
+
* Runtime helper for SFC's CSS variable injection feature.
|
|
676
|
+
* @private
|
|
677
|
+
*/
|
|
678
|
+
function useCssVars(getter) {
|
|
679
|
+
const instance = getCurrentInstance();
|
|
680
|
+
/* istanbul ignore next */
|
|
681
|
+
if (!instance) {
|
|
682
|
+
(process.env.NODE_ENV !== 'production') &&
|
|
683
|
+
warn(`useCssVars is called without current active component instance.`);
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
|
|
687
|
+
watchPostEffect(setVars);
|
|
688
|
+
onMounted(() => {
|
|
689
|
+
const ob = new MutationObserver(setVars);
|
|
690
|
+
ob.observe(instance.subTree.el.parentNode, { childList: true });
|
|
691
|
+
onUnmounted(() => ob.disconnect());
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
function setVarsOnVNode(vnode, vars) {
|
|
695
|
+
if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
|
|
696
|
+
const suspense = vnode.suspense;
|
|
697
|
+
vnode = suspense.activeBranch;
|
|
698
|
+
if (suspense.pendingBranch && !suspense.isHydrating) {
|
|
699
|
+
suspense.effects.push(() => {
|
|
700
|
+
setVarsOnVNode(suspense.activeBranch, vars);
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
// drill down HOCs until it's a non-component vnode
|
|
705
|
+
while (vnode.component) {
|
|
706
|
+
vnode = vnode.component.subTree;
|
|
707
|
+
}
|
|
708
|
+
if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */ && vnode.el) {
|
|
709
|
+
setVarsOnNode(vnode.el, vars);
|
|
710
|
+
}
|
|
711
|
+
else if (vnode.type === Fragment) {
|
|
712
|
+
vnode.children.forEach(c => setVarsOnVNode(c, vars));
|
|
713
|
+
}
|
|
714
|
+
else if (vnode.type === Static) {
|
|
715
|
+
let { el, anchor } = vnode;
|
|
716
|
+
while (el) {
|
|
717
|
+
setVarsOnNode(el, vars);
|
|
718
|
+
if (el === anchor)
|
|
719
|
+
break;
|
|
720
|
+
el = el.nextSibling;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
function setVarsOnNode(el, vars) {
|
|
725
|
+
if (el.nodeType === 1) {
|
|
726
|
+
const style = el.style;
|
|
727
|
+
for (const key in vars) {
|
|
728
|
+
style.setProperty(`--${key}`, vars[key]);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
763
731
|
}
|
|
764
732
|
|
|
765
|
-
const TRANSITION = 'transition';
|
|
766
|
-
const ANIMATION = 'animation';
|
|
767
|
-
// DOM Transition is a higher-order-component based on the platform-agnostic
|
|
768
|
-
// base Transition component, with DOM-specific logic.
|
|
769
|
-
const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
|
|
770
|
-
Transition.displayName = 'Transition';
|
|
771
|
-
const DOMTransitionPropsValidators = {
|
|
772
|
-
name: String,
|
|
773
|
-
type: String,
|
|
774
|
-
css: {
|
|
775
|
-
type: Boolean,
|
|
776
|
-
default: true
|
|
777
|
-
},
|
|
778
|
-
duration: [String, Number, Object],
|
|
779
|
-
enterFromClass: String,
|
|
780
|
-
enterActiveClass: String,
|
|
781
|
-
enterToClass: String,
|
|
782
|
-
appearFromClass: String,
|
|
783
|
-
appearActiveClass: String,
|
|
784
|
-
appearToClass: String,
|
|
785
|
-
leaveFromClass: String,
|
|
786
|
-
leaveActiveClass: String,
|
|
787
|
-
leaveToClass: String
|
|
788
|
-
};
|
|
789
|
-
const TransitionPropsValidators = (Transition.props =
|
|
790
|
-
/*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
|
|
791
|
-
/**
|
|
792
|
-
* #3227 Incoming hooks may be merged into arrays when wrapping Transition
|
|
793
|
-
* with custom HOCs.
|
|
794
|
-
*/
|
|
795
|
-
const callHook = (hook, args = []) => {
|
|
796
|
-
if (isArray(hook)) {
|
|
797
|
-
hook.forEach(h => h(...args));
|
|
798
|
-
}
|
|
799
|
-
else if (hook) {
|
|
800
|
-
hook(...args);
|
|
801
|
-
}
|
|
802
|
-
};
|
|
803
|
-
/**
|
|
804
|
-
* Check if a hook expects a callback (2nd arg), which means the user
|
|
805
|
-
* intends to explicitly control the end of the transition.
|
|
806
|
-
*/
|
|
807
|
-
const hasExplicitCallback = (hook) => {
|
|
808
|
-
return hook
|
|
809
|
-
? isArray(hook)
|
|
810
|
-
? hook.some(h => h.length > 1)
|
|
811
|
-
: hook.length > 1
|
|
812
|
-
: false;
|
|
813
|
-
};
|
|
814
|
-
function resolveTransitionProps(rawProps) {
|
|
815
|
-
const baseProps = {};
|
|
816
|
-
for (const key in rawProps) {
|
|
817
|
-
if (!(key in DOMTransitionPropsValidators)) {
|
|
818
|
-
baseProps[key] = rawProps[key];
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
if (rawProps.css === false) {
|
|
822
|
-
return baseProps;
|
|
823
|
-
}
|
|
824
|
-
const { name = 'v', type, duration, enterFromClass = `${name}-enter-from`, enterActiveClass = `${name}-enter-active`, enterToClass = `${name}-enter-to`, appearFromClass = enterFromClass, appearActiveClass = enterActiveClass, appearToClass = enterToClass, leaveFromClass = `${name}-leave-from`, leaveActiveClass = `${name}-leave-active`, leaveToClass = `${name}-leave-to` } = rawProps;
|
|
825
|
-
const durations = normalizeDuration(duration);
|
|
826
|
-
const enterDuration = durations && durations[0];
|
|
827
|
-
const leaveDuration = durations && durations[1];
|
|
828
|
-
const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
|
|
829
|
-
const finishEnter = (el, isAppear, done) => {
|
|
830
|
-
removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
|
|
831
|
-
removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
|
|
832
|
-
done && done();
|
|
833
|
-
};
|
|
834
|
-
const finishLeave = (el, done) => {
|
|
835
|
-
el._isLeaving = false;
|
|
836
|
-
removeTransitionClass(el, leaveFromClass);
|
|
837
|
-
removeTransitionClass(el, leaveToClass);
|
|
838
|
-
removeTransitionClass(el, leaveActiveClass);
|
|
839
|
-
done && done();
|
|
840
|
-
};
|
|
841
|
-
const makeEnterHook = (isAppear) => {
|
|
842
|
-
return (el, done) => {
|
|
843
|
-
const hook = isAppear ? onAppear : onEnter;
|
|
844
|
-
const resolve = () => finishEnter(el, isAppear, done);
|
|
845
|
-
callHook(hook, [el, resolve]);
|
|
846
|
-
nextFrame(() => {
|
|
847
|
-
removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
|
|
848
|
-
addTransitionClass(el, isAppear ? appearToClass : enterToClass);
|
|
849
|
-
if (!hasExplicitCallback(hook)) {
|
|
850
|
-
whenTransitionEnds(el, type, enterDuration, resolve);
|
|
851
|
-
}
|
|
852
|
-
});
|
|
853
|
-
};
|
|
854
|
-
};
|
|
855
|
-
return extend(baseProps, {
|
|
856
|
-
onBeforeEnter(el) {
|
|
857
|
-
callHook(onBeforeEnter, [el]);
|
|
858
|
-
addTransitionClass(el, enterFromClass);
|
|
859
|
-
addTransitionClass(el, enterActiveClass);
|
|
860
|
-
},
|
|
861
|
-
onBeforeAppear(el) {
|
|
862
|
-
callHook(onBeforeAppear, [el]);
|
|
863
|
-
addTransitionClass(el, appearFromClass);
|
|
864
|
-
addTransitionClass(el, appearActiveClass);
|
|
865
|
-
},
|
|
866
|
-
onEnter: makeEnterHook(false),
|
|
867
|
-
onAppear: makeEnterHook(true),
|
|
868
|
-
onLeave(el, done) {
|
|
869
|
-
el._isLeaving = true;
|
|
870
|
-
const resolve = () => finishLeave(el, done);
|
|
871
|
-
addTransitionClass(el, leaveFromClass);
|
|
872
|
-
// force reflow so *-leave-from classes immediately take effect (#2593)
|
|
873
|
-
forceReflow();
|
|
874
|
-
addTransitionClass(el, leaveActiveClass);
|
|
875
|
-
nextFrame(() => {
|
|
876
|
-
if (!el._isLeaving) {
|
|
877
|
-
// cancelled
|
|
878
|
-
return;
|
|
879
|
-
}
|
|
880
|
-
removeTransitionClass(el, leaveFromClass);
|
|
881
|
-
addTransitionClass(el, leaveToClass);
|
|
882
|
-
if (!hasExplicitCallback(onLeave)) {
|
|
883
|
-
whenTransitionEnds(el, type, leaveDuration, resolve);
|
|
884
|
-
}
|
|
885
|
-
});
|
|
886
|
-
callHook(onLeave, [el, resolve]);
|
|
887
|
-
},
|
|
888
|
-
onEnterCancelled(el) {
|
|
889
|
-
finishEnter(el, false);
|
|
890
|
-
callHook(onEnterCancelled, [el]);
|
|
891
|
-
},
|
|
892
|
-
onAppearCancelled(el) {
|
|
893
|
-
finishEnter(el, true);
|
|
894
|
-
callHook(onAppearCancelled, [el]);
|
|
895
|
-
},
|
|
896
|
-
onLeaveCancelled(el) {
|
|
897
|
-
finishLeave(el);
|
|
898
|
-
callHook(onLeaveCancelled, [el]);
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
function normalizeDuration(duration) {
|
|
903
|
-
if (duration == null) {
|
|
904
|
-
return null;
|
|
905
|
-
}
|
|
906
|
-
else if (isObject(duration)) {
|
|
907
|
-
return [NumberOf(duration.enter), NumberOf(duration.leave)];
|
|
908
|
-
}
|
|
909
|
-
else {
|
|
910
|
-
const n = NumberOf(duration);
|
|
911
|
-
return [n, n];
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
function NumberOf(val) {
|
|
915
|
-
const res = toNumber(val);
|
|
916
|
-
if ((process.env.NODE_ENV !== 'production'))
|
|
917
|
-
validateDuration(res);
|
|
918
|
-
return res;
|
|
919
|
-
}
|
|
920
|
-
function validateDuration(val) {
|
|
921
|
-
if (typeof val !== 'number') {
|
|
922
|
-
warn(`<transition> explicit duration is not a valid number - ` +
|
|
923
|
-
`got ${JSON.stringify(val)}.`);
|
|
924
|
-
}
|
|
925
|
-
else if (isNaN(val)) {
|
|
926
|
-
warn(`<transition> explicit duration is NaN - ` +
|
|
927
|
-
'the duration expression might be incorrect.');
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
function addTransitionClass(el, cls) {
|
|
931
|
-
cls.split(/\s+/).forEach(c => c && el.classList.add(c));
|
|
932
|
-
(el._vtc ||
|
|
933
|
-
(el._vtc = new Set())).add(cls);
|
|
934
|
-
}
|
|
935
|
-
function removeTransitionClass(el, cls) {
|
|
936
|
-
cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
|
|
937
|
-
const { _vtc } = el;
|
|
938
|
-
if (_vtc) {
|
|
939
|
-
_vtc.delete(cls);
|
|
940
|
-
if (!_vtc.size) {
|
|
941
|
-
el._vtc = undefined;
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
function nextFrame(cb) {
|
|
946
|
-
requestAnimationFrame(() => {
|
|
947
|
-
requestAnimationFrame(cb);
|
|
948
|
-
});
|
|
949
|
-
}
|
|
950
|
-
let endId = 0;
|
|
951
|
-
function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
|
|
952
|
-
const id = (el._endId = ++endId);
|
|
953
|
-
const resolveIfNotStale = () => {
|
|
954
|
-
if (id === el._endId) {
|
|
955
|
-
resolve();
|
|
956
|
-
}
|
|
957
|
-
};
|
|
958
|
-
if (explicitTimeout) {
|
|
959
|
-
return setTimeout(resolveIfNotStale, explicitTimeout);
|
|
960
|
-
}
|
|
961
|
-
const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
|
|
962
|
-
if (!type) {
|
|
963
|
-
return resolve();
|
|
964
|
-
}
|
|
965
|
-
const endEvent = type + 'end';
|
|
966
|
-
let ended = 0;
|
|
967
|
-
const end = () => {
|
|
968
|
-
el.removeEventListener(endEvent, onEnd);
|
|
969
|
-
resolveIfNotStale();
|
|
970
|
-
};
|
|
971
|
-
const onEnd = (e) => {
|
|
972
|
-
if (e.target === el && ++ended >= propCount) {
|
|
973
|
-
end();
|
|
974
|
-
}
|
|
975
|
-
};
|
|
976
|
-
setTimeout(() => {
|
|
977
|
-
if (ended < propCount) {
|
|
978
|
-
end();
|
|
979
|
-
}
|
|
980
|
-
}, timeout + 1);
|
|
981
|
-
el.addEventListener(endEvent, onEnd);
|
|
982
|
-
}
|
|
983
|
-
function getTransitionInfo(el, expectedType) {
|
|
984
|
-
const styles = window.getComputedStyle(el);
|
|
985
|
-
// JSDOM may return undefined for transition properties
|
|
986
|
-
const getStyleProperties = (key) => (styles[key] || '').split(', ');
|
|
987
|
-
const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
|
|
988
|
-
const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
|
|
989
|
-
const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
|
|
990
|
-
const animationDelays = getStyleProperties(ANIMATION + 'Delay');
|
|
991
|
-
const animationDurations = getStyleProperties(ANIMATION + 'Duration');
|
|
992
|
-
const animationTimeout = getTimeout(animationDelays, animationDurations);
|
|
993
|
-
let type = null;
|
|
994
|
-
let timeout = 0;
|
|
995
|
-
let propCount = 0;
|
|
996
|
-
/* istanbul ignore if */
|
|
997
|
-
if (expectedType === TRANSITION) {
|
|
998
|
-
if (transitionTimeout > 0) {
|
|
999
|
-
type = TRANSITION;
|
|
1000
|
-
timeout = transitionTimeout;
|
|
1001
|
-
propCount = transitionDurations.length;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
else if (expectedType === ANIMATION) {
|
|
1005
|
-
if (animationTimeout > 0) {
|
|
1006
|
-
type = ANIMATION;
|
|
1007
|
-
timeout = animationTimeout;
|
|
1008
|
-
propCount = animationDurations.length;
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
else {
|
|
1012
|
-
timeout = Math.max(transitionTimeout, animationTimeout);
|
|
1013
|
-
type =
|
|
1014
|
-
timeout > 0
|
|
1015
|
-
? transitionTimeout > animationTimeout
|
|
1016
|
-
? TRANSITION
|
|
1017
|
-
: ANIMATION
|
|
1018
|
-
: null;
|
|
1019
|
-
propCount = type
|
|
1020
|
-
? type === TRANSITION
|
|
1021
|
-
? transitionDurations.length
|
|
1022
|
-
: animationDurations.length
|
|
1023
|
-
: 0;
|
|
1024
|
-
}
|
|
1025
|
-
const hasTransform = type === TRANSITION &&
|
|
1026
|
-
/\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
|
|
1027
|
-
return {
|
|
1028
|
-
type,
|
|
1029
|
-
timeout,
|
|
1030
|
-
propCount,
|
|
1031
|
-
hasTransform
|
|
1032
|
-
};
|
|
1033
|
-
}
|
|
1034
|
-
function getTimeout(delays, durations) {
|
|
1035
|
-
while (delays.length < durations.length) {
|
|
1036
|
-
delays = delays.concat(delays);
|
|
1037
|
-
}
|
|
1038
|
-
return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
|
|
1039
|
-
}
|
|
1040
|
-
// Old versions of Chromium (below 61.0.3163.100) formats floating pointer
|
|
1041
|
-
// numbers in a locale-dependent way, using a comma instead of a dot.
|
|
1042
|
-
// If comma is not replaced with a dot, the input will be rounded down
|
|
1043
|
-
// (i.e. acting as a floor function) causing unexpected behaviors
|
|
1044
|
-
function toMs(s) {
|
|
1045
|
-
return Number(s.slice(0, -1).replace(',', '.')) * 1000;
|
|
1046
|
-
}
|
|
1047
|
-
// synchronously force layout to put elements into a certain state
|
|
1048
|
-
function forceReflow() {
|
|
1049
|
-
return document.body.offsetHeight;
|
|
733
|
+
const TRANSITION = 'transition';
|
|
734
|
+
const ANIMATION = 'animation';
|
|
735
|
+
// DOM Transition is a higher-order-component based on the platform-agnostic
|
|
736
|
+
// base Transition component, with DOM-specific logic.
|
|
737
|
+
const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
|
|
738
|
+
Transition.displayName = 'Transition';
|
|
739
|
+
const DOMTransitionPropsValidators = {
|
|
740
|
+
name: String,
|
|
741
|
+
type: String,
|
|
742
|
+
css: {
|
|
743
|
+
type: Boolean,
|
|
744
|
+
default: true
|
|
745
|
+
},
|
|
746
|
+
duration: [String, Number, Object],
|
|
747
|
+
enterFromClass: String,
|
|
748
|
+
enterActiveClass: String,
|
|
749
|
+
enterToClass: String,
|
|
750
|
+
appearFromClass: String,
|
|
751
|
+
appearActiveClass: String,
|
|
752
|
+
appearToClass: String,
|
|
753
|
+
leaveFromClass: String,
|
|
754
|
+
leaveActiveClass: String,
|
|
755
|
+
leaveToClass: String
|
|
756
|
+
};
|
|
757
|
+
const TransitionPropsValidators = (Transition.props =
|
|
758
|
+
/*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
|
|
759
|
+
/**
|
|
760
|
+
* #3227 Incoming hooks may be merged into arrays when wrapping Transition
|
|
761
|
+
* with custom HOCs.
|
|
762
|
+
*/
|
|
763
|
+
const callHook = (hook, args = []) => {
|
|
764
|
+
if (isArray(hook)) {
|
|
765
|
+
hook.forEach(h => h(...args));
|
|
766
|
+
}
|
|
767
|
+
else if (hook) {
|
|
768
|
+
hook(...args);
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
/**
|
|
772
|
+
* Check if a hook expects a callback (2nd arg), which means the user
|
|
773
|
+
* intends to explicitly control the end of the transition.
|
|
774
|
+
*/
|
|
775
|
+
const hasExplicitCallback = (hook) => {
|
|
776
|
+
return hook
|
|
777
|
+
? isArray(hook)
|
|
778
|
+
? hook.some(h => h.length > 1)
|
|
779
|
+
: hook.length > 1
|
|
780
|
+
: false;
|
|
781
|
+
};
|
|
782
|
+
function resolveTransitionProps(rawProps) {
|
|
783
|
+
const baseProps = {};
|
|
784
|
+
for (const key in rawProps) {
|
|
785
|
+
if (!(key in DOMTransitionPropsValidators)) {
|
|
786
|
+
baseProps[key] = rawProps[key];
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (rawProps.css === false) {
|
|
790
|
+
return baseProps;
|
|
791
|
+
}
|
|
792
|
+
const { name = 'v', type, duration, enterFromClass = `${name}-enter-from`, enterActiveClass = `${name}-enter-active`, enterToClass = `${name}-enter-to`, appearFromClass = enterFromClass, appearActiveClass = enterActiveClass, appearToClass = enterToClass, leaveFromClass = `${name}-leave-from`, leaveActiveClass = `${name}-leave-active`, leaveToClass = `${name}-leave-to` } = rawProps;
|
|
793
|
+
const durations = normalizeDuration(duration);
|
|
794
|
+
const enterDuration = durations && durations[0];
|
|
795
|
+
const leaveDuration = durations && durations[1];
|
|
796
|
+
const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
|
|
797
|
+
const finishEnter = (el, isAppear, done) => {
|
|
798
|
+
removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
|
|
799
|
+
removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
|
|
800
|
+
done && done();
|
|
801
|
+
};
|
|
802
|
+
const finishLeave = (el, done) => {
|
|
803
|
+
el._isLeaving = false;
|
|
804
|
+
removeTransitionClass(el, leaveFromClass);
|
|
805
|
+
removeTransitionClass(el, leaveToClass);
|
|
806
|
+
removeTransitionClass(el, leaveActiveClass);
|
|
807
|
+
done && done();
|
|
808
|
+
};
|
|
809
|
+
const makeEnterHook = (isAppear) => {
|
|
810
|
+
return (el, done) => {
|
|
811
|
+
const hook = isAppear ? onAppear : onEnter;
|
|
812
|
+
const resolve = () => finishEnter(el, isAppear, done);
|
|
813
|
+
callHook(hook, [el, resolve]);
|
|
814
|
+
nextFrame(() => {
|
|
815
|
+
removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
|
|
816
|
+
addTransitionClass(el, isAppear ? appearToClass : enterToClass);
|
|
817
|
+
if (!hasExplicitCallback(hook)) {
|
|
818
|
+
whenTransitionEnds(el, type, enterDuration, resolve);
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
};
|
|
822
|
+
};
|
|
823
|
+
return extend(baseProps, {
|
|
824
|
+
onBeforeEnter(el) {
|
|
825
|
+
callHook(onBeforeEnter, [el]);
|
|
826
|
+
addTransitionClass(el, enterFromClass);
|
|
827
|
+
addTransitionClass(el, enterActiveClass);
|
|
828
|
+
},
|
|
829
|
+
onBeforeAppear(el) {
|
|
830
|
+
callHook(onBeforeAppear, [el]);
|
|
831
|
+
addTransitionClass(el, appearFromClass);
|
|
832
|
+
addTransitionClass(el, appearActiveClass);
|
|
833
|
+
},
|
|
834
|
+
onEnter: makeEnterHook(false),
|
|
835
|
+
onAppear: makeEnterHook(true),
|
|
836
|
+
onLeave(el, done) {
|
|
837
|
+
el._isLeaving = true;
|
|
838
|
+
const resolve = () => finishLeave(el, done);
|
|
839
|
+
addTransitionClass(el, leaveFromClass);
|
|
840
|
+
// force reflow so *-leave-from classes immediately take effect (#2593)
|
|
841
|
+
forceReflow();
|
|
842
|
+
addTransitionClass(el, leaveActiveClass);
|
|
843
|
+
nextFrame(() => {
|
|
844
|
+
if (!el._isLeaving) {
|
|
845
|
+
// cancelled
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
removeTransitionClass(el, leaveFromClass);
|
|
849
|
+
addTransitionClass(el, leaveToClass);
|
|
850
|
+
if (!hasExplicitCallback(onLeave)) {
|
|
851
|
+
whenTransitionEnds(el, type, leaveDuration, resolve);
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
callHook(onLeave, [el, resolve]);
|
|
855
|
+
},
|
|
856
|
+
onEnterCancelled(el) {
|
|
857
|
+
finishEnter(el, false);
|
|
858
|
+
callHook(onEnterCancelled, [el]);
|
|
859
|
+
},
|
|
860
|
+
onAppearCancelled(el) {
|
|
861
|
+
finishEnter(el, true);
|
|
862
|
+
callHook(onAppearCancelled, [el]);
|
|
863
|
+
},
|
|
864
|
+
onLeaveCancelled(el) {
|
|
865
|
+
finishLeave(el);
|
|
866
|
+
callHook(onLeaveCancelled, [el]);
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
function normalizeDuration(duration) {
|
|
871
|
+
if (duration == null) {
|
|
872
|
+
return null;
|
|
873
|
+
}
|
|
874
|
+
else if (isObject(duration)) {
|
|
875
|
+
return [NumberOf(duration.enter), NumberOf(duration.leave)];
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
878
|
+
const n = NumberOf(duration);
|
|
879
|
+
return [n, n];
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
function NumberOf(val) {
|
|
883
|
+
const res = toNumber(val);
|
|
884
|
+
if ((process.env.NODE_ENV !== 'production'))
|
|
885
|
+
validateDuration(res);
|
|
886
|
+
return res;
|
|
887
|
+
}
|
|
888
|
+
function validateDuration(val) {
|
|
889
|
+
if (typeof val !== 'number') {
|
|
890
|
+
warn(`<transition> explicit duration is not a valid number - ` +
|
|
891
|
+
`got ${JSON.stringify(val)}.`);
|
|
892
|
+
}
|
|
893
|
+
else if (isNaN(val)) {
|
|
894
|
+
warn(`<transition> explicit duration is NaN - ` +
|
|
895
|
+
'the duration expression might be incorrect.');
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
function addTransitionClass(el, cls) {
|
|
899
|
+
cls.split(/\s+/).forEach(c => c && el.classList.add(c));
|
|
900
|
+
(el._vtc ||
|
|
901
|
+
(el._vtc = new Set())).add(cls);
|
|
902
|
+
}
|
|
903
|
+
function removeTransitionClass(el, cls) {
|
|
904
|
+
cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
|
|
905
|
+
const { _vtc } = el;
|
|
906
|
+
if (_vtc) {
|
|
907
|
+
_vtc.delete(cls);
|
|
908
|
+
if (!_vtc.size) {
|
|
909
|
+
el._vtc = undefined;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
function nextFrame(cb) {
|
|
914
|
+
requestAnimationFrame(() => {
|
|
915
|
+
requestAnimationFrame(cb);
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
let endId = 0;
|
|
919
|
+
function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
|
|
920
|
+
const id = (el._endId = ++endId);
|
|
921
|
+
const resolveIfNotStale = () => {
|
|
922
|
+
if (id === el._endId) {
|
|
923
|
+
resolve();
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
if (explicitTimeout) {
|
|
927
|
+
return setTimeout(resolveIfNotStale, explicitTimeout);
|
|
928
|
+
}
|
|
929
|
+
const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
|
|
930
|
+
if (!type) {
|
|
931
|
+
return resolve();
|
|
932
|
+
}
|
|
933
|
+
const endEvent = type + 'end';
|
|
934
|
+
let ended = 0;
|
|
935
|
+
const end = () => {
|
|
936
|
+
el.removeEventListener(endEvent, onEnd);
|
|
937
|
+
resolveIfNotStale();
|
|
938
|
+
};
|
|
939
|
+
const onEnd = (e) => {
|
|
940
|
+
if (e.target === el && ++ended >= propCount) {
|
|
941
|
+
end();
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
setTimeout(() => {
|
|
945
|
+
if (ended < propCount) {
|
|
946
|
+
end();
|
|
947
|
+
}
|
|
948
|
+
}, timeout + 1);
|
|
949
|
+
el.addEventListener(endEvent, onEnd);
|
|
950
|
+
}
|
|
951
|
+
function getTransitionInfo(el, expectedType) {
|
|
952
|
+
const styles = window.getComputedStyle(el);
|
|
953
|
+
// JSDOM may return undefined for transition properties
|
|
954
|
+
const getStyleProperties = (key) => (styles[key] || '').split(', ');
|
|
955
|
+
const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
|
|
956
|
+
const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
|
|
957
|
+
const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
|
|
958
|
+
const animationDelays = getStyleProperties(ANIMATION + 'Delay');
|
|
959
|
+
const animationDurations = getStyleProperties(ANIMATION + 'Duration');
|
|
960
|
+
const animationTimeout = getTimeout(animationDelays, animationDurations);
|
|
961
|
+
let type = null;
|
|
962
|
+
let timeout = 0;
|
|
963
|
+
let propCount = 0;
|
|
964
|
+
/* istanbul ignore if */
|
|
965
|
+
if (expectedType === TRANSITION) {
|
|
966
|
+
if (transitionTimeout > 0) {
|
|
967
|
+
type = TRANSITION;
|
|
968
|
+
timeout = transitionTimeout;
|
|
969
|
+
propCount = transitionDurations.length;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
else if (expectedType === ANIMATION) {
|
|
973
|
+
if (animationTimeout > 0) {
|
|
974
|
+
type = ANIMATION;
|
|
975
|
+
timeout = animationTimeout;
|
|
976
|
+
propCount = animationDurations.length;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
else {
|
|
980
|
+
timeout = Math.max(transitionTimeout, animationTimeout);
|
|
981
|
+
type =
|
|
982
|
+
timeout > 0
|
|
983
|
+
? transitionTimeout > animationTimeout
|
|
984
|
+
? TRANSITION
|
|
985
|
+
: ANIMATION
|
|
986
|
+
: null;
|
|
987
|
+
propCount = type
|
|
988
|
+
? type === TRANSITION
|
|
989
|
+
? transitionDurations.length
|
|
990
|
+
: animationDurations.length
|
|
991
|
+
: 0;
|
|
992
|
+
}
|
|
993
|
+
const hasTransform = type === TRANSITION &&
|
|
994
|
+
/\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
|
|
995
|
+
return {
|
|
996
|
+
type,
|
|
997
|
+
timeout,
|
|
998
|
+
propCount,
|
|
999
|
+
hasTransform
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
function getTimeout(delays, durations) {
|
|
1003
|
+
while (delays.length < durations.length) {
|
|
1004
|
+
delays = delays.concat(delays);
|
|
1005
|
+
}
|
|
1006
|
+
return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
|
|
1007
|
+
}
|
|
1008
|
+
// Old versions of Chromium (below 61.0.3163.100) formats floating pointer
|
|
1009
|
+
// numbers in a locale-dependent way, using a comma instead of a dot.
|
|
1010
|
+
// If comma is not replaced with a dot, the input will be rounded down
|
|
1011
|
+
// (i.e. acting as a floor function) causing unexpected behaviors
|
|
1012
|
+
function toMs(s) {
|
|
1013
|
+
return Number(s.slice(0, -1).replace(',', '.')) * 1000;
|
|
1014
|
+
}
|
|
1015
|
+
// synchronously force layout to put elements into a certain state
|
|
1016
|
+
function forceReflow() {
|
|
1017
|
+
return document.body.offsetHeight;
|
|
1050
1018
|
}
|
|
1051
1019
|
|
|
1052
|
-
const positionMap = new WeakMap();
|
|
1053
|
-
const newPositionMap = new WeakMap();
|
|
1054
|
-
const TransitionGroupImpl = {
|
|
1055
|
-
name: 'TransitionGroup',
|
|
1056
|
-
props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
|
|
1057
|
-
tag: String,
|
|
1058
|
-
moveClass: String
|
|
1059
|
-
}),
|
|
1060
|
-
setup(props, { slots }) {
|
|
1061
|
-
const instance = getCurrentInstance();
|
|
1062
|
-
const state = useTransitionState();
|
|
1063
|
-
let prevChildren;
|
|
1064
|
-
let children;
|
|
1065
|
-
onUpdated(() => {
|
|
1066
|
-
// children is guaranteed to exist after initial render
|
|
1067
|
-
if (!prevChildren.length) {
|
|
1068
|
-
return;
|
|
1069
|
-
}
|
|
1070
|
-
const moveClass = props.moveClass || `${props.name || 'v'}-move`;
|
|
1071
|
-
if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
|
|
1072
|
-
return;
|
|
1073
|
-
}
|
|
1074
|
-
// we divide the work into three loops to avoid mixing DOM reads and writes
|
|
1075
|
-
// in each iteration - which helps prevent layout thrashing.
|
|
1076
|
-
prevChildren.forEach(callPendingCbs);
|
|
1077
|
-
prevChildren.forEach(recordPosition);
|
|
1078
|
-
const movedChildren = prevChildren.filter(applyTranslation);
|
|
1079
|
-
// force reflow to put everything in position
|
|
1080
|
-
forceReflow();
|
|
1081
|
-
movedChildren.forEach(c => {
|
|
1082
|
-
const el = c.el;
|
|
1083
|
-
const style = el.style;
|
|
1084
|
-
addTransitionClass(el, moveClass);
|
|
1085
|
-
style.transform = style.webkitTransform = style.transitionDuration = '';
|
|
1086
|
-
const cb = (el._moveCb = (e) => {
|
|
1087
|
-
if (e && e.target !== el) {
|
|
1088
|
-
return;
|
|
1089
|
-
}
|
|
1090
|
-
if (!e || /transform$/.test(e.propertyName)) {
|
|
1091
|
-
el.removeEventListener('transitionend', cb);
|
|
1092
|
-
el._moveCb = null;
|
|
1093
|
-
removeTransitionClass(el, moveClass);
|
|
1094
|
-
}
|
|
1095
|
-
});
|
|
1096
|
-
el.addEventListener('transitionend', cb);
|
|
1097
|
-
});
|
|
1098
|
-
});
|
|
1099
|
-
return () => {
|
|
1100
|
-
const rawProps = toRaw(props);
|
|
1101
|
-
const cssTransitionProps = resolveTransitionProps(rawProps);
|
|
1102
|
-
let tag = rawProps.tag || Fragment;
|
|
1103
|
-
prevChildren = children;
|
|
1104
|
-
children = slots.default ? getTransitionRawChildren(slots.default()) : [];
|
|
1105
|
-
for (let i = 0; i < children.length; i++) {
|
|
1106
|
-
const child = children[i];
|
|
1107
|
-
if (child.key != null) {
|
|
1108
|
-
setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
|
|
1109
|
-
}
|
|
1110
|
-
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1111
|
-
warn(`<TransitionGroup> children must be keyed.`);
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
if (prevChildren) {
|
|
1115
|
-
for (let i = 0; i < prevChildren.length; i++) {
|
|
1116
|
-
const child = prevChildren[i];
|
|
1117
|
-
setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
|
|
1118
|
-
positionMap.set(child, child.el.getBoundingClientRect());
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
return createVNode(tag, null, children);
|
|
1122
|
-
};
|
|
1123
|
-
}
|
|
1124
|
-
};
|
|
1125
|
-
const TransitionGroup = TransitionGroupImpl;
|
|
1126
|
-
function callPendingCbs(c) {
|
|
1127
|
-
const el = c.el;
|
|
1128
|
-
if (el._moveCb) {
|
|
1129
|
-
el._moveCb();
|
|
1130
|
-
}
|
|
1131
|
-
if (el._enterCb) {
|
|
1132
|
-
el._enterCb();
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
function recordPosition(c) {
|
|
1136
|
-
newPositionMap.set(c, c.el.getBoundingClientRect());
|
|
1137
|
-
}
|
|
1138
|
-
function applyTranslation(c) {
|
|
1139
|
-
const oldPos = positionMap.get(c);
|
|
1140
|
-
const newPos = newPositionMap.get(c);
|
|
1141
|
-
const dx = oldPos.left - newPos.left;
|
|
1142
|
-
const dy = oldPos.top - newPos.top;
|
|
1143
|
-
if (dx || dy) {
|
|
1144
|
-
const s = c.el.style;
|
|
1145
|
-
s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
|
|
1146
|
-
s.transitionDuration = '0s';
|
|
1147
|
-
return c;
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
function hasCSSTransform(el, root, moveClass) {
|
|
1151
|
-
// Detect whether an element with the move class applied has
|
|
1152
|
-
// CSS transitions. Since the element may be inside an entering
|
|
1153
|
-
// transition at this very moment, we make a clone of it and remove
|
|
1154
|
-
// all other transition classes applied to ensure only the move class
|
|
1155
|
-
// is applied.
|
|
1156
|
-
const clone = el.cloneNode();
|
|
1157
|
-
if (el._vtc) {
|
|
1158
|
-
el._vtc.forEach(cls => {
|
|
1159
|
-
cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
|
|
1160
|
-
});
|
|
1161
|
-
}
|
|
1162
|
-
moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
|
|
1163
|
-
clone.style.display = 'none';
|
|
1164
|
-
const container = (root.nodeType === 1 ? root : root.parentNode);
|
|
1165
|
-
container.appendChild(clone);
|
|
1166
|
-
const { hasTransform } = getTransitionInfo(clone);
|
|
1167
|
-
container.removeChild(clone);
|
|
1168
|
-
return hasTransform;
|
|
1020
|
+
const positionMap = new WeakMap();
|
|
1021
|
+
const newPositionMap = new WeakMap();
|
|
1022
|
+
const TransitionGroupImpl = {
|
|
1023
|
+
name: 'TransitionGroup',
|
|
1024
|
+
props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
|
|
1025
|
+
tag: String,
|
|
1026
|
+
moveClass: String
|
|
1027
|
+
}),
|
|
1028
|
+
setup(props, { slots }) {
|
|
1029
|
+
const instance = getCurrentInstance();
|
|
1030
|
+
const state = useTransitionState();
|
|
1031
|
+
let prevChildren;
|
|
1032
|
+
let children;
|
|
1033
|
+
onUpdated(() => {
|
|
1034
|
+
// children is guaranteed to exist after initial render
|
|
1035
|
+
if (!prevChildren.length) {
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
const moveClass = props.moveClass || `${props.name || 'v'}-move`;
|
|
1039
|
+
if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
// we divide the work into three loops to avoid mixing DOM reads and writes
|
|
1043
|
+
// in each iteration - which helps prevent layout thrashing.
|
|
1044
|
+
prevChildren.forEach(callPendingCbs);
|
|
1045
|
+
prevChildren.forEach(recordPosition);
|
|
1046
|
+
const movedChildren = prevChildren.filter(applyTranslation);
|
|
1047
|
+
// force reflow to put everything in position
|
|
1048
|
+
forceReflow();
|
|
1049
|
+
movedChildren.forEach(c => {
|
|
1050
|
+
const el = c.el;
|
|
1051
|
+
const style = el.style;
|
|
1052
|
+
addTransitionClass(el, moveClass);
|
|
1053
|
+
style.transform = style.webkitTransform = style.transitionDuration = '';
|
|
1054
|
+
const cb = (el._moveCb = (e) => {
|
|
1055
|
+
if (e && e.target !== el) {
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
if (!e || /transform$/.test(e.propertyName)) {
|
|
1059
|
+
el.removeEventListener('transitionend', cb);
|
|
1060
|
+
el._moveCb = null;
|
|
1061
|
+
removeTransitionClass(el, moveClass);
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
el.addEventListener('transitionend', cb);
|
|
1065
|
+
});
|
|
1066
|
+
});
|
|
1067
|
+
return () => {
|
|
1068
|
+
const rawProps = toRaw(props);
|
|
1069
|
+
const cssTransitionProps = resolveTransitionProps(rawProps);
|
|
1070
|
+
let tag = rawProps.tag || Fragment;
|
|
1071
|
+
prevChildren = children;
|
|
1072
|
+
children = slots.default ? getTransitionRawChildren(slots.default()) : [];
|
|
1073
|
+
for (let i = 0; i < children.length; i++) {
|
|
1074
|
+
const child = children[i];
|
|
1075
|
+
if (child.key != null) {
|
|
1076
|
+
setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
|
|
1077
|
+
}
|
|
1078
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1079
|
+
warn(`<TransitionGroup> children must be keyed.`);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if (prevChildren) {
|
|
1083
|
+
for (let i = 0; i < prevChildren.length; i++) {
|
|
1084
|
+
const child = prevChildren[i];
|
|
1085
|
+
setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
|
|
1086
|
+
positionMap.set(child, child.el.getBoundingClientRect());
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
return createVNode(tag, null, children);
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
const TransitionGroup = TransitionGroupImpl;
|
|
1094
|
+
function callPendingCbs(c) {
|
|
1095
|
+
const el = c.el;
|
|
1096
|
+
if (el._moveCb) {
|
|
1097
|
+
el._moveCb();
|
|
1098
|
+
}
|
|
1099
|
+
if (el._enterCb) {
|
|
1100
|
+
el._enterCb();
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
function recordPosition(c) {
|
|
1104
|
+
newPositionMap.set(c, c.el.getBoundingClientRect());
|
|
1105
|
+
}
|
|
1106
|
+
function applyTranslation(c) {
|
|
1107
|
+
const oldPos = positionMap.get(c);
|
|
1108
|
+
const newPos = newPositionMap.get(c);
|
|
1109
|
+
const dx = oldPos.left - newPos.left;
|
|
1110
|
+
const dy = oldPos.top - newPos.top;
|
|
1111
|
+
if (dx || dy) {
|
|
1112
|
+
const s = c.el.style;
|
|
1113
|
+
s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
|
|
1114
|
+
s.transitionDuration = '0s';
|
|
1115
|
+
return c;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
function hasCSSTransform(el, root, moveClass) {
|
|
1119
|
+
// Detect whether an element with the move class applied has
|
|
1120
|
+
// CSS transitions. Since the element may be inside an entering
|
|
1121
|
+
// transition at this very moment, we make a clone of it and remove
|
|
1122
|
+
// all other transition classes applied to ensure only the move class
|
|
1123
|
+
// is applied.
|
|
1124
|
+
const clone = el.cloneNode();
|
|
1125
|
+
if (el._vtc) {
|
|
1126
|
+
el._vtc.forEach(cls => {
|
|
1127
|
+
cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
|
|
1131
|
+
clone.style.display = 'none';
|
|
1132
|
+
const container = (root.nodeType === 1 ? root : root.parentNode);
|
|
1133
|
+
container.appendChild(clone);
|
|
1134
|
+
const { hasTransform } = getTransitionInfo(clone);
|
|
1135
|
+
container.removeChild(clone);
|
|
1136
|
+
return hasTransform;
|
|
1169
1137
|
}
|
|
1170
1138
|
|
|
1171
|
-
const getModelAssigner = (vnode) => {
|
|
1172
|
-
const fn = vnode.props['onUpdate:modelValue'] ||
|
|
1173
|
-
(false );
|
|
1174
|
-
return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
|
|
1175
|
-
};
|
|
1176
|
-
function onCompositionStart(e) {
|
|
1177
|
-
e.target.composing = true;
|
|
1178
|
-
}
|
|
1179
|
-
function onCompositionEnd(e) {
|
|
1180
|
-
const target = e.target;
|
|
1181
|
-
if (target.composing) {
|
|
1182
|
-
target.composing = false;
|
|
1183
|
-
target.dispatchEvent(new Event('input'));
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
// We are exporting the v-model runtime directly as vnode hooks so that it can
|
|
1187
|
-
// be tree-shaken in case v-model is never used.
|
|
1188
|
-
const vModelText = {
|
|
1189
|
-
created(el, { modifiers: { lazy, trim, number } }, vnode) {
|
|
1190
|
-
el._assign = getModelAssigner(vnode);
|
|
1191
|
-
const castToNumber = number || (vnode.props && vnode.props.type === 'number');
|
|
1192
|
-
addEventListener(el, lazy ? 'change' : 'input', e => {
|
|
1193
|
-
if (e.target.composing)
|
|
1194
|
-
return;
|
|
1195
|
-
let domValue = el.value;
|
|
1196
|
-
if (trim) {
|
|
1197
|
-
domValue = domValue.trim();
|
|
1198
|
-
}
|
|
1199
|
-
if (castToNumber) {
|
|
1200
|
-
domValue = toNumber(domValue);
|
|
1201
|
-
}
|
|
1202
|
-
el._assign(domValue);
|
|
1203
|
-
});
|
|
1204
|
-
if (trim) {
|
|
1205
|
-
addEventListener(el, 'change', () => {
|
|
1206
|
-
el.value = el.value.trim();
|
|
1207
|
-
});
|
|
1208
|
-
}
|
|
1209
|
-
if (!lazy) {
|
|
1210
|
-
addEventListener(el, 'compositionstart', onCompositionStart);
|
|
1211
|
-
addEventListener(el, 'compositionend', onCompositionEnd);
|
|
1212
|
-
// Safari < 10.2 & UIWebView doesn't fire compositionend when
|
|
1213
|
-
// switching focus before confirming composition choice
|
|
1214
|
-
// this also fixes the issue where some browsers e.g. iOS Chrome
|
|
1215
|
-
// fires "change" instead of "input" on autocomplete.
|
|
1216
|
-
addEventListener(el, 'change', onCompositionEnd);
|
|
1217
|
-
}
|
|
1218
|
-
},
|
|
1219
|
-
// set value on mounted so it's after min/max for type="range"
|
|
1220
|
-
mounted(el, { value }) {
|
|
1221
|
-
el.value = value == null ? '' : value;
|
|
1222
|
-
},
|
|
1223
|
-
beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
|
|
1224
|
-
el._assign = getModelAssigner(vnode);
|
|
1225
|
-
// avoid clearing unresolved text. #2302
|
|
1226
|
-
if (el.composing)
|
|
1227
|
-
return;
|
|
1228
|
-
if (document.activeElement === el && el.type !== 'range') {
|
|
1229
|
-
if (lazy) {
|
|
1230
|
-
return;
|
|
1231
|
-
}
|
|
1232
|
-
if (trim && el.value.trim() === value) {
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
|
-
if ((number || el.type === 'number') && toNumber(el.value) === value) {
|
|
1236
|
-
return;
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
const newValue = value == null ? '' : value;
|
|
1240
|
-
if (el.value !== newValue) {
|
|
1241
|
-
el.value = newValue;
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
const vModelCheckbox = {
|
|
1246
|
-
// #4096 array checkboxes need to be deep traversed
|
|
1247
|
-
deep: true,
|
|
1248
|
-
created(el, _, vnode) {
|
|
1249
|
-
el._assign = getModelAssigner(vnode);
|
|
1250
|
-
addEventListener(el, 'change', () => {
|
|
1251
|
-
const modelValue = el._modelValue;
|
|
1252
|
-
const elementValue = getValue(el);
|
|
1253
|
-
const checked = el.checked;
|
|
1254
|
-
const assign = el._assign;
|
|
1255
|
-
if (isArray(modelValue)) {
|
|
1256
|
-
const index = looseIndexOf(modelValue, elementValue);
|
|
1257
|
-
const found = index !== -1;
|
|
1258
|
-
if (checked && !found) {
|
|
1259
|
-
assign(modelValue.concat(elementValue));
|
|
1260
|
-
}
|
|
1261
|
-
else if (!checked && found) {
|
|
1262
|
-
const filtered = [...modelValue];
|
|
1263
|
-
filtered.splice(index, 1);
|
|
1264
|
-
assign(filtered);
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
else if (isSet(modelValue)) {
|
|
1268
|
-
const cloned = new Set(modelValue);
|
|
1269
|
-
if (checked) {
|
|
1270
|
-
cloned.add(elementValue);
|
|
1271
|
-
}
|
|
1272
|
-
else {
|
|
1273
|
-
cloned.delete(elementValue);
|
|
1274
|
-
}
|
|
1275
|
-
assign(cloned);
|
|
1276
|
-
}
|
|
1277
|
-
else {
|
|
1278
|
-
assign(getCheckboxValue(el, checked));
|
|
1279
|
-
}
|
|
1280
|
-
});
|
|
1281
|
-
},
|
|
1282
|
-
// set initial checked on mount to wait for true-value/false-value
|
|
1283
|
-
mounted: setChecked,
|
|
1284
|
-
beforeUpdate(el, binding, vnode) {
|
|
1285
|
-
el._assign = getModelAssigner(vnode);
|
|
1286
|
-
setChecked(el, binding, vnode);
|
|
1287
|
-
}
|
|
1288
|
-
};
|
|
1289
|
-
function setChecked(el, { value, oldValue }, vnode) {
|
|
1290
|
-
el._modelValue = value;
|
|
1291
|
-
if (isArray(value)) {
|
|
1292
|
-
el.checked = looseIndexOf(value, vnode.props.value) > -1;
|
|
1293
|
-
}
|
|
1294
|
-
else if (isSet(value)) {
|
|
1295
|
-
el.checked = value.has(vnode.props.value);
|
|
1296
|
-
}
|
|
1297
|
-
else if (value !== oldValue) {
|
|
1298
|
-
el.checked = looseEqual(value, getCheckboxValue(el, true));
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
const vModelRadio = {
|
|
1302
|
-
created(el, { value }, vnode) {
|
|
1303
|
-
el.checked = looseEqual(value, vnode.props.value);
|
|
1304
|
-
el._assign = getModelAssigner(vnode);
|
|
1305
|
-
addEventListener(el, 'change', () => {
|
|
1306
|
-
el._assign(getValue(el));
|
|
1307
|
-
});
|
|
1308
|
-
},
|
|
1309
|
-
beforeUpdate(el, { value, oldValue }, vnode) {
|
|
1310
|
-
el._assign = getModelAssigner(vnode);
|
|
1311
|
-
if (value !== oldValue) {
|
|
1312
|
-
el.checked = looseEqual(value, vnode.props.value);
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
};
|
|
1316
|
-
const vModelSelect = {
|
|
1317
|
-
// <select multiple> value need to be deep traversed
|
|
1318
|
-
deep: true,
|
|
1319
|
-
created(el, { value, modifiers: { number } }, vnode) {
|
|
1320
|
-
const isSetModel = isSet(value);
|
|
1321
|
-
addEventListener(el, 'change', () => {
|
|
1322
|
-
const selectedVal = Array.prototype.filter
|
|
1323
|
-
.call(el.options, (o) => o.selected)
|
|
1324
|
-
.map((o) => number ? toNumber(getValue(o)) : getValue(o));
|
|
1325
|
-
el._assign(el.multiple
|
|
1326
|
-
? isSetModel
|
|
1327
|
-
? new Set(selectedVal)
|
|
1328
|
-
: selectedVal
|
|
1329
|
-
: selectedVal[0]);
|
|
1330
|
-
});
|
|
1331
|
-
el._assign = getModelAssigner(vnode);
|
|
1332
|
-
},
|
|
1333
|
-
// set value in mounted & updated because <select> relies on its children
|
|
1334
|
-
// <option>s.
|
|
1335
|
-
mounted(el, { value }) {
|
|
1336
|
-
setSelected(el, value);
|
|
1337
|
-
},
|
|
1338
|
-
beforeUpdate(el, _binding, vnode) {
|
|
1339
|
-
el._assign = getModelAssigner(vnode);
|
|
1340
|
-
},
|
|
1341
|
-
updated(el, { value }) {
|
|
1342
|
-
setSelected(el, value);
|
|
1343
|
-
}
|
|
1344
|
-
};
|
|
1345
|
-
function setSelected(el, value) {
|
|
1346
|
-
const isMultiple = el.multiple;
|
|
1347
|
-
if (isMultiple && !isArray(value) && !isSet(value)) {
|
|
1348
|
-
(process.env.NODE_ENV !== 'production') &&
|
|
1349
|
-
warn(`<select multiple v-model> expects an Array or Set value for its binding, ` +
|
|
1350
|
-
`but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
|
|
1351
|
-
return;
|
|
1352
|
-
}
|
|
1353
|
-
for (let i = 0, l = el.options.length; i < l; i++) {
|
|
1354
|
-
const option = el.options[i];
|
|
1355
|
-
const optionValue = getValue(option);
|
|
1356
|
-
if (isMultiple) {
|
|
1357
|
-
if (isArray(value)) {
|
|
1358
|
-
option.selected = looseIndexOf(value, optionValue) > -1;
|
|
1359
|
-
}
|
|
1360
|
-
else {
|
|
1361
|
-
option.selected = value.has(optionValue);
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
else {
|
|
1365
|
-
if (looseEqual(getValue(option), value)) {
|
|
1366
|
-
if (el.selectedIndex !== i)
|
|
1367
|
-
el.selectedIndex = i;
|
|
1368
|
-
return;
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
if (!isMultiple && el.selectedIndex !== -1) {
|
|
1373
|
-
el.selectedIndex = -1;
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
// retrieve raw value set via :value bindings
|
|
1377
|
-
function getValue(el) {
|
|
1378
|
-
return '_value' in el ? el._value : el.value;
|
|
1379
|
-
}
|
|
1380
|
-
// retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
|
|
1381
|
-
function getCheckboxValue(el, checked) {
|
|
1382
|
-
const key = checked ? '_trueValue' : '_falseValue';
|
|
1383
|
-
return key in el ? el[key] : checked;
|
|
1384
|
-
}
|
|
1385
|
-
const vModelDynamic = {
|
|
1386
|
-
created(el, binding, vnode) {
|
|
1387
|
-
callModelHook(el, binding, vnode, null, 'created');
|
|
1388
|
-
},
|
|
1389
|
-
mounted(el, binding, vnode) {
|
|
1390
|
-
callModelHook(el, binding, vnode, null, 'mounted');
|
|
1391
|
-
},
|
|
1392
|
-
beforeUpdate(el, binding, vnode, prevVNode) {
|
|
1393
|
-
callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
|
|
1394
|
-
},
|
|
1395
|
-
updated(el, binding, vnode, prevVNode) {
|
|
1396
|
-
callModelHook(el, binding, vnode, prevVNode, 'updated');
|
|
1397
|
-
}
|
|
1398
|
-
};
|
|
1399
|
-
function resolveDynamicModel(tagName, type) {
|
|
1400
|
-
switch (tagName) {
|
|
1401
|
-
case 'SELECT':
|
|
1402
|
-
return vModelSelect;
|
|
1403
|
-
case 'TEXTAREA':
|
|
1404
|
-
return vModelText;
|
|
1405
|
-
default:
|
|
1406
|
-
switch (type) {
|
|
1407
|
-
case 'checkbox':
|
|
1408
|
-
return vModelCheckbox;
|
|
1409
|
-
case 'radio':
|
|
1410
|
-
return vModelRadio;
|
|
1411
|
-
default:
|
|
1412
|
-
return vModelText;
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
function callModelHook(el, binding, vnode, prevVNode, hook) {
|
|
1417
|
-
const modelToUse = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type);
|
|
1418
|
-
const fn = modelToUse[hook];
|
|
1419
|
-
fn && fn(el, binding, vnode, prevVNode);
|
|
1420
|
-
}
|
|
1421
|
-
// SSR vnode transforms, only used when user includes client-oriented render
|
|
1422
|
-
// function in SSR
|
|
1423
|
-
function initVModelForSSR() {
|
|
1424
|
-
vModelText.getSSRProps = ({ value }) => ({ value });
|
|
1425
|
-
vModelRadio.getSSRProps = ({ value }, vnode) => {
|
|
1426
|
-
if (vnode.props && looseEqual(vnode.props.value, value)) {
|
|
1427
|
-
return { checked: true };
|
|
1428
|
-
}
|
|
1429
|
-
};
|
|
1430
|
-
vModelCheckbox.getSSRProps = ({ value }, vnode) => {
|
|
1431
|
-
if (isArray(value)) {
|
|
1432
|
-
if (vnode.props && looseIndexOf(value, vnode.props.value) > -1) {
|
|
1433
|
-
return { checked: true };
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
else if (isSet(value)) {
|
|
1437
|
-
if (vnode.props && value.has(vnode.props.value)) {
|
|
1438
|
-
return { checked: true };
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
else if (value) {
|
|
1442
|
-
return { checked: true };
|
|
1443
|
-
}
|
|
1444
|
-
};
|
|
1445
|
-
vModelDynamic.getSSRProps = (binding, vnode) => {
|
|
1446
|
-
if (typeof vnode.type !== 'string') {
|
|
1447
|
-
return;
|
|
1448
|
-
}
|
|
1449
|
-
const modelToUse = resolveDynamicModel(
|
|
1450
|
-
// resolveDynamicModel expects an uppercase tag name, but vnode.type is lowercase
|
|
1451
|
-
vnode.type.toUpperCase(), vnode.props && vnode.props.type);
|
|
1452
|
-
if (modelToUse.getSSRProps) {
|
|
1453
|
-
return modelToUse.getSSRProps(binding, vnode);
|
|
1454
|
-
}
|
|
1455
|
-
};
|
|
1139
|
+
const getModelAssigner = (vnode) => {
|
|
1140
|
+
const fn = vnode.props['onUpdate:modelValue'] ||
|
|
1141
|
+
(false );
|
|
1142
|
+
return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
|
|
1143
|
+
};
|
|
1144
|
+
function onCompositionStart(e) {
|
|
1145
|
+
e.target.composing = true;
|
|
1146
|
+
}
|
|
1147
|
+
function onCompositionEnd(e) {
|
|
1148
|
+
const target = e.target;
|
|
1149
|
+
if (target.composing) {
|
|
1150
|
+
target.composing = false;
|
|
1151
|
+
target.dispatchEvent(new Event('input'));
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
// We are exporting the v-model runtime directly as vnode hooks so that it can
|
|
1155
|
+
// be tree-shaken in case v-model is never used.
|
|
1156
|
+
const vModelText = {
|
|
1157
|
+
created(el, { modifiers: { lazy, trim, number } }, vnode) {
|
|
1158
|
+
el._assign = getModelAssigner(vnode);
|
|
1159
|
+
const castToNumber = number || (vnode.props && vnode.props.type === 'number');
|
|
1160
|
+
addEventListener(el, lazy ? 'change' : 'input', e => {
|
|
1161
|
+
if (e.target.composing)
|
|
1162
|
+
return;
|
|
1163
|
+
let domValue = el.value;
|
|
1164
|
+
if (trim) {
|
|
1165
|
+
domValue = domValue.trim();
|
|
1166
|
+
}
|
|
1167
|
+
if (castToNumber) {
|
|
1168
|
+
domValue = toNumber(domValue);
|
|
1169
|
+
}
|
|
1170
|
+
el._assign(domValue);
|
|
1171
|
+
});
|
|
1172
|
+
if (trim) {
|
|
1173
|
+
addEventListener(el, 'change', () => {
|
|
1174
|
+
el.value = el.value.trim();
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
if (!lazy) {
|
|
1178
|
+
addEventListener(el, 'compositionstart', onCompositionStart);
|
|
1179
|
+
addEventListener(el, 'compositionend', onCompositionEnd);
|
|
1180
|
+
// Safari < 10.2 & UIWebView doesn't fire compositionend when
|
|
1181
|
+
// switching focus before confirming composition choice
|
|
1182
|
+
// this also fixes the issue where some browsers e.g. iOS Chrome
|
|
1183
|
+
// fires "change" instead of "input" on autocomplete.
|
|
1184
|
+
addEventListener(el, 'change', onCompositionEnd);
|
|
1185
|
+
}
|
|
1186
|
+
},
|
|
1187
|
+
// set value on mounted so it's after min/max for type="range"
|
|
1188
|
+
mounted(el, { value }) {
|
|
1189
|
+
el.value = value == null ? '' : value;
|
|
1190
|
+
},
|
|
1191
|
+
beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
|
|
1192
|
+
el._assign = getModelAssigner(vnode);
|
|
1193
|
+
// avoid clearing unresolved text. #2302
|
|
1194
|
+
if (el.composing)
|
|
1195
|
+
return;
|
|
1196
|
+
if (document.activeElement === el && el.type !== 'range') {
|
|
1197
|
+
if (lazy) {
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
if (trim && el.value.trim() === value) {
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
if ((number || el.type === 'number') && toNumber(el.value) === value) {
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
const newValue = value == null ? '' : value;
|
|
1208
|
+
if (el.value !== newValue) {
|
|
1209
|
+
el.value = newValue;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
const vModelCheckbox = {
|
|
1214
|
+
// #4096 array checkboxes need to be deep traversed
|
|
1215
|
+
deep: true,
|
|
1216
|
+
created(el, _, vnode) {
|
|
1217
|
+
el._assign = getModelAssigner(vnode);
|
|
1218
|
+
addEventListener(el, 'change', () => {
|
|
1219
|
+
const modelValue = el._modelValue;
|
|
1220
|
+
const elementValue = getValue(el);
|
|
1221
|
+
const checked = el.checked;
|
|
1222
|
+
const assign = el._assign;
|
|
1223
|
+
if (isArray(modelValue)) {
|
|
1224
|
+
const index = looseIndexOf(modelValue, elementValue);
|
|
1225
|
+
const found = index !== -1;
|
|
1226
|
+
if (checked && !found) {
|
|
1227
|
+
assign(modelValue.concat(elementValue));
|
|
1228
|
+
}
|
|
1229
|
+
else if (!checked && found) {
|
|
1230
|
+
const filtered = [...modelValue];
|
|
1231
|
+
filtered.splice(index, 1);
|
|
1232
|
+
assign(filtered);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
else if (isSet(modelValue)) {
|
|
1236
|
+
const cloned = new Set(modelValue);
|
|
1237
|
+
if (checked) {
|
|
1238
|
+
cloned.add(elementValue);
|
|
1239
|
+
}
|
|
1240
|
+
else {
|
|
1241
|
+
cloned.delete(elementValue);
|
|
1242
|
+
}
|
|
1243
|
+
assign(cloned);
|
|
1244
|
+
}
|
|
1245
|
+
else {
|
|
1246
|
+
assign(getCheckboxValue(el, checked));
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
},
|
|
1250
|
+
// set initial checked on mount to wait for true-value/false-value
|
|
1251
|
+
mounted: setChecked,
|
|
1252
|
+
beforeUpdate(el, binding, vnode) {
|
|
1253
|
+
el._assign = getModelAssigner(vnode);
|
|
1254
|
+
setChecked(el, binding, vnode);
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
function setChecked(el, { value, oldValue }, vnode) {
|
|
1258
|
+
el._modelValue = value;
|
|
1259
|
+
if (isArray(value)) {
|
|
1260
|
+
el.checked = looseIndexOf(value, vnode.props.value) > -1;
|
|
1261
|
+
}
|
|
1262
|
+
else if (isSet(value)) {
|
|
1263
|
+
el.checked = value.has(vnode.props.value);
|
|
1264
|
+
}
|
|
1265
|
+
else if (value !== oldValue) {
|
|
1266
|
+
el.checked = looseEqual(value, getCheckboxValue(el, true));
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
const vModelRadio = {
|
|
1270
|
+
created(el, { value }, vnode) {
|
|
1271
|
+
el.checked = looseEqual(value, vnode.props.value);
|
|
1272
|
+
el._assign = getModelAssigner(vnode);
|
|
1273
|
+
addEventListener(el, 'change', () => {
|
|
1274
|
+
el._assign(getValue(el));
|
|
1275
|
+
});
|
|
1276
|
+
},
|
|
1277
|
+
beforeUpdate(el, { value, oldValue }, vnode) {
|
|
1278
|
+
el._assign = getModelAssigner(vnode);
|
|
1279
|
+
if (value !== oldValue) {
|
|
1280
|
+
el.checked = looseEqual(value, vnode.props.value);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
const vModelSelect = {
|
|
1285
|
+
// <select multiple> value need to be deep traversed
|
|
1286
|
+
deep: true,
|
|
1287
|
+
created(el, { value, modifiers: { number } }, vnode) {
|
|
1288
|
+
const isSetModel = isSet(value);
|
|
1289
|
+
addEventListener(el, 'change', () => {
|
|
1290
|
+
const selectedVal = Array.prototype.filter
|
|
1291
|
+
.call(el.options, (o) => o.selected)
|
|
1292
|
+
.map((o) => number ? toNumber(getValue(o)) : getValue(o));
|
|
1293
|
+
el._assign(el.multiple
|
|
1294
|
+
? isSetModel
|
|
1295
|
+
? new Set(selectedVal)
|
|
1296
|
+
: selectedVal
|
|
1297
|
+
: selectedVal[0]);
|
|
1298
|
+
});
|
|
1299
|
+
el._assign = getModelAssigner(vnode);
|
|
1300
|
+
},
|
|
1301
|
+
// set value in mounted & updated because <select> relies on its children
|
|
1302
|
+
// <option>s.
|
|
1303
|
+
mounted(el, { value }) {
|
|
1304
|
+
setSelected(el, value);
|
|
1305
|
+
},
|
|
1306
|
+
beforeUpdate(el, _binding, vnode) {
|
|
1307
|
+
el._assign = getModelAssigner(vnode);
|
|
1308
|
+
},
|
|
1309
|
+
updated(el, { value }) {
|
|
1310
|
+
setSelected(el, value);
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
function setSelected(el, value) {
|
|
1314
|
+
const isMultiple = el.multiple;
|
|
1315
|
+
if (isMultiple && !isArray(value) && !isSet(value)) {
|
|
1316
|
+
(process.env.NODE_ENV !== 'production') &&
|
|
1317
|
+
warn(`<select multiple v-model> expects an Array or Set value for its binding, ` +
|
|
1318
|
+
`but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
for (let i = 0, l = el.options.length; i < l; i++) {
|
|
1322
|
+
const option = el.options[i];
|
|
1323
|
+
const optionValue = getValue(option);
|
|
1324
|
+
if (isMultiple) {
|
|
1325
|
+
if (isArray(value)) {
|
|
1326
|
+
option.selected = looseIndexOf(value, optionValue) > -1;
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
option.selected = value.has(optionValue);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
else {
|
|
1333
|
+
if (looseEqual(getValue(option), value)) {
|
|
1334
|
+
if (el.selectedIndex !== i)
|
|
1335
|
+
el.selectedIndex = i;
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
if (!isMultiple && el.selectedIndex !== -1) {
|
|
1341
|
+
el.selectedIndex = -1;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
// retrieve raw value set via :value bindings
|
|
1345
|
+
function getValue(el) {
|
|
1346
|
+
return '_value' in el ? el._value : el.value;
|
|
1347
|
+
}
|
|
1348
|
+
// retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
|
|
1349
|
+
function getCheckboxValue(el, checked) {
|
|
1350
|
+
const key = checked ? '_trueValue' : '_falseValue';
|
|
1351
|
+
return key in el ? el[key] : checked;
|
|
1352
|
+
}
|
|
1353
|
+
const vModelDynamic = {
|
|
1354
|
+
created(el, binding, vnode) {
|
|
1355
|
+
callModelHook(el, binding, vnode, null, 'created');
|
|
1356
|
+
},
|
|
1357
|
+
mounted(el, binding, vnode) {
|
|
1358
|
+
callModelHook(el, binding, vnode, null, 'mounted');
|
|
1359
|
+
},
|
|
1360
|
+
beforeUpdate(el, binding, vnode, prevVNode) {
|
|
1361
|
+
callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
|
|
1362
|
+
},
|
|
1363
|
+
updated(el, binding, vnode, prevVNode) {
|
|
1364
|
+
callModelHook(el, binding, vnode, prevVNode, 'updated');
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
function resolveDynamicModel(tagName, type) {
|
|
1368
|
+
switch (tagName) {
|
|
1369
|
+
case 'SELECT':
|
|
1370
|
+
return vModelSelect;
|
|
1371
|
+
case 'TEXTAREA':
|
|
1372
|
+
return vModelText;
|
|
1373
|
+
default:
|
|
1374
|
+
switch (type) {
|
|
1375
|
+
case 'checkbox':
|
|
1376
|
+
return vModelCheckbox;
|
|
1377
|
+
case 'radio':
|
|
1378
|
+
return vModelRadio;
|
|
1379
|
+
default:
|
|
1380
|
+
return vModelText;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
function callModelHook(el, binding, vnode, prevVNode, hook) {
|
|
1385
|
+
const modelToUse = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type);
|
|
1386
|
+
const fn = modelToUse[hook];
|
|
1387
|
+
fn && fn(el, binding, vnode, prevVNode);
|
|
1388
|
+
}
|
|
1389
|
+
// SSR vnode transforms, only used when user includes client-oriented render
|
|
1390
|
+
// function in SSR
|
|
1391
|
+
function initVModelForSSR() {
|
|
1392
|
+
vModelText.getSSRProps = ({ value }) => ({ value });
|
|
1393
|
+
vModelRadio.getSSRProps = ({ value }, vnode) => {
|
|
1394
|
+
if (vnode.props && looseEqual(vnode.props.value, value)) {
|
|
1395
|
+
return { checked: true };
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
vModelCheckbox.getSSRProps = ({ value }, vnode) => {
|
|
1399
|
+
if (isArray(value)) {
|
|
1400
|
+
if (vnode.props && looseIndexOf(value, vnode.props.value) > -1) {
|
|
1401
|
+
return { checked: true };
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
else if (isSet(value)) {
|
|
1405
|
+
if (vnode.props && value.has(vnode.props.value)) {
|
|
1406
|
+
return { checked: true };
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
else if (value) {
|
|
1410
|
+
return { checked: true };
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1413
|
+
vModelDynamic.getSSRProps = (binding, vnode) => {
|
|
1414
|
+
if (typeof vnode.type !== 'string') {
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
const modelToUse = resolveDynamicModel(
|
|
1418
|
+
// resolveDynamicModel expects an uppercase tag name, but vnode.type is lowercase
|
|
1419
|
+
vnode.type.toUpperCase(), vnode.props && vnode.props.type);
|
|
1420
|
+
if (modelToUse.getSSRProps) {
|
|
1421
|
+
return modelToUse.getSSRProps(binding, vnode);
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1456
1424
|
}
|
|
1457
1425
|
|
|
1458
|
-
const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
|
|
1459
|
-
const modifierGuards = {
|
|
1460
|
-
stop: e => e.stopPropagation(),
|
|
1461
|
-
prevent: e => e.preventDefault(),
|
|
1462
|
-
self: e => e.target !== e.currentTarget,
|
|
1463
|
-
ctrl: e => !e.ctrlKey,
|
|
1464
|
-
shift: e => !e.shiftKey,
|
|
1465
|
-
alt: e => !e.altKey,
|
|
1466
|
-
meta: e => !e.metaKey,
|
|
1467
|
-
left: e => 'button' in e && e.button !== 0,
|
|
1468
|
-
middle: e => 'button' in e && e.button !== 1,
|
|
1469
|
-
right: e => 'button' in e && e.button !== 2,
|
|
1470
|
-
exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
|
|
1471
|
-
};
|
|
1472
|
-
/**
|
|
1473
|
-
* @private
|
|
1474
|
-
*/
|
|
1475
|
-
const withModifiers = (fn, modifiers) => {
|
|
1476
|
-
return (event, ...args) => {
|
|
1477
|
-
for (let i = 0; i < modifiers.length; i++) {
|
|
1478
|
-
const guard = modifierGuards[modifiers[i]];
|
|
1479
|
-
if (guard && guard(event, modifiers))
|
|
1480
|
-
return;
|
|
1481
|
-
}
|
|
1482
|
-
return fn(event, ...args);
|
|
1483
|
-
};
|
|
1484
|
-
};
|
|
1485
|
-
// Kept for 2.x compat.
|
|
1486
|
-
// Note: IE11 compat for `spacebar` and `del` is removed for now.
|
|
1487
|
-
const keyNames = {
|
|
1488
|
-
esc: 'escape',
|
|
1489
|
-
space: ' ',
|
|
1490
|
-
up: 'arrow-up',
|
|
1491
|
-
left: 'arrow-left',
|
|
1492
|
-
right: 'arrow-right',
|
|
1493
|
-
down: 'arrow-down',
|
|
1494
|
-
delete: 'backspace'
|
|
1495
|
-
};
|
|
1496
|
-
/**
|
|
1497
|
-
* @private
|
|
1498
|
-
*/
|
|
1499
|
-
const withKeys = (fn, modifiers) => {
|
|
1500
|
-
return (event) => {
|
|
1501
|
-
if (!('key' in event)) {
|
|
1502
|
-
return;
|
|
1503
|
-
}
|
|
1504
|
-
const eventKey = hyphenate(event.key);
|
|
1505
|
-
if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
|
|
1506
|
-
return fn(event);
|
|
1507
|
-
}
|
|
1508
|
-
};
|
|
1426
|
+
const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
|
|
1427
|
+
const modifierGuards = {
|
|
1428
|
+
stop: e => e.stopPropagation(),
|
|
1429
|
+
prevent: e => e.preventDefault(),
|
|
1430
|
+
self: e => e.target !== e.currentTarget,
|
|
1431
|
+
ctrl: e => !e.ctrlKey,
|
|
1432
|
+
shift: e => !e.shiftKey,
|
|
1433
|
+
alt: e => !e.altKey,
|
|
1434
|
+
meta: e => !e.metaKey,
|
|
1435
|
+
left: e => 'button' in e && e.button !== 0,
|
|
1436
|
+
middle: e => 'button' in e && e.button !== 1,
|
|
1437
|
+
right: e => 'button' in e && e.button !== 2,
|
|
1438
|
+
exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
|
|
1439
|
+
};
|
|
1440
|
+
/**
|
|
1441
|
+
* @private
|
|
1442
|
+
*/
|
|
1443
|
+
const withModifiers = (fn, modifiers) => {
|
|
1444
|
+
return (event, ...args) => {
|
|
1445
|
+
for (let i = 0; i < modifiers.length; i++) {
|
|
1446
|
+
const guard = modifierGuards[modifiers[i]];
|
|
1447
|
+
if (guard && guard(event, modifiers))
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
return fn(event, ...args);
|
|
1451
|
+
};
|
|
1452
|
+
};
|
|
1453
|
+
// Kept for 2.x compat.
|
|
1454
|
+
// Note: IE11 compat for `spacebar` and `del` is removed for now.
|
|
1455
|
+
const keyNames = {
|
|
1456
|
+
esc: 'escape',
|
|
1457
|
+
space: ' ',
|
|
1458
|
+
up: 'arrow-up',
|
|
1459
|
+
left: 'arrow-left',
|
|
1460
|
+
right: 'arrow-right',
|
|
1461
|
+
down: 'arrow-down',
|
|
1462
|
+
delete: 'backspace'
|
|
1463
|
+
};
|
|
1464
|
+
/**
|
|
1465
|
+
* @private
|
|
1466
|
+
*/
|
|
1467
|
+
const withKeys = (fn, modifiers) => {
|
|
1468
|
+
return (event) => {
|
|
1469
|
+
if (!('key' in event)) {
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1472
|
+
const eventKey = hyphenate(event.key);
|
|
1473
|
+
if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
|
|
1474
|
+
return fn(event);
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1509
1477
|
};
|
|
1510
1478
|
|
|
1511
|
-
const vShow = {
|
|
1512
|
-
beforeMount(el, { value }, { transition }) {
|
|
1513
|
-
el._vod = el.style.display === 'none' ? '' : el.style.display;
|
|
1514
|
-
if (transition && value) {
|
|
1515
|
-
transition.beforeEnter(el);
|
|
1516
|
-
}
|
|
1517
|
-
else {
|
|
1518
|
-
setDisplay(el, value);
|
|
1519
|
-
}
|
|
1520
|
-
},
|
|
1521
|
-
mounted(el, { value }, { transition }) {
|
|
1522
|
-
if (transition && value) {
|
|
1523
|
-
transition.enter(el);
|
|
1524
|
-
}
|
|
1525
|
-
},
|
|
1526
|
-
updated(el, { value, oldValue }, { transition }) {
|
|
1527
|
-
if (!value === !oldValue)
|
|
1528
|
-
return;
|
|
1529
|
-
if (transition) {
|
|
1530
|
-
if (value) {
|
|
1531
|
-
transition.beforeEnter(el);
|
|
1532
|
-
setDisplay(el, true);
|
|
1533
|
-
transition.enter(el);
|
|
1534
|
-
}
|
|
1535
|
-
else {
|
|
1536
|
-
transition.leave(el, () => {
|
|
1537
|
-
setDisplay(el, false);
|
|
1538
|
-
});
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
else {
|
|
1542
|
-
setDisplay(el, value);
|
|
1543
|
-
}
|
|
1544
|
-
},
|
|
1545
|
-
beforeUnmount(el, { value }) {
|
|
1546
|
-
setDisplay(el, value);
|
|
1547
|
-
}
|
|
1548
|
-
};
|
|
1549
|
-
function setDisplay(el, value) {
|
|
1550
|
-
el.style.display = value ? el._vod : 'none';
|
|
1551
|
-
}
|
|
1552
|
-
// SSR vnode transforms, only used when user includes client-oriented render
|
|
1553
|
-
// function in SSR
|
|
1554
|
-
function initVShowForSSR() {
|
|
1555
|
-
vShow.getSSRProps = ({ value }) => {
|
|
1556
|
-
if (!value) {
|
|
1557
|
-
return { style: { display: 'none' } };
|
|
1558
|
-
}
|
|
1559
|
-
};
|
|
1479
|
+
const vShow = {
|
|
1480
|
+
beforeMount(el, { value }, { transition }) {
|
|
1481
|
+
el._vod = el.style.display === 'none' ? '' : el.style.display;
|
|
1482
|
+
if (transition && value) {
|
|
1483
|
+
transition.beforeEnter(el);
|
|
1484
|
+
}
|
|
1485
|
+
else {
|
|
1486
|
+
setDisplay(el, value);
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
mounted(el, { value }, { transition }) {
|
|
1490
|
+
if (transition && value) {
|
|
1491
|
+
transition.enter(el);
|
|
1492
|
+
}
|
|
1493
|
+
},
|
|
1494
|
+
updated(el, { value, oldValue }, { transition }) {
|
|
1495
|
+
if (!value === !oldValue)
|
|
1496
|
+
return;
|
|
1497
|
+
if (transition) {
|
|
1498
|
+
if (value) {
|
|
1499
|
+
transition.beforeEnter(el);
|
|
1500
|
+
setDisplay(el, true);
|
|
1501
|
+
transition.enter(el);
|
|
1502
|
+
}
|
|
1503
|
+
else {
|
|
1504
|
+
transition.leave(el, () => {
|
|
1505
|
+
setDisplay(el, false);
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
else {
|
|
1510
|
+
setDisplay(el, value);
|
|
1511
|
+
}
|
|
1512
|
+
},
|
|
1513
|
+
beforeUnmount(el, { value }) {
|
|
1514
|
+
setDisplay(el, value);
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
function setDisplay(el, value) {
|
|
1518
|
+
el.style.display = value ? el._vod : 'none';
|
|
1519
|
+
}
|
|
1520
|
+
// SSR vnode transforms, only used when user includes client-oriented render
|
|
1521
|
+
// function in SSR
|
|
1522
|
+
function initVShowForSSR() {
|
|
1523
|
+
vShow.getSSRProps = ({ value }) => {
|
|
1524
|
+
if (!value) {
|
|
1525
|
+
return { style: { display: 'none' } };
|
|
1526
|
+
}
|
|
1527
|
+
};
|
|
1560
1528
|
}
|
|
1561
1529
|
|
|
1562
|
-
const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps);
|
|
1563
|
-
// lazy create the renderer - this makes core renderer logic tree-shakable
|
|
1564
|
-
// in case the user only imports reactivity utilities from Vue.
|
|
1565
|
-
let renderer;
|
|
1566
|
-
let enabledHydration = false;
|
|
1567
|
-
function ensureRenderer() {
|
|
1568
|
-
return (renderer ||
|
|
1569
|
-
(renderer = createRenderer(rendererOptions)));
|
|
1570
|
-
}
|
|
1571
|
-
function ensureHydrationRenderer() {
|
|
1572
|
-
renderer = enabledHydration
|
|
1573
|
-
? renderer
|
|
1574
|
-
: createHydrationRenderer(rendererOptions);
|
|
1575
|
-
enabledHydration = true;
|
|
1576
|
-
return renderer;
|
|
1577
|
-
}
|
|
1578
|
-
// use explicit type casts here to avoid import() calls in rolled-up d.ts
|
|
1579
|
-
const render = ((...args) => {
|
|
1580
|
-
ensureRenderer().render(...args);
|
|
1581
|
-
});
|
|
1582
|
-
const hydrate = ((...args) => {
|
|
1583
|
-
ensureHydrationRenderer().hydrate(...args);
|
|
1584
|
-
});
|
|
1585
|
-
const createApp = ((...args) => {
|
|
1586
|
-
const app = ensureRenderer().createApp(...args);
|
|
1587
|
-
if ((process.env.NODE_ENV !== 'production')) {
|
|
1588
|
-
injectNativeTagCheck(app);
|
|
1589
|
-
injectCompilerOptionsCheck(app);
|
|
1590
|
-
}
|
|
1591
|
-
const { mount } = app;
|
|
1592
|
-
app.mount = (containerOrSelector) => {
|
|
1593
|
-
const container = normalizeContainer(containerOrSelector);
|
|
1594
|
-
if (!container)
|
|
1595
|
-
return;
|
|
1596
|
-
const component = app._component;
|
|
1597
|
-
if (!isFunction(component) && !component.render && !component.template) {
|
|
1598
|
-
// __UNSAFE__
|
|
1599
|
-
// Reason: potential execution of JS expressions in in-DOM template.
|
|
1600
|
-
// The user must make sure the in-DOM template is trusted. If it's
|
|
1601
|
-
// rendered by the server, the template should not contain any user data.
|
|
1602
|
-
component.template = container.innerHTML;
|
|
1603
|
-
}
|
|
1604
|
-
// clear content before mounting
|
|
1605
|
-
container.innerHTML = '';
|
|
1606
|
-
const proxy = mount(container, false, container instanceof SVGElement);
|
|
1607
|
-
if (container instanceof Element) {
|
|
1608
|
-
container.removeAttribute('v-cloak');
|
|
1609
|
-
container.setAttribute('data-v-app', '');
|
|
1610
|
-
}
|
|
1611
|
-
return proxy;
|
|
1612
|
-
};
|
|
1613
|
-
return app;
|
|
1614
|
-
});
|
|
1615
|
-
const createSSRApp = ((...args) => {
|
|
1616
|
-
const app = ensureHydrationRenderer().createApp(...args);
|
|
1617
|
-
if ((process.env.NODE_ENV !== 'production')) {
|
|
1618
|
-
injectNativeTagCheck(app);
|
|
1619
|
-
injectCompilerOptionsCheck(app);
|
|
1620
|
-
}
|
|
1621
|
-
const { mount } = app;
|
|
1622
|
-
app.mount = (containerOrSelector) => {
|
|
1623
|
-
const container = normalizeContainer(containerOrSelector);
|
|
1624
|
-
if (container) {
|
|
1625
|
-
return mount(container, true, container instanceof SVGElement);
|
|
1626
|
-
}
|
|
1627
|
-
};
|
|
1628
|
-
return app;
|
|
1629
|
-
});
|
|
1630
|
-
function injectNativeTagCheck(app) {
|
|
1631
|
-
// Inject `isNativeTag`
|
|
1632
|
-
// this is used for component name validation (dev only)
|
|
1633
|
-
Object.defineProperty(app.config, 'isNativeTag', {
|
|
1634
|
-
value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
|
|
1635
|
-
writable: false
|
|
1636
|
-
});
|
|
1637
|
-
}
|
|
1638
|
-
// dev only
|
|
1639
|
-
function injectCompilerOptionsCheck(app) {
|
|
1640
|
-
if (isRuntimeOnly()) {
|
|
1641
|
-
const isCustomElement = app.config.isCustomElement;
|
|
1642
|
-
Object.defineProperty(app.config, 'isCustomElement', {
|
|
1643
|
-
get() {
|
|
1644
|
-
return isCustomElement;
|
|
1645
|
-
},
|
|
1646
|
-
set() {
|
|
1647
|
-
warn(`The \`isCustomElement\` config option is deprecated. Use ` +
|
|
1648
|
-
`\`compilerOptions.isCustomElement\` instead.`);
|
|
1649
|
-
}
|
|
1650
|
-
});
|
|
1651
|
-
const compilerOptions = app.config.compilerOptions;
|
|
1652
|
-
const msg = `The \`compilerOptions\` config option is only respected when using ` +
|
|
1653
|
-
`a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
|
|
1654
|
-
`Since you are using the runtime-only build, \`compilerOptions\` ` +
|
|
1655
|
-
`must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
|
|
1656
|
-
`- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
|
|
1657
|
-
`- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
|
|
1658
|
-
`- For vite: pass it via @vitejs/plugin-vue options. See https://github.com/vitejs/vite/tree/main/packages/plugin-vue#example-for-passing-options-to-vuecompiler-dom`;
|
|
1659
|
-
Object.defineProperty(app.config, 'compilerOptions', {
|
|
1660
|
-
get() {
|
|
1661
|
-
warn(msg);
|
|
1662
|
-
return compilerOptions;
|
|
1663
|
-
},
|
|
1664
|
-
set() {
|
|
1665
|
-
warn(msg);
|
|
1666
|
-
}
|
|
1667
|
-
});
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
function normalizeContainer(container) {
|
|
1671
|
-
if (isString(container)) {
|
|
1672
|
-
const res = document.querySelector(container);
|
|
1673
|
-
if ((process.env.NODE_ENV !== 'production') && !res) {
|
|
1674
|
-
warn(`Failed to mount app: mount target selector "${container}" returned null.`);
|
|
1675
|
-
}
|
|
1676
|
-
return res;
|
|
1677
|
-
}
|
|
1678
|
-
if ((process.env.NODE_ENV !== 'production') &&
|
|
1679
|
-
window.ShadowRoot &&
|
|
1680
|
-
container instanceof window.ShadowRoot &&
|
|
1681
|
-
container.mode === 'closed') {
|
|
1682
|
-
warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
|
|
1683
|
-
}
|
|
1684
|
-
return container;
|
|
1685
|
-
}
|
|
1686
|
-
let ssrDirectiveInitialized = false;
|
|
1687
|
-
/**
|
|
1688
|
-
* @internal
|
|
1689
|
-
*/
|
|
1690
|
-
const initDirectivesForSSR = () => {
|
|
1691
|
-
if (!ssrDirectiveInitialized) {
|
|
1692
|
-
ssrDirectiveInitialized = true;
|
|
1693
|
-
initVModelForSSR();
|
|
1694
|
-
initVShowForSSR();
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1530
|
+
const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps);
|
|
1531
|
+
// lazy create the renderer - this makes core renderer logic tree-shakable
|
|
1532
|
+
// in case the user only imports reactivity utilities from Vue.
|
|
1533
|
+
let renderer;
|
|
1534
|
+
let enabledHydration = false;
|
|
1535
|
+
function ensureRenderer() {
|
|
1536
|
+
return (renderer ||
|
|
1537
|
+
(renderer = createRenderer(rendererOptions)));
|
|
1538
|
+
}
|
|
1539
|
+
function ensureHydrationRenderer() {
|
|
1540
|
+
renderer = enabledHydration
|
|
1541
|
+
? renderer
|
|
1542
|
+
: createHydrationRenderer(rendererOptions);
|
|
1543
|
+
enabledHydration = true;
|
|
1544
|
+
return renderer;
|
|
1545
|
+
}
|
|
1546
|
+
// use explicit type casts here to avoid import() calls in rolled-up d.ts
|
|
1547
|
+
const render = ((...args) => {
|
|
1548
|
+
ensureRenderer().render(...args);
|
|
1549
|
+
});
|
|
1550
|
+
const hydrate = ((...args) => {
|
|
1551
|
+
ensureHydrationRenderer().hydrate(...args);
|
|
1552
|
+
});
|
|
1553
|
+
const createApp = ((...args) => {
|
|
1554
|
+
const app = ensureRenderer().createApp(...args);
|
|
1555
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
1556
|
+
injectNativeTagCheck(app);
|
|
1557
|
+
injectCompilerOptionsCheck(app);
|
|
1558
|
+
}
|
|
1559
|
+
const { mount } = app;
|
|
1560
|
+
app.mount = (containerOrSelector) => {
|
|
1561
|
+
const container = normalizeContainer(containerOrSelector);
|
|
1562
|
+
if (!container)
|
|
1563
|
+
return;
|
|
1564
|
+
const component = app._component;
|
|
1565
|
+
if (!isFunction(component) && !component.render && !component.template) {
|
|
1566
|
+
// __UNSAFE__
|
|
1567
|
+
// Reason: potential execution of JS expressions in in-DOM template.
|
|
1568
|
+
// The user must make sure the in-DOM template is trusted. If it's
|
|
1569
|
+
// rendered by the server, the template should not contain any user data.
|
|
1570
|
+
component.template = container.innerHTML;
|
|
1571
|
+
}
|
|
1572
|
+
// clear content before mounting
|
|
1573
|
+
container.innerHTML = '';
|
|
1574
|
+
const proxy = mount(container, false, container instanceof SVGElement);
|
|
1575
|
+
if (container instanceof Element) {
|
|
1576
|
+
container.removeAttribute('v-cloak');
|
|
1577
|
+
container.setAttribute('data-v-app', '');
|
|
1578
|
+
}
|
|
1579
|
+
return proxy;
|
|
1580
|
+
};
|
|
1581
|
+
return app;
|
|
1582
|
+
});
|
|
1583
|
+
const createSSRApp = ((...args) => {
|
|
1584
|
+
const app = ensureHydrationRenderer().createApp(...args);
|
|
1585
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
1586
|
+
injectNativeTagCheck(app);
|
|
1587
|
+
injectCompilerOptionsCheck(app);
|
|
1588
|
+
}
|
|
1589
|
+
const { mount } = app;
|
|
1590
|
+
app.mount = (containerOrSelector) => {
|
|
1591
|
+
const container = normalizeContainer(containerOrSelector);
|
|
1592
|
+
if (container) {
|
|
1593
|
+
return mount(container, true, container instanceof SVGElement);
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
return app;
|
|
1597
|
+
});
|
|
1598
|
+
function injectNativeTagCheck(app) {
|
|
1599
|
+
// Inject `isNativeTag`
|
|
1600
|
+
// this is used for component name validation (dev only)
|
|
1601
|
+
Object.defineProperty(app.config, 'isNativeTag', {
|
|
1602
|
+
value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
|
|
1603
|
+
writable: false
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
// dev only
|
|
1607
|
+
function injectCompilerOptionsCheck(app) {
|
|
1608
|
+
if (isRuntimeOnly()) {
|
|
1609
|
+
const isCustomElement = app.config.isCustomElement;
|
|
1610
|
+
Object.defineProperty(app.config, 'isCustomElement', {
|
|
1611
|
+
get() {
|
|
1612
|
+
return isCustomElement;
|
|
1613
|
+
},
|
|
1614
|
+
set() {
|
|
1615
|
+
warn(`The \`isCustomElement\` config option is deprecated. Use ` +
|
|
1616
|
+
`\`compilerOptions.isCustomElement\` instead.`);
|
|
1617
|
+
}
|
|
1618
|
+
});
|
|
1619
|
+
const compilerOptions = app.config.compilerOptions;
|
|
1620
|
+
const msg = `The \`compilerOptions\` config option is only respected when using ` +
|
|
1621
|
+
`a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
|
|
1622
|
+
`Since you are using the runtime-only build, \`compilerOptions\` ` +
|
|
1623
|
+
`must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
|
|
1624
|
+
`- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
|
|
1625
|
+
`- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
|
|
1626
|
+
`- For vite: pass it via @vitejs/plugin-vue options. See https://github.com/vitejs/vite/tree/main/packages/plugin-vue#example-for-passing-options-to-vuecompiler-dom`;
|
|
1627
|
+
Object.defineProperty(app.config, 'compilerOptions', {
|
|
1628
|
+
get() {
|
|
1629
|
+
warn(msg);
|
|
1630
|
+
return compilerOptions;
|
|
1631
|
+
},
|
|
1632
|
+
set() {
|
|
1633
|
+
warn(msg);
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
function normalizeContainer(container) {
|
|
1639
|
+
if (isString(container)) {
|
|
1640
|
+
const res = document.querySelector(container);
|
|
1641
|
+
if ((process.env.NODE_ENV !== 'production') && !res) {
|
|
1642
|
+
warn(`Failed to mount app: mount target selector "${container}" returned null.`);
|
|
1643
|
+
}
|
|
1644
|
+
return res;
|
|
1645
|
+
}
|
|
1646
|
+
if ((process.env.NODE_ENV !== 'production') &&
|
|
1647
|
+
window.ShadowRoot &&
|
|
1648
|
+
container instanceof window.ShadowRoot &&
|
|
1649
|
+
container.mode === 'closed') {
|
|
1650
|
+
warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
|
|
1651
|
+
}
|
|
1652
|
+
return container;
|
|
1653
|
+
}
|
|
1654
|
+
let ssrDirectiveInitialized = false;
|
|
1655
|
+
/**
|
|
1656
|
+
* @internal
|
|
1657
|
+
*/
|
|
1658
|
+
const initDirectivesForSSR = () => {
|
|
1659
|
+
if (!ssrDirectiveInitialized) {
|
|
1660
|
+
ssrDirectiveInitialized = true;
|
|
1661
|
+
initVModelForSSR();
|
|
1662
|
+
initVShowForSSR();
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1697
1665
|
;
|
|
1698
1666
|
|
|
1699
1667
|
export { Transition, TransitionGroup, VueElement, createApp, createSSRApp, defineCustomElement, defineSSRCustomElement, hydrate, initDirectivesForSSR, render, useCssModule, useCssVars, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, withKeys, withModifiers };
|