Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 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 328 329 330 331 | 43x 43x 43x 43x 128x 128x 1x 1x 1x 1x 1x 1x 1x 1x 43x 10x 10x 10x 12x 11x 11x 1x 10x 2x 11x 10x 1x 10x 9x 9x 9x 10x 21x 21x 21x 21x 21x 8x 43x 8x 8x 14x 14x 14x 14x 14x 4x 4x 4x 2x 2x 2x 2x 2x 10x 4x 4x 2x 2x 4x 6x 40x 40x 48x 48x 16x 32x 16x 16x 16x 43x 2x 2x 2x 2x 10x 10x 10x 43x 7x 7x 18x 36x 23x 18x 7x 7x 30x 30x 37x 37x 37x 71x 71x 71x 60x 36x 24x 11x 5x 5x 32x 121x 22x 22x 43x 25x 25x 98x 98x 246x 74x 74x 6x 6x 166x 94x 94x 24x 24x 48x 246x 246x 43x 8x 8x 2x 1x 8x 4x 2x 1x 2x 2x 1x | import { ObjectDirective, VNode, DirectiveHook, DirectiveBinding, warn } from '@vue/runtime-core' import { addEventListener } from '../modules/events' import { isArray, looseEqual, looseIndexOf, invokeArrayFns, toNumber, isSet } from '@vue/shared' type AssignerFn = (value: any) => void const getModelAssigner = (vnode: VNode): AssignerFn => { const fn = vnode.props!['onUpdate:modelValue'] return isArray(fn) ? value => invokeArrayFns(fn, value) : fn } function onCompositionStart(e: Event) { ;(e.target as any).composing = true } function onCompositionEnd(e: Event) { const target = e.target as any if (target.composing) { target.composing = false trigger(target, 'input') } } function trigger(el: HTMLElement, type: string) { const e = document.createEvent('HTMLEvents') e.initEvent(type, true, true) el.dispatchEvent(e) } type ModelDirective<T> = ObjectDirective<T & { _assign: AssignerFn }> // We are exporting the v-model runtime directly as vnode hooks so that it can // be tree-shaken in case v-model is never used. export const vModelText: ModelDirective< HTMLInputElement | HTMLTextAreaElement > = { created(el, { modifiers: { lazy, trim, number } }, vnode) { el._assign = getModelAssigner(vnode) const castToNumber = number || (vnode.props && vnode.props.type === 'number') addEventListener(el, lazy ? 'change' : 'input', e => { if ((e.target as any).composing) return let domValue: string | number = el.value if (trim) { domValue = domValue.trim() } else if (castToNumber) { domValue = toNumber(domValue) } el._assign(domValue) }) if (trim) { addEventListener(el, 'change', () => { el.value = el.value.trim() }) } if (!lazy) { addEventListener(el, 'compositionstart', onCompositionStart) addEventListener(el, 'compositionend', onCompositionEnd) // Safari < 10.2 & UIWebView doesn't fire compositionend when // switching focus before confirming composition choice // this also fixes the issue where some browsers e.g. iOS Chrome // fires "change" instead of "input" on autocomplete. addEventListener(el, 'change', onCompositionEnd) } }, // set value on mounted so it's after min/max for type="range" mounted(el, { value }) { el.value = value == null ? '' : value }, beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) { el._assign = getModelAssigner(vnode) // avoid clearing unresolved text. #2302 Iif ((el as any).composing) return Iif (document.activeElement === el) { Iif (lazy) { return } Iif (trim && el.value.trim() === value) { return } Iif ((number || el.type === 'number') && toNumber(el.value) === value) { return } } const newValue = value == null ? '' : value if (el.value !== newValue) { el.value = newValue } } } export const vModelCheckbox: ModelDirective<HTMLInputElement> = { // #4096 array checkboxes need to be deep traversed deep: true, created(el, _, vnode) { el._assign = getModelAssigner(vnode) addEventListener(el, 'change', () => { const modelValue = (el as any)._modelValue const elementValue = getValue(el) const checked = el.checked const assign = el._assign if (isArray(modelValue)) { const index = looseIndexOf(modelValue, elementValue) const found = index !== -1 if (checked && !found) { assign(modelValue.concat(elementValue)) } else if (!checked && found) { const filtered = [...modelValue] filtered.splice(index, 1) assign(filtered) } } else if (isSet(modelValue)) { const cloned = new Set(modelValue) if (checked) { cloned.add(elementValue) } else { cloned.delete(elementValue) } assign(cloned) } else { assign(getCheckboxValue(el, checked)) } }) }, // set initial checked on mount to wait for true-value/false-value mounted: setChecked, beforeUpdate(el, binding, vnode) { el._assign = getModelAssigner(vnode) setChecked(el, binding, vnode) } } function setChecked( el: HTMLInputElement, { value, oldValue }: DirectiveBinding, vnode: VNode ) { // store the v-model value on the element so it can be accessed by the // change listener. ;(el as any)._modelValue = value if (isArray(value)) { el.checked = looseIndexOf(value, vnode.props!.value) > -1 } else if (isSet(value)) { el.checked = value.has(vnode.props!.value) } else if (value !== oldValue) { el.checked = looseEqual(value, getCheckboxValue(el, true)) } } export const vModelRadio: ModelDirective<HTMLInputElement> = { created(el, { value }, vnode) { el.checked = looseEqual(value, vnode.props!.value) el._assign = getModelAssigner(vnode) addEventListener(el, 'change', () => { el._assign(getValue(el)) }) }, beforeUpdate(el, { value, oldValue }, vnode) { el._assign = getModelAssigner(vnode) if (value !== oldValue) { el.checked = looseEqual(value, vnode.props!.value) } } } export const vModelSelect: ModelDirective<HTMLSelectElement> = { // <select multiple> value need to be deep traversed deep: true, created(el, { value, modifiers: { number } }, vnode) { const isSetModel = isSet(value) addEventListener(el, 'change', () => { const selectedVal = Array.prototype.filter .call(el.options, (o: HTMLOptionElement) => o.selected) .map((o: HTMLOptionElement) => number ? toNumber(getValue(o)) : getValue(o) ) el._assign( el.multiple ? isSetModel ? new Set(selectedVal) : selectedVal : selectedVal[0] ) }) el._assign = getModelAssigner(vnode) }, // set value in mounted & updated because <select> relies on its children // <option>s. mounted(el, { value }) { setSelected(el, value) }, beforeUpdate(el, _binding, vnode) { el._assign = getModelAssigner(vnode) }, updated(el, { value }) { setSelected(el, value) } } function setSelected(el: HTMLSelectElement, value: any) { const isMultiple = el.multiple Iif (isMultiple && !isArray(value) && !isSet(value)) { __DEV__ && warn( `<select multiple v-model> expects an Array or Set value for its binding, ` + `but got ${Object.prototype.toString.call(value).slice(8, -1)}.` ) return } for (let i = 0, l = el.options.length; i < l; i++) { const option = el.options[i] const optionValue = getValue(option) if (isMultiple) { if (isArray(value)) { option.selected = looseIndexOf(value, optionValue) > -1 } else { option.selected = value.has(optionValue) } } else { if (looseEqual(getValue(option), value)) { if (el.selectedIndex !== i) el.selectedIndex = i return } } } Iif (!isMultiple && el.selectedIndex !== -1) { el.selectedIndex = -1 } } // retrieve raw value set via :value bindings function getValue(el: HTMLOptionElement | HTMLInputElement) { return '_value' in el ? (el as any)._value : el.value } // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings function getCheckboxValue( el: HTMLInputElement & { _trueValue?: any; _falseValue?: any }, checked: boolean ) { const key = checked ? '_trueValue' : '_falseValue' return key in el ? el[key] : checked } export const vModelDynamic: ObjectDirective< HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement > = { created(el, binding, vnode) { callModelHook(el, binding, vnode, null, 'created') }, mounted(el, binding, vnode) { callModelHook(el, binding, vnode, null, 'mounted') }, beforeUpdate(el, binding, vnode, prevVNode) { callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate') }, updated(el, binding, vnode, prevVNode) { callModelHook(el, binding, vnode, prevVNode, 'updated') } } function callModelHook( el: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, binding: DirectiveBinding, vnode: VNode, prevVNode: VNode | null, hook: keyof ObjectDirective ) { let modelToUse: ObjectDirective switch (el.tagName) { case 'SELECT': modelToUse = vModelSelect break case 'TEXTAREA': modelToUse = vModelText break default: switch (vnode.props && vnode.props.type) { case 'checkbox': modelToUse = vModelCheckbox break case 'radio': modelToUse = vModelRadio break default: modelToUse = vModelText } } const fn = modelToUse[hook] as DirectiveHook fn && fn(el, binding, vnode, prevVNode) } // SSR vnode transforms, only used when user includes client-oriented render // function in SSR export function initVModelForSSR() { vModelText.getSSRProps = ({ value }) => ({ value }) vModelRadio.getSSRProps = ({ value }, vnode) => { if (vnode.props && looseEqual(vnode.props.value, value)) { return { checked: true } } } vModelCheckbox.getSSRProps = ({ value }, vnode) => { if (isArray(value)) { if (vnode.props && looseIndexOf(value, vnode.props.value) > -1) { return { checked: true } } } else Iif (isSet(value)) { Iif (vnode.props && value.has(vnode.props.value)) { return { checked: true } } } else if (value) { return { checked: true } } } } |