@ -1401,6 +1401,7 @@ export function delegate(events) {
* @ returns { void }
* @ returns { void }
* /
* /
function handle _event _propagation ( handler _element , event ) {
function handle _event _propagation ( handler _element , event ) {
const owner _document = handler _element . ownerDocument ;
const event _name = event . type ;
const event _name = event . type ;
const path = event . composedPath ? . ( ) || [ ] ;
const path = event . composedPath ? . ( ) || [ ] ;
let current _target = /** @type {null | Element} */ ( path [ 0 ] || event . target ) ;
let current _target = /** @type {null | Element} */ ( path [ 0 ] || event . target ) ;
@ -1420,12 +1421,15 @@ function handle_event_propagation(handler_element, event) {
const handled _at = event . _ _root ;
const handled _at = event . _ _root ;
if ( handled _at ) {
if ( handled _at ) {
const at _idx = path . indexOf ( handled _at ) ;
const at _idx = path . indexOf ( handled _at ) ;
if ( at _idx !== - 1 && handler _element === document ) {
if (
// This is the fallback document listener but the event was already handled
at _idx !== - 1 &&
// -> ignore, but set handle_at to document so that we're resetting the event
( handler _element === document || handler _element === /** @type {any} */ ( window ) )
) {
// This is the fallback document listener or a window listener, but the event was already handled
// -> ignore, but set handle_at to document/window so that we're resetting the event
// chain in case someone manually dispatches the same event object again.
// chain in case someone manually dispatches the same event object again.
// @ts-expect-error
// @ts-expect-error
event . _ _root = document ;
event . _ _root = handler _ele ment;
return ;
return ;
}
}
// We're deliberately not skipping if the index is higher, because
// We're deliberately not skipping if the index is higher, because
@ -1451,8 +1455,7 @@ function handle_event_propagation(handler_element, event) {
define _property ( event , 'currentTarget' , {
define _property ( event , 'currentTarget' , {
configurable : true ,
configurable : true ,
get ( ) {
get ( ) {
// TODO: ensure correct document?
return current _target || owner _document ;
return current _target || document ;
}
}
} ) ;
} ) ;