nav tabs on admin dashboard
This commit is contained in:
55
node_modules/vue/src/compiler/codegen/events.js
generated
vendored
55
node_modules/vue/src/compiler/codegen/events.js
generated
vendored
@@ -1,6 +1,7 @@
|
||||
/* @flow */
|
||||
|
||||
const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/
|
||||
const fnInvokeRE = /\([^)]*?\);*$/
|
||||
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/
|
||||
|
||||
// KeyboardEvent.keyCode aliases
|
||||
@@ -18,16 +19,19 @@ const keyCodes: { [key: string]: number | Array<number> } = {
|
||||
|
||||
// KeyboardEvent.key aliases
|
||||
const keyNames: { [key: string]: string | Array<string> } = {
|
||||
esc: 'Escape',
|
||||
// #7880: IE11 and Edge use `Esc` for Escape key name.
|
||||
esc: ['Esc', 'Escape'],
|
||||
tab: 'Tab',
|
||||
enter: 'Enter',
|
||||
space: ' ',
|
||||
// #9112: IE11 uses `Spacebar` for Space key name.
|
||||
space: [' ', 'Spacebar'],
|
||||
// #7806: IE11 uses key names without `Arrow` prefix for arrow keys.
|
||||
up: ['Up', 'ArrowUp'],
|
||||
left: ['Left', 'ArrowLeft'],
|
||||
right: ['Right', 'ArrowRight'],
|
||||
down: ['Down', 'ArrowDown'],
|
||||
'delete': ['Backspace', 'Delete']
|
||||
// #9112: IE11 uses `Del` for Delete key name.
|
||||
'delete': ['Backspace', 'Delete', 'Del']
|
||||
}
|
||||
|
||||
// #4868: modifiers that prevent the execution of the listener
|
||||
@@ -50,14 +54,25 @@ const modifierCode: { [key: string]: string } = {
|
||||
|
||||
export function genHandlers (
|
||||
events: ASTElementHandlers,
|
||||
isNative: boolean,
|
||||
warn: Function
|
||||
isNative: boolean
|
||||
): string {
|
||||
let res = isNative ? 'nativeOn:{' : 'on:{'
|
||||
const prefix = isNative ? 'nativeOn:' : 'on:'
|
||||
let staticHandlers = ``
|
||||
let dynamicHandlers = ``
|
||||
for (const name in events) {
|
||||
res += `"${name}":${genHandler(name, events[name])},`
|
||||
const handlerCode = genHandler(events[name])
|
||||
if (events[name] && events[name].dynamic) {
|
||||
dynamicHandlers += `${name},${handlerCode},`
|
||||
} else {
|
||||
staticHandlers += `"${name}":${handlerCode},`
|
||||
}
|
||||
}
|
||||
staticHandlers = `{${staticHandlers.slice(0, -1)}}`
|
||||
if (dynamicHandlers) {
|
||||
return prefix + `_d(${staticHandlers},[${dynamicHandlers.slice(0, -1)}])`
|
||||
} else {
|
||||
return prefix + staticHandlers
|
||||
}
|
||||
return res.slice(0, -1) + '}'
|
||||
}
|
||||
|
||||
// Generate handler code with binding params on Weex
|
||||
@@ -78,20 +93,18 @@ function genWeexHandler (params: Array<any>, handlerCode: string) {
|
||||
'}'
|
||||
}
|
||||
|
||||
function genHandler (
|
||||
name: string,
|
||||
handler: ASTElementHandler | Array<ASTElementHandler>
|
||||
): string {
|
||||
function genHandler (handler: ASTElementHandler | Array<ASTElementHandler>): string {
|
||||
if (!handler) {
|
||||
return 'function(){}'
|
||||
}
|
||||
|
||||
if (Array.isArray(handler)) {
|
||||
return `[${handler.map(handler => genHandler(name, handler)).join(',')}]`
|
||||
return `[${handler.map(handler => genHandler(handler)).join(',')}]`
|
||||
}
|
||||
|
||||
const isMethodPath = simplePathRE.test(handler.value)
|
||||
const isFunctionExpression = fnExpRE.test(handler.value)
|
||||
const isFunctionInvocation = simplePathRE.test(handler.value.replace(fnInvokeRE, ''))
|
||||
|
||||
if (!handler.modifiers) {
|
||||
if (isMethodPath || isFunctionExpression) {
|
||||
@@ -101,7 +114,9 @@ function genHandler (
|
||||
if (__WEEX__ && handler.params) {
|
||||
return genWeexHandler(handler.params, handler.value)
|
||||
}
|
||||
return `function($event){${handler.value}}` // inline statement
|
||||
return `function($event){${
|
||||
isFunctionInvocation ? `return ${handler.value}` : handler.value
|
||||
}}` // inline statement
|
||||
} else {
|
||||
let code = ''
|
||||
let genModifierCode = ''
|
||||
@@ -136,7 +151,9 @@ function genHandler (
|
||||
? `return ${handler.value}($event)`
|
||||
: isFunctionExpression
|
||||
? `return (${handler.value})($event)`
|
||||
: handler.value
|
||||
: isFunctionInvocation
|
||||
? `return ${handler.value}`
|
||||
: handler.value
|
||||
/* istanbul ignore if */
|
||||
if (__WEEX__ && handler.params) {
|
||||
return genWeexHandler(handler.params, code + handlerCode)
|
||||
@@ -146,7 +163,13 @@ function genHandler (
|
||||
}
|
||||
|
||||
function genKeyFilter (keys: Array<string>): string {
|
||||
return `if(!('button' in $event)&&${keys.map(genFilterCode).join('&&')})return null;`
|
||||
return (
|
||||
// make sure the key filters only apply to KeyboardEvents
|
||||
// #9441: can't use 'keyCode' in $event because Chrome autofill fires fake
|
||||
// key events that do not have keyCode property...
|
||||
`if(!$event.type.indexOf('key')&&` +
|
||||
`${keys.map(genFilterCode).join('&&')})return null;`
|
||||
)
|
||||
}
|
||||
|
||||
function genFilterCode (key: string): string {
|
||||
|
||||
205
node_modules/vue/src/compiler/codegen/index.js
generated
vendored
205
node_modules/vue/src/compiler/codegen/index.js
generated
vendored
@@ -4,6 +4,7 @@ import { genHandlers } from './events'
|
||||
import baseDirectives from '../directives/index'
|
||||
import { camelize, no, extend } from 'shared/util'
|
||||
import { baseWarn, pluckModuleFunction } from '../helpers'
|
||||
import { emptySlotScopeToken } from '../parser/index'
|
||||
|
||||
type TransformFunction = (el: ASTElement, code: string) => string;
|
||||
type DataGenFunction = (el: ASTElement) => string;
|
||||
@@ -18,6 +19,7 @@ export class CodegenState {
|
||||
maybeComponent: (el: ASTElement) => boolean;
|
||||
onceId: number;
|
||||
staticRenderFns: Array<string>;
|
||||
pre: boolean;
|
||||
|
||||
constructor (options: CompilerOptions) {
|
||||
this.options = options
|
||||
@@ -26,9 +28,10 @@ export class CodegenState {
|
||||
this.dataGenFns = pluckModuleFunction(options.modules, 'genData')
|
||||
this.directives = extend(extend({}, baseDirectives), options.directives)
|
||||
const isReservedTag = options.isReservedTag || no
|
||||
this.maybeComponent = (el: ASTElement) => !isReservedTag(el.tag)
|
||||
this.maybeComponent = (el: ASTElement) => !!el.component || !isReservedTag(el.tag)
|
||||
this.onceId = 0
|
||||
this.staticRenderFns = []
|
||||
this.pre = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +53,10 @@ export function generate (
|
||||
}
|
||||
|
||||
export function genElement (el: ASTElement, state: CodegenState): string {
|
||||
if (el.parent) {
|
||||
el.pre = el.pre || el.parent.pre
|
||||
}
|
||||
|
||||
if (el.staticRoot && !el.staticProcessed) {
|
||||
return genStatic(el, state)
|
||||
} else if (el.once && !el.onceProcessed) {
|
||||
@@ -58,7 +65,7 @@ export function genElement (el: ASTElement, state: CodegenState): string {
|
||||
return genFor(el, state)
|
||||
} else if (el.if && !el.ifProcessed) {
|
||||
return genIf(el, state)
|
||||
} else if (el.tag === 'template' && !el.slotTarget) {
|
||||
} else if (el.tag === 'template' && !el.slotTarget && !state.pre) {
|
||||
return genChildren(el, state) || 'void 0'
|
||||
} else if (el.tag === 'slot') {
|
||||
return genSlot(el, state)
|
||||
@@ -68,7 +75,10 @@ export function genElement (el: ASTElement, state: CodegenState): string {
|
||||
if (el.component) {
|
||||
code = genComponent(el.component, el, state)
|
||||
} else {
|
||||
const data = el.plain ? undefined : genData(el, state)
|
||||
let data
|
||||
if (!el.plain || (el.pre && state.maybeComponent(el))) {
|
||||
data = genData(el, state)
|
||||
}
|
||||
|
||||
const children = el.inlineTemplate ? null : genChildren(el, state, true)
|
||||
code = `_c('${el.tag}'${
|
||||
@@ -88,7 +98,15 @@ export function genElement (el: ASTElement, state: CodegenState): string {
|
||||
// hoist static sub-trees out
|
||||
function genStatic (el: ASTElement, state: CodegenState): string {
|
||||
el.staticProcessed = true
|
||||
// Some elements (templates) need to behave differently inside of a v-pre
|
||||
// node. All pre nodes are static roots, so we can use this as a location to
|
||||
// wrap a state change and reset it upon exiting the pre node.
|
||||
const originalPreState = state.pre
|
||||
if (el.pre) {
|
||||
state.pre = el.pre
|
||||
}
|
||||
state.staticRenderFns.push(`with(this){return ${genElement(el, state)}}`)
|
||||
state.pre = originalPreState
|
||||
return `_m(${
|
||||
state.staticRenderFns.length - 1
|
||||
}${
|
||||
@@ -113,7 +131,8 @@ function genOnce (el: ASTElement, state: CodegenState): string {
|
||||
}
|
||||
if (!key) {
|
||||
process.env.NODE_ENV !== 'production' && state.warn(
|
||||
`v-once can only be used inside v-for that is keyed. `
|
||||
`v-once can only be used inside v-for that is keyed. `,
|
||||
el.rawAttrsMap['v-once']
|
||||
)
|
||||
return genElement(el, state)
|
||||
}
|
||||
@@ -185,6 +204,7 @@ export function genFor (
|
||||
`<${el.tag} v-for="${alias} in ${exp}">: component lists rendered with ` +
|
||||
`v-for should have explicit keys. ` +
|
||||
`See https://vuejs.org/guide/list.html#key for more info.`,
|
||||
el.rawAttrsMap['v-for'],
|
||||
true /* tip */
|
||||
)
|
||||
}
|
||||
@@ -229,18 +249,18 @@ export function genData (el: ASTElement, state: CodegenState): string {
|
||||
}
|
||||
// attributes
|
||||
if (el.attrs) {
|
||||
data += `attrs:{${genProps(el.attrs)}},`
|
||||
data += `attrs:${genProps(el.attrs)},`
|
||||
}
|
||||
// DOM props
|
||||
if (el.props) {
|
||||
data += `domProps:{${genProps(el.props)}},`
|
||||
data += `domProps:${genProps(el.props)},`
|
||||
}
|
||||
// event handlers
|
||||
if (el.events) {
|
||||
data += `${genHandlers(el.events, false, state.warn)},`
|
||||
data += `${genHandlers(el.events, false)},`
|
||||
}
|
||||
if (el.nativeEvents) {
|
||||
data += `${genHandlers(el.nativeEvents, true, state.warn)},`
|
||||
data += `${genHandlers(el.nativeEvents, true)},`
|
||||
}
|
||||
// slot target
|
||||
// only for non-scoped slots
|
||||
@@ -249,7 +269,7 @@ export function genData (el: ASTElement, state: CodegenState): string {
|
||||
}
|
||||
// scoped slots
|
||||
if (el.scopedSlots) {
|
||||
data += `${genScopedSlots(el.scopedSlots, state)},`
|
||||
data += `${genScopedSlots(el, el.scopedSlots, state)},`
|
||||
}
|
||||
// component v-model
|
||||
if (el.model) {
|
||||
@@ -269,6 +289,12 @@ export function genData (el: ASTElement, state: CodegenState): string {
|
||||
}
|
||||
}
|
||||
data = data.replace(/,$/, '') + '}'
|
||||
// v-bind dynamic argument wrap
|
||||
// v-bind with dynamic arguments must be applied using the same v-bind object
|
||||
// merge helper so that class/style/mustUseProp attrs are handled correctly.
|
||||
if (el.dynamicAttrs) {
|
||||
data = `_b(${data},"${el.tag}",${genProps(el.dynamicAttrs)})`
|
||||
}
|
||||
// v-bind data wrap
|
||||
if (el.wrapData) {
|
||||
data = el.wrapData(data)
|
||||
@@ -300,7 +326,7 @@ function genDirectives (el: ASTElement, state: CodegenState): string | void {
|
||||
res += `{name:"${dir.name}",rawName:"${dir.rawName}"${
|
||||
dir.value ? `,value:(${dir.value}),expression:${JSON.stringify(dir.value)}` : ''
|
||||
}${
|
||||
dir.arg ? `,arg:"${dir.arg}"` : ''
|
||||
dir.arg ? `,arg:${dir.isDynamicArg ? dir.arg : `"${dir.arg}"`}` : ''
|
||||
}${
|
||||
dir.modifiers ? `,modifiers:${JSON.stringify(dir.modifiers)}` : ''
|
||||
}},`
|
||||
@@ -316,9 +342,12 @@ function genInlineTemplate (el: ASTElement, state: CodegenState): ?string {
|
||||
if (process.env.NODE_ENV !== 'production' && (
|
||||
el.children.length !== 1 || ast.type !== 1
|
||||
)) {
|
||||
state.warn('Inline-template components must have exactly one child element.')
|
||||
state.warn(
|
||||
'Inline-template components must have exactly one child element.',
|
||||
{ start: el.start }
|
||||
)
|
||||
}
|
||||
if (ast.type === 1) {
|
||||
if (ast && ast.type === 1) {
|
||||
const inlineRenderFns = generate(ast, state.options)
|
||||
return `inlineTemplate:{render:function(){${
|
||||
inlineRenderFns.render
|
||||
@@ -329,48 +358,106 @@ function genInlineTemplate (el: ASTElement, state: CodegenState): ?string {
|
||||
}
|
||||
|
||||
function genScopedSlots (
|
||||
el: ASTElement,
|
||||
slots: { [key: string]: ASTElement },
|
||||
state: CodegenState
|
||||
): string {
|
||||
return `scopedSlots:_u([${
|
||||
Object.keys(slots).map(key => {
|
||||
return genScopedSlot(key, slots[key], state)
|
||||
}).join(',')
|
||||
}])`
|
||||
// by default scoped slots are considered "stable", this allows child
|
||||
// components with only scoped slots to skip forced updates from parent.
|
||||
// but in some cases we have to bail-out of this optimization
|
||||
// for example if the slot contains dynamic names, has v-if or v-for on them...
|
||||
let needsForceUpdate = el.for || Object.keys(slots).some(key => {
|
||||
const slot = slots[key]
|
||||
return (
|
||||
slot.slotTargetDynamic ||
|
||||
slot.if ||
|
||||
slot.for ||
|
||||
containsSlotChild(slot) // is passing down slot from parent which may be dynamic
|
||||
)
|
||||
})
|
||||
|
||||
// #9534: if a component with scoped slots is inside a conditional branch,
|
||||
// it's possible for the same component to be reused but with different
|
||||
// compiled slot content. To avoid that, we generate a unique key based on
|
||||
// the generated code of all the slot contents.
|
||||
let needsKey = !!el.if
|
||||
|
||||
// OR when it is inside another scoped slot or v-for (the reactivity may be
|
||||
// disconnected due to the intermediate scope variable)
|
||||
// #9438, #9506
|
||||
// TODO: this can be further optimized by properly analyzing in-scope bindings
|
||||
// and skip force updating ones that do not actually use scope variables.
|
||||
if (!needsForceUpdate) {
|
||||
let parent = el.parent
|
||||
while (parent) {
|
||||
if (
|
||||
(parent.slotScope && parent.slotScope !== emptySlotScopeToken) ||
|
||||
parent.for
|
||||
) {
|
||||
needsForceUpdate = true
|
||||
break
|
||||
}
|
||||
if (parent.if) {
|
||||
needsKey = true
|
||||
}
|
||||
parent = parent.parent
|
||||
}
|
||||
}
|
||||
|
||||
const generatedSlots = Object.keys(slots)
|
||||
.map(key => genScopedSlot(slots[key], state))
|
||||
.join(',')
|
||||
|
||||
return `scopedSlots:_u([${generatedSlots}]${
|
||||
needsForceUpdate ? `,null,true` : ``
|
||||
}${
|
||||
!needsForceUpdate && needsKey ? `,null,false,${hash(generatedSlots)}` : ``
|
||||
})`
|
||||
}
|
||||
|
||||
function hash(str) {
|
||||
let hash = 5381
|
||||
let i = str.length
|
||||
while(i) {
|
||||
hash = (hash * 33) ^ str.charCodeAt(--i)
|
||||
}
|
||||
return hash >>> 0
|
||||
}
|
||||
|
||||
function containsSlotChild (el: ASTNode): boolean {
|
||||
if (el.type === 1) {
|
||||
if (el.tag === 'slot') {
|
||||
return true
|
||||
}
|
||||
return el.children.some(containsSlotChild)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function genScopedSlot (
|
||||
key: string,
|
||||
el: ASTElement,
|
||||
state: CodegenState
|
||||
): string {
|
||||
if (el.for && !el.forProcessed) {
|
||||
return genForScopedSlot(key, el, state)
|
||||
const isLegacySyntax = el.attrsMap['slot-scope']
|
||||
if (el.if && !el.ifProcessed && !isLegacySyntax) {
|
||||
return genIf(el, state, genScopedSlot, `null`)
|
||||
}
|
||||
const fn = `function(${String(el.slotScope)}){` +
|
||||
if (el.for && !el.forProcessed) {
|
||||
return genFor(el, state, genScopedSlot)
|
||||
}
|
||||
const slotScope = el.slotScope === emptySlotScopeToken
|
||||
? ``
|
||||
: String(el.slotScope)
|
||||
const fn = `function(${slotScope}){` +
|
||||
`return ${el.tag === 'template'
|
||||
? el.if
|
||||
? `${el.if}?${genChildren(el, state) || 'undefined'}:undefined`
|
||||
? el.if && isLegacySyntax
|
||||
? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined`
|
||||
: genChildren(el, state) || 'undefined'
|
||||
: genElement(el, state)
|
||||
}}`
|
||||
return `{key:${key},fn:${fn}}`
|
||||
}
|
||||
|
||||
function genForScopedSlot (
|
||||
key: string,
|
||||
el: any,
|
||||
state: CodegenState
|
||||
): string {
|
||||
const exp = el.for
|
||||
const alias = el.alias
|
||||
const iterator1 = el.iterator1 ? `,${el.iterator1}` : ''
|
||||
const iterator2 = el.iterator2 ? `,${el.iterator2}` : ''
|
||||
el.forProcessed = true // avoid recursion
|
||||
return `_l((${exp}),` +
|
||||
`function(${alias}${iterator1}${iterator2}){` +
|
||||
`return ${genScopedSlot(key, el, state)}` +
|
||||
'})'
|
||||
// reverse proxy v-slot without scope on this.$slots
|
||||
const reverseProxy = slotScope ? `` : `,proxy:true`
|
||||
return `{key:${el.slotTarget || `"default"`},fn:${fn}${reverseProxy}}`
|
||||
}
|
||||
|
||||
export function genChildren (
|
||||
@@ -389,7 +476,10 @@ export function genChildren (
|
||||
el.tag !== 'template' &&
|
||||
el.tag !== 'slot'
|
||||
) {
|
||||
return (altGenElement || genElement)(el, state)
|
||||
const normalizationType = checkSkip
|
||||
? state.maybeComponent(el) ? `,1` : `,0`
|
||||
: ``
|
||||
return `${(altGenElement || genElement)(el, state)}${normalizationType}`
|
||||
}
|
||||
const normalizationType = checkSkip
|
||||
? getNormalizationType(children, state.maybeComponent)
|
||||
@@ -435,7 +525,7 @@ function needsNormalization (el: ASTElement): boolean {
|
||||
function genNode (node: ASTNode, state: CodegenState): string {
|
||||
if (node.type === 1) {
|
||||
return genElement(node, state)
|
||||
} if (node.type === 3 && node.isComment) {
|
||||
} else if (node.type === 3 && node.isComment) {
|
||||
return genComment(node)
|
||||
} else {
|
||||
return genText(node)
|
||||
@@ -457,7 +547,14 @@ function genSlot (el: ASTElement, state: CodegenState): string {
|
||||
const slotName = el.slotName || '"default"'
|
||||
const children = genChildren(el, state)
|
||||
let res = `_t(${slotName}${children ? `,${children}` : ''}`
|
||||
const attrs = el.attrs && `{${el.attrs.map(a => `${camelize(a.name)}:${a.value}`).join(',')}}`
|
||||
const attrs = el.attrs || el.dynamicAttrs
|
||||
? genProps((el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
|
||||
// slot props are camelized
|
||||
name: camelize(attr.name),
|
||||
value: attr.value,
|
||||
dynamic: attr.dynamic
|
||||
})))
|
||||
: null
|
||||
const bind = el.attrsMap['v-bind']
|
||||
if ((attrs || bind) && !children) {
|
||||
res += `,null`
|
||||
@@ -483,18 +580,26 @@ function genComponent (
|
||||
})`
|
||||
}
|
||||
|
||||
function genProps (props: Array<{ name: string, value: any }>): string {
|
||||
let res = ''
|
||||
function genProps (props: Array<ASTAttr>): string {
|
||||
let staticProps = ``
|
||||
let dynamicProps = ``
|
||||
for (let i = 0; i < props.length; i++) {
|
||||
const prop = props[i]
|
||||
/* istanbul ignore if */
|
||||
if (__WEEX__) {
|
||||
res += `"${prop.name}":${generateValue(prop.value)},`
|
||||
const value = __WEEX__
|
||||
? generateValue(prop.value)
|
||||
: transformSpecialNewlines(prop.value)
|
||||
if (prop.dynamic) {
|
||||
dynamicProps += `${prop.name},${value},`
|
||||
} else {
|
||||
res += `"${prop.name}":${transformSpecialNewlines(prop.value)},`
|
||||
staticProps += `"${prop.name}":${value},`
|
||||
}
|
||||
}
|
||||
return res.slice(0, -1)
|
||||
staticProps = `{${staticProps.slice(0, -1)}}`
|
||||
if (dynamicProps) {
|
||||
return `_d(${staticProps},[${dynamicProps.slice(0, -1)}])`
|
||||
} else {
|
||||
return staticProps
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
|
||||
Reference in New Issue
Block a user