Match-id-c95952cfdb908b64baf7fced8799a28544af9cc0

This commit is contained in:
* 2022-02-09 11:10:01 +08:00 committed by *
parent e578f6a77d
commit d1a459760a
10 changed files with 17 additions and 79 deletions

View File

@ -10,7 +10,6 @@ import {
} from '../dom/DOMInternalKeys';
import {CustomBaseEvent} from './customEvents/CustomBaseEvent';
import {runDiscreteUpdates} from '../renderer/TreeBuilder';
import {getEventTarget} from './utils';
import {isMounted} from '../renderer/vnode/VNodeUtils';
import {SuspenseComponent} from '../renderer/vnode/VNodeTags';
import {handleEventMain} from './HorizonEventMain';
@ -33,7 +32,7 @@ function triggerDelegatedEvent(
// 执行之前的调度事件
runDiscreteUpdates();
const nativeEventTarget = getEventTarget(nativeEvent);
const nativeEventTarget = nativeEvent.target || nativeEvent.srcElement;
let targetVNode = getNearestVNode(nativeEventTarget);
if (targetVNode !== null) {

View File

@ -14,9 +14,8 @@ import { getListeners as getSelectionListeners } from './simulatedEvtHandler/Sel
import {
getCustomEventNameWithOn,
uniqueCharCode,
getEventTarget
} from './utils';
import { createCommonCustomEvent } from './customEvents/EventFactory';
import { createCustomEvent } from './customEvents/EventFactory';
import { getListenersFromTree } from './ListenerGetter';
import { shouldUpdateValue, updateControlledValue } from './ControlledValueUpdater';
import { asyncUpdates, runDiscreteUpdates } from '../renderer/Renderer';
@ -54,7 +53,7 @@ function getCommonListeners(
nativeEvtName = 'blur';
}
const horizonEvent = createCommonCustomEvent(horizonEvtName, nativeEvtName, nativeEvent, null, target);
const horizonEvent = createCustomEvent(horizonEvtName, nativeEvtName, nativeEvent, null, target);
return getListenersFromTree(
vNode,
horizonEvtName,
@ -142,7 +141,7 @@ function triggerHorizonEvents(
nativeEvent: AnyNativeEvent,
vNode: VNode | null,
): void {
const nativeEventTarget = getEventTarget(nativeEvent);
const nativeEventTarget = nativeEvent.target || nativeEvent.srcElement;
// 获取委托事件队列
const listenerList = getProcessListenersFacade(nativeEvtName, vNode, nativeEvent, nativeEventTarget, isCapture);

View File

@ -64,6 +64,7 @@ export class CustomBaseEvent {
isDefaultPrevented: () => boolean;
isPropagationStopped: () => boolean;
currentTarget: EventTarget;
relatedTarget: EventTarget;
constructor(
customEvtName: string | null,
@ -92,6 +93,7 @@ export class CustomBaseEvent {
this.stopPropagation = this.stopPropagation.bind(this);
this.isDefaultPrevented = () => defaultPrevented;
this.isPropagationStopped = () => false;
this.relatedTarget = nativeEvt.relatedTarget;
}
// 兼容性方法

View File

@ -1,26 +0,0 @@
import type {VNode} from '../../renderer/Types';
import {CustomBaseEvent} from './CustomBaseEvent';
export class CustomMouseEvent extends CustomBaseEvent {
relatedTarget: EventTarget;
constructor(
customEvtName: string | null,
nativeEvtName: string,
nativeEvt: { [propName: string]: any },
vNode: VNode,
target: null | EventTarget
) {
super(customEvtName, nativeEvtName, nativeEvt, vNode, target);
let relatedTarget = nativeEvt.relatedTarget;
if (relatedTarget === undefined) {
if (nativeEvt.fromElement === nativeEvt.srcElement) {
relatedTarget = nativeEvt.toElement;
} else {
relatedTarget = nativeEvt.fromElement;
}
}
this.relatedTarget = relatedTarget;
}
}

View File

@ -1,30 +1,15 @@
import {CustomKeyboardEvent} from './CustomKeyboardEvent';
import {CustomMouseEvent} from './CustomMouseEvent';
import {CustomBaseEvent} from './CustomBaseEvent';
const CommonEventToCustom = {
const keyboardEvents = {
keypress: CustomKeyboardEvent,
keydown: CustomKeyboardEvent,
keyup: CustomKeyboardEvent,
click: CustomMouseEvent,
dblclick: CustomMouseEvent,
mousedown: CustomMouseEvent,
mousemove: CustomMouseEvent,
mouseup: CustomMouseEvent,
mouseout: CustomMouseEvent,
mouseover: CustomMouseEvent,
contextmenu: CustomMouseEvent,
pointercancel: CustomMouseEvent,
pointerdown: CustomMouseEvent,
pointermove: CustomMouseEvent,
pointerout: CustomMouseEvent,
pointerover: CustomMouseEvent,
pointerup: CustomMouseEvent,
}
// 创建普通自定义事件对象实例,和原生事件对应
export function createCommonCustomEvent(customEventName, nativeEvtName, nativeEvent, vNode, currentTarget) {
const EventConstructor = CommonEventToCustom[nativeEvtName] || CustomBaseEvent;
export function createCustomEvent(customEventName, nativeEvtName, nativeEvent, vNode, currentTarget) {
const EventConstructor = keyboardEvents[nativeEvtName] || CustomBaseEvent;
return new EventConstructor(
customEventName,
nativeEvtName,
@ -33,14 +18,3 @@ export function createCommonCustomEvent(customEventName, nativeEvtName, nativeEv
currentTarget,
);
}
// 创建模拟事件实例对象,需要handler特殊处理
export function createHandlerCustomEvent(customEventName, nativeEvtName, nativeEvent, vNode, currentTarget) {
return new CustomMouseEvent(
customEventName,
nativeEvtName,
nativeEvent,
vNode,
currentTarget,
);
}

View File

@ -1,7 +1,7 @@
import type {VNode} from '../../renderer/Types';
import type {AnyNativeEvent} from '../Types';
import {getListenersFromTree} from '../ListenerGetter';
import {createHandlerCustomEvent} from '../customEvents/EventFactory';
import {createCustomEvent} from '../customEvents/EventFactory';
import {CHAR_CODE_SPACE, EVENT_TYPE_ALL} from '../const';
import {CustomBaseEvent} from '../customEvents/CustomBaseEvent';
import {ListenerUnitList} from '../Types';
@ -36,7 +36,7 @@ export function getListeners(
return [];
}
const event: CustomBaseEvent = createHandlerCustomEvent(
const event: CustomBaseEvent = createCustomEvent(
'onBeforeInput',
'beforeinput',
nativeEvent,

View File

@ -1,4 +1,4 @@
import {createHandlerCustomEvent} from '../customEvents/EventFactory';
import {createCustomEvent} from '../customEvents/EventFactory';
import {getDom} from '../../dom/DOMInternalKeys';
import {isInputValueChanged} from '../../dom/valueHandler/ValueChangeHandler';
import {addValueUpdateList} from '../ControlledValueUpdater';
@ -48,7 +48,7 @@ export function getListeners(
// 判断是否需要触发change事件
if (shouldTriggerChangeEvent(targetDom, nativeEvtName)) {
addValueUpdateList(target);
const event = createHandlerCustomEvent(
const event = createCustomEvent(
'onChange',
'change',
nativeEvt,

View File

@ -1,7 +1,7 @@
import type {VNode} from '../../renderer/Types';
import type {AnyNativeEvent} from '../Types';
import {getListenersFromTree} from '../ListenerGetter';
import {createHandlerCustomEvent} from '../customEvents/EventFactory';
import {createCustomEvent} from '../customEvents/EventFactory';
import {EVENT_TYPE_ALL} from '../const';
import {ListenerUnitList} from '../Types';
@ -20,7 +20,7 @@ export function getListeners(
): ListenerUnitList {
const evtType = compositionEventObj[evtName];
const event = createHandlerCustomEvent(
const event = createCustomEvent(
evtType,
evtName,
nativeEvt,

View File

@ -1,4 +1,4 @@
import {createHandlerCustomEvent} from '../customEvents/EventFactory';
import {createCustomEvent} from '../customEvents/EventFactory';
import {shallowCompare} from '../../renderer/utils/compare';
import {getFocusedDom} from '../../dom/utils/Common';
import {getDom} from '../../dom/DOMInternalKeys';
@ -54,7 +54,7 @@ function getSelectEvent(nativeEvent, target) {
if (!shallowCompare(lastSelection, currentSelection)) {
lastSelection = currentSelection;
const event = createHandlerCustomEvent(
const event = createCustomEvent(
horizonEventName,
'select',
nativeEvent,

View File

@ -1,4 +1,3 @@
import {isText} from '../dom/utils/Common';
import { CHAR_CODE_ENTER, CHAR_CODE_SPACE } from './const';
export function uniqueCharCode(nativeEvent): number {
@ -22,15 +21,6 @@ export function uniqueCharCode(nativeEvent): number {
return 0;
}
// 获取事件的target对象
export function getEventTarget(nativeEvent) {
const target = nativeEvent.target || nativeEvent.srcElement || window;
if (isText(target)) {
return target.parentNode;
}
return target;
}
// 支持的输入框类型
const supportedInputTypes = ['color', 'date', 'datetime', 'datetime-local', 'email', 'month',
'number', 'password', 'range', 'search', 'tel', 'text', 'time', 'url', 'week'];