Revert "chore: ensure we use event system code paths throughout" (#11644)

* Revert "chore: ensure we use event system code paths throughout (#11640)"

This reverts commit c00d8245ee.

* Update packages/svelte/src/internal/client/dom/elements/attributes.js

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/11646/head
Dominic Gannaway 2 months ago committed by GitHub
parent 3bf68b4765
commit c131e6f494
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,7 +2,7 @@ import { DEV } from 'esm-env';
import { hydrating } from '../hydration.js';
import { get_descriptors, get_prototype_of, map_get, map_set } from '../../utils.js';
import { AttributeAliases, DelegatedEvents, namespace_svg } from '../../../../constants.js';
import { create_event, delegate } from './events.js';
import { delegate } from './events.js';
import { autofocus } from './misc.js';
import { effect, effect_root } from '../../reactivity/effects.js';
import * as w from '../../warnings.js';
@ -149,14 +149,11 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
if (value != null) {
if (!delegated) {
// we use `addEventListener` here because these events are not delegated
if (!prev) {
events.push([
key,
value,
() => (next[key] = create_event(event_name, element, value, opts))
]);
events.push([key, value, () => element.addEventListener(event_name, value, opts)]);
} else {
next[key] = create_event(event_name, element, value, opts);
element.addEventListener(event_name, value, opts);
}
} else {
// @ts-ignore

@ -6,14 +6,18 @@ import { define_property, is_array } from '../../utils.js';
* @param {string} event_name
* @param {Element} dom
* @param {EventListener} handler
* @param {AddEventListenerOptions} options
* @param {boolean} capture
* @param {boolean} [passive]
* @returns {void}
*/
export function create_event(event_name, dom, handler, options) {
export function event(event_name, dom, handler, capture, passive) {
var options = { capture, passive };
/**
* @this {EventTarget}
*/
function target_handler(/** @type {Event} */ event) {
if (!options.capture) {
if (!capture) {
// Only call in the bubble phase, else delegated events would be called before the capturing events
handle_event_propagation(dom, event);
}
@ -24,21 +28,6 @@ export function create_event(event_name, dom, handler, options) {
dom.addEventListener(event_name, target_handler, options);
return target_handler;
}
/**
* @param {string} event_name
* @param {Element} dom
* @param {EventListener} handler
* @param {boolean} capture
* @param {boolean} [passive]
* @returns {void}
*/
export function event(event_name, dom, handler, capture, passive) {
var options = { capture, passive };
var target_handler = create_event(event_name, dom, handler, options);
// @ts-ignore
if (dom === document.body || dom === window || dom === document) {
render_effect(() => {

Loading…
Cancel
Save