-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
domeventdata.ts
78 lines (66 loc) · 1.87 KB
/
domeventdata.ts
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module engine/view/observer/domeventdata
*/
import { extend } from 'lodash-es';
import type Document from '../document.js';
import type Element from '../element.js';
import type View from '../view.js';
/**
* Information about a DOM event in context of the {@link module:engine/view/document~Document}.
* It wraps the native event, which usually should not be used as the wrapper contains
* additional data (like key code for keyboard events).
*
* @typeParam TEvent The type of DOM Event that this class represents.
*/
export default class DomEventData<TEvent extends Event = Event> {
/**
* Instance of the view controller.
*/
public readonly view: View;
/**
* The instance of the document.
*/
public readonly document: Document;
/**
* The DOM event.
*/
public readonly domEvent: TEvent;
/**
* The DOM target.
*/
public readonly domTarget: HTMLElement;
/**
* @param view The instance of the view controller.
* @param domEvent The DOM event.
* @param additionalData Additional properties that the instance should contain.
*/
constructor( view: View, domEvent: TEvent, additionalData?: object ) {
this.view = view;
this.document = view.document;
this.domEvent = domEvent;
this.domTarget = domEvent.target as any;
extend( this, additionalData );
}
/**
* The tree view element representing the target.
*/
public get target(): Element {
return this.view.domConverter.mapDomToView( this.domTarget ) as Element;
}
/**
* Prevents the native's event default action.
*/
public preventDefault(): void {
this.domEvent.preventDefault();
}
/**
* Stops native event propagation.
*/
public stopPropagation(): void {
this.domEvent.stopPropagation();
}
}