mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] qweb, blockdom, components: t-on with modifiers
supported modifiers: capture, prevent, stop, self.
This commit is contained in:
committed by
Aaron Bohy
parent
2ae0149adb
commit
4cceb239dd
@@ -1,13 +1,26 @@
|
||||
import { filterOutModifiersFromData } from "../blockdom/config";
|
||||
|
||||
export function mainEventHandler(data: any, ev: Event) {
|
||||
if (typeof data === "function") {
|
||||
data(ev);
|
||||
} else {
|
||||
data = filterOutModifiersFromData(data).data;
|
||||
const ctx = data[0];
|
||||
export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarget|null) => {
|
||||
const { data: _data, modifiers } = filterOutModifiersFromData(data);
|
||||
data = _data;
|
||||
let stopped = false;
|
||||
if (modifiers.length) {
|
||||
let selfMode = false;
|
||||
const isSelf = ev.target === currentTarget;
|
||||
for (const mod of modifiers) {
|
||||
switch (mod) {
|
||||
case "self": selfMode = true; if (isSelf) { continue; } else { return stopped; };
|
||||
case "prevent": if ((selfMode && isSelf) || (!selfMode)) ev.preventDefault(); continue;
|
||||
case "stop": if ((selfMode && isSelf) || (!selfMode)) ev.stopPropagation() ; stopped = true; continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof data[0] === "function") {
|
||||
data[0](ev);
|
||||
} else if (data[0].__owl__) {
|
||||
const method = data[1];
|
||||
const args = data[2] || [];
|
||||
ctx.__owl__.component[method](...args, ev);
|
||||
data[0].__owl__.component[method](...args, ev);
|
||||
}
|
||||
return stopped;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user