|
@@ -19,7 +19,11 @@ const keyCodes = {
|
|
|
const modifierCode = {
|
|
const modifierCode = {
|
|
|
stop: '$event.stopPropagation();',
|
|
stop: '$event.stopPropagation();',
|
|
|
prevent: '$event.preventDefault();',
|
|
prevent: '$event.preventDefault();',
|
|
|
- self: 'if($event.target !== $event.currentTarget)return;',
|
|
|
|
|
|
|
+ self: 'if($event.target !== $event.currentTarget)return;'
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const isMouseEventRE = /^mouse|^pointer|^(click|dblclick|contextmenu|wheel)$/
|
|
|
|
|
+const mouseEventModifierCode = {
|
|
|
ctrl: 'if(!$event.ctrlKey)return;',
|
|
ctrl: 'if(!$event.ctrlKey)return;',
|
|
|
shift: 'if(!$event.shiftKey)return;',
|
|
shift: 'if(!$event.shiftKey)return;',
|
|
|
alt: 'if(!$event.altKey)return;',
|
|
alt: 'if(!$event.altKey)return;',
|
|
@@ -29,18 +33,19 @@ const modifierCode = {
|
|
|
export function genHandlers (events: ASTElementHandlers, native?: boolean): string {
|
|
export function genHandlers (events: ASTElementHandlers, native?: boolean): string {
|
|
|
let res = native ? 'nativeOn:{' : 'on:{'
|
|
let res = native ? 'nativeOn:{' : 'on:{'
|
|
|
for (const name in events) {
|
|
for (const name in events) {
|
|
|
- res += `"${name}":${genHandler(events[name])},`
|
|
|
|
|
|
|
+ res += `"${name}":${genHandler(name, events[name])},`
|
|
|
}
|
|
}
|
|
|
return res.slice(0, -1) + '}'
|
|
return res.slice(0, -1) + '}'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function genHandler (
|
|
function genHandler (
|
|
|
|
|
+ name: string,
|
|
|
handler: ASTElementHandler | Array<ASTElementHandler>
|
|
handler: ASTElementHandler | Array<ASTElementHandler>
|
|
|
): string {
|
|
): string {
|
|
|
if (!handler) {
|
|
if (!handler) {
|
|
|
return 'function(){}'
|
|
return 'function(){}'
|
|
|
} else if (Array.isArray(handler)) {
|
|
} else if (Array.isArray(handler)) {
|
|
|
- return `[${handler.map(genHandler).join(',')}]`
|
|
|
|
|
|
|
+ return `[${handler.map(handler => genHandler(name, handler)).join(',')}]`
|
|
|
} else if (!handler.modifiers) {
|
|
} else if (!handler.modifiers) {
|
|
|
return fnExpRE.test(handler.value) || simplePathRE.test(handler.value)
|
|
return fnExpRE.test(handler.value) || simplePathRE.test(handler.value)
|
|
|
? handler.value
|
|
? handler.value
|
|
@@ -48,9 +53,12 @@ function genHandler (
|
|
|
} else {
|
|
} else {
|
|
|
let code = ''
|
|
let code = ''
|
|
|
const keys = []
|
|
const keys = []
|
|
|
|
|
+ const isMouseEvnet = isMouseEventRE.test(name)
|
|
|
for (const key in handler.modifiers) {
|
|
for (const key in handler.modifiers) {
|
|
|
if (modifierCode[key]) {
|
|
if (modifierCode[key]) {
|
|
|
code += modifierCode[key]
|
|
code += modifierCode[key]
|
|
|
|
|
+ } else if (isMouseEvnet && mouseEventModifierCode[key]) {
|
|
|
|
|
+ code += mouseEventModifierCode[key]
|
|
|
} else {
|
|
} else {
|
|
|
keys.push(key)
|
|
keys.push(key)
|
|
|
}
|
|
}
|