-
-
Notifications
You must be signed in to change notification settings - Fork 285
/
Copy pathforwardEvents.js
35 lines (30 loc) · 1.15 KB
/
forwardEvents.js
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
import {bubble, listen} from 'svelte/internal';
export function forwardEventsBuilder(component, additionalEvents = []) {
const events = [
'focus', 'blur',
'fullscreenchange', 'fullscreenerror', 'scroll',
'cut', 'copy', 'paste',
'keydown', 'keypress', 'keyup',
'auxclick', 'click', 'contextmenu', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup', 'pointerlockchange', 'pointerlockerror', 'select', 'wheel',
'drag', 'dragend', 'dragenter', 'dragstart', 'dragleave', 'dragover', 'drop',
'touchcancel', 'touchend', 'touchmove', 'touchstart',
'pointerover', 'pointerenter', 'pointerdown', 'pointermove', 'pointerup', 'pointercancel', 'pointerout', 'pointerleave', 'gotpointercapture', 'lostpointercapture',
...additionalEvents
];
function forward(e) {
bubble(component, e);
}
return node => {
const destructors = [];
for (let i = 0; i < events.length; i++) {
destructors.push(listen(node, events[i], forward));
}
return {
destroy: () => {
for (let i = 0; i < destructors.length; i++) {
destructors[i]();
}
}
}
};
}