@ckeditor/ckeditor5-utils 40.0.0 → 40.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -26
- package/LICENSE.md +3 -3
- package/package.json +1 -1
- package/src/abortabledebounce.d.ts +17 -0
- package/src/abortabledebounce.js +22 -0
- package/src/areconnectedthroughproperties.d.ts +11 -11
- package/src/areconnectedthroughproperties.js +73 -73
- package/src/ckeditorerror.d.ts +123 -123
- package/src/ckeditorerror.js +176 -176
- package/src/collection.d.ts +433 -427
- package/src/collection.js +583 -575
- package/src/comparearrays.d.ts +30 -30
- package/src/comparearrays.js +47 -47
- package/src/config.d.ts +163 -163
- package/src/config.js +163 -162
- package/src/count.d.ts +18 -18
- package/src/count.js +24 -24
- package/src/delay.d.ts +19 -19
- package/src/delay.js +26 -26
- package/src/diff.d.ts +31 -31
- package/src/diff.js +115 -115
- package/src/difftochanges.d.ts +59 -59
- package/src/difftochanges.js +79 -79
- package/src/dom/createelement.d.ts +57 -57
- package/src/dom/createelement.js +40 -40
- package/src/dom/emittermixin.d.ts +142 -142
- package/src/dom/emittermixin.js +239 -239
- package/src/dom/findclosestscrollableancestor.d.ts +11 -11
- package/src/dom/findclosestscrollableancestor.js +31 -31
- package/src/dom/getancestors.d.ts +17 -17
- package/src/dom/getancestors.js +27 -27
- package/src/dom/getborderwidths.d.ts +24 -24
- package/src/dom/getborderwidths.js +24 -24
- package/src/dom/getcommonancestor.d.ts +12 -12
- package/src/dom/getcommonancestor.js +25 -25
- package/src/dom/getdatafromelement.d.ts +14 -14
- package/src/dom/getdatafromelement.js +20 -20
- package/src/dom/getpositionedancestor.d.ts +10 -10
- package/src/dom/getpositionedancestor.js +22 -22
- package/src/dom/global.d.ts +32 -32
- package/src/dom/global.js +35 -35
- package/src/dom/indexof.d.ts +14 -14
- package/src/dom/indexof.js +21 -21
- package/src/dom/insertat.d.ts +15 -15
- package/src/dom/insertat.js +17 -17
- package/src/dom/iscomment.d.ts +11 -11
- package/src/dom/iscomment.js +14 -14
- package/src/dom/isnode.d.ts +11 -11
- package/src/dom/isnode.js +21 -21
- package/src/dom/isrange.d.ts +11 -11
- package/src/dom/isrange.js +13 -13
- package/src/dom/istext.d.ts +11 -11
- package/src/dom/istext.js +13 -13
- package/src/dom/isvalidattributename.d.ts +10 -10
- package/src/dom/isvalidattributename.js +22 -22
- package/src/dom/isvisible.d.ts +18 -18
- package/src/dom/isvisible.js +20 -20
- package/src/dom/iswindow.d.ts +11 -11
- package/src/dom/iswindow.js +22 -22
- package/src/dom/position.d.ts +211 -211
- package/src/dom/position.js +313 -313
- package/src/dom/rect.d.ts +195 -195
- package/src/dom/rect.js +474 -474
- package/src/dom/remove.d.ts +13 -13
- package/src/dom/remove.js +18 -18
- package/src/dom/resizeobserver.d.ts +74 -74
- package/src/dom/resizeobserver.js +126 -126
- package/src/dom/scroll.d.ts +73 -73
- package/src/dom/scroll.js +383 -383
- package/src/dom/setdatainelement.d.ts +14 -14
- package/src/dom/setdatainelement.js +20 -20
- package/src/dom/tounit.d.ts +22 -22
- package/src/dom/tounit.js +16 -16
- package/src/elementreplacer.d.ts +31 -31
- package/src/elementreplacer.js +43 -43
- package/src/emittermixin.d.ts +312 -312
- package/src/emittermixin.js +453 -453
- package/src/env.d.ts +117 -117
- package/src/env.js +122 -122
- package/src/eventinfo.d.ts +58 -58
- package/src/eventinfo.js +26 -26
- package/src/fastdiff.d.ts +112 -112
- package/src/fastdiff.js +248 -248
- package/src/first.d.ts +11 -11
- package/src/first.js +17 -17
- package/src/focustracker.d.ts +75 -75
- package/src/focustracker.js +95 -95
- package/src/index.d.ts +64 -61
- package/src/index.js +63 -60
- package/src/inserttopriorityarray.d.ts +30 -30
- package/src/inserttopriorityarray.js +21 -21
- package/src/isiterable.d.ts +14 -14
- package/src/isiterable.js +16 -16
- package/src/keyboard.d.ts +126 -126
- package/src/keyboard.js +221 -221
- package/src/keystrokehandler.d.ts +87 -87
- package/src/keystrokehandler.js +122 -122
- package/src/language.d.ts +17 -17
- package/src/language.js +19 -19
- package/src/locale.d.ts +120 -120
- package/src/locale.js +76 -76
- package/src/mapsequal.d.ts +15 -15
- package/src/mapsequal.js +27 -27
- package/src/mix.d.ts +85 -85
- package/src/mix.js +50 -50
- package/src/nth.d.ts +16 -16
- package/src/nth.js +24 -24
- package/src/objecttomap.d.ts +23 -23
- package/src/objecttomap.js +27 -27
- package/src/observablemixin.d.ts +560 -560
- package/src/observablemixin.js +580 -580
- package/src/priorities.d.ts +33 -33
- package/src/priorities.js +23 -23
- package/src/retry.d.ts +33 -0
- package/src/retry.js +47 -0
- package/src/splicearray.d.ts +26 -26
- package/src/splicearray.js +40 -40
- package/src/spy.d.ts +21 -21
- package/src/spy.js +22 -22
- package/src/toarray.d.ts +25 -25
- package/src/toarray.js +7 -7
- package/src/tomap.d.ts +19 -19
- package/src/tomap.js +29 -29
- package/src/translation-service.d.ts +168 -168
- package/src/translation-service.js +198 -198
- package/src/uid.d.ts +15 -15
- package/src/uid.js +57 -57
- package/src/unicode.d.ts +54 -54
- package/src/unicode.js +85 -85
- package/src/verifylicense.d.ts +15 -15
- package/src/verifylicense.js +87 -87
- package/src/version.d.ts +10 -10
- package/src/version.js +153 -153
- package/src/wait.d.ts +16 -0
- package/src/wait.js +29 -0
package/src/dom/emittermixin.js
CHANGED
|
@@ -1,239 +1,239 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/dom/emittermixin
|
|
7
|
-
*/
|
|
8
|
-
import EmitterMixin, { _getEmitterListenedTo, _setEmitterId } from '../emittermixin';
|
|
9
|
-
import uid from '../uid';
|
|
10
|
-
import isNode from './isnode';
|
|
11
|
-
import isWindow from './iswindow';
|
|
12
|
-
const defaultEmitterClass = DomEmitterMixin(EmitterMixin());
|
|
13
|
-
export default function DomEmitterMixin(base) {
|
|
14
|
-
if (!base) {
|
|
15
|
-
return defaultEmitterClass;
|
|
16
|
-
}
|
|
17
|
-
class Mixin extends base {
|
|
18
|
-
listenTo(emitter, event, callback, options = {}) {
|
|
19
|
-
// Check if emitter is an instance of DOM Node. If so, use corresponding ProxyEmitter (or create one if not existing).
|
|
20
|
-
if (isNode(emitter) || isWindow(emitter)) {
|
|
21
|
-
const proxyOptions = {
|
|
22
|
-
capture: !!options.useCapture,
|
|
23
|
-
passive: !!options.usePassive
|
|
24
|
-
};
|
|
25
|
-
const proxyEmitter = this._getProxyEmitter(emitter, proxyOptions) || new ProxyEmitter(emitter, proxyOptions);
|
|
26
|
-
this.listenTo(proxyEmitter, event, callback, options);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
30
|
-
super.listenTo(emitter, event, callback, options);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
stopListening(emitter, event, callback) {
|
|
34
|
-
// Check if the emitter is an instance of DOM Node. If so, forward the call to the corresponding ProxyEmitters.
|
|
35
|
-
if (isNode(emitter) || isWindow(emitter)) {
|
|
36
|
-
const proxyEmitters = this._getAllProxyEmitters(emitter);
|
|
37
|
-
for (const proxy of proxyEmitters) {
|
|
38
|
-
this.stopListening(proxy, event, callback);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
43
|
-
super.stopListening(emitter, event, callback);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Retrieves ProxyEmitter instance for given DOM Node residing in this Host and given options.
|
|
48
|
-
*
|
|
49
|
-
* @param node DOM Node of the ProxyEmitter.
|
|
50
|
-
* @param options Additional options.
|
|
51
|
-
* @param options.useCapture Indicates that events of this type will be dispatched to the registered
|
|
52
|
-
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
53
|
-
* @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
|
|
54
|
-
* and prevents blocking browser's main thread by this event handler.
|
|
55
|
-
* @returns ProxyEmitter instance bound to the DOM Node.
|
|
56
|
-
*/
|
|
57
|
-
_getProxyEmitter(node, options) {
|
|
58
|
-
return _getEmitterListenedTo(this, getProxyEmitterId(node, options));
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Retrieves all the ProxyEmitter instances for given DOM Node residing in this Host.
|
|
62
|
-
*
|
|
63
|
-
* @param node DOM Node of the ProxyEmitter.
|
|
64
|
-
*/
|
|
65
|
-
_getAllProxyEmitters(node) {
|
|
66
|
-
return [
|
|
67
|
-
{ capture: false, passive: false },
|
|
68
|
-
{ capture: false, passive: true },
|
|
69
|
-
{ capture: true, passive: false },
|
|
70
|
-
{ capture: true, passive: true }
|
|
71
|
-
].map(options => this._getProxyEmitter(node, options)).filter(proxy => !!proxy);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return Mixin;
|
|
75
|
-
}
|
|
76
|
-
// Backward compatibility with `mix`
|
|
77
|
-
([
|
|
78
|
-
'_getProxyEmitter', '_getAllProxyEmitters',
|
|
79
|
-
'on', 'once', 'off', 'listenTo',
|
|
80
|
-
'stopListening', 'fire', 'delegate', 'stopDelegating',
|
|
81
|
-
'_addEventListener', '_removeEventListener'
|
|
82
|
-
]).forEach(key => {
|
|
83
|
-
DomEmitterMixin[key] = defaultEmitterClass.prototype[key];
|
|
84
|
-
});
|
|
85
|
-
/**
|
|
86
|
-
* Creates a ProxyEmitter instance. Such an instance is a bridge between a DOM Node firing events
|
|
87
|
-
* and any Host listening to them. It is backwards compatible with {@link module:utils/emittermixin~Emitter#on}.
|
|
88
|
-
* There is a separate instance for each combination of modes (useCapture & usePassive). The mode is concatenated with
|
|
89
|
-
* UID stored in HTMLElement to give each instance unique identifier.
|
|
90
|
-
*
|
|
91
|
-
* listenTo( click, ... )
|
|
92
|
-
* +-----------------------------------------+
|
|
93
|
-
* | stopListening( ... ) |
|
|
94
|
-
* +----------------------------+ | addEventListener( click, ... )
|
|
95
|
-
* | Host | | +---------------------------------------------+
|
|
96
|
-
* +----------------------------+ | | removeEventListener( click, ... ) |
|
|
97
|
-
* | _listeningTo: { | +----------v-------------+ |
|
|
98
|
-
* | UID+mode: { | | ProxyEmitter | |
|
|
99
|
-
* | emitter: ProxyEmitter, | +------------------------+ +------------v----------+
|
|
100
|
-
* | callbacks: { | | events: { | | Node (HTMLElement) |
|
|
101
|
-
* | click: [ callbacks ] | | click: [ callbacks ] | +-----------------------+
|
|
102
|
-
* | } | | }, | | data-ck-expando: UID |
|
|
103
|
-
* | } | | _domNode: Node, | +-----------------------+
|
|
104
|
-
* | } | | _domListeners: {}, | |
|
|
105
|
-
* | +------------------------+ | | _emitterId: UID+mode | |
|
|
106
|
-
* | | DomEmitterMixin | | +--------------^---------+ |
|
|
107
|
-
* | +------------------------+ | | | |
|
|
108
|
-
* +--------------^-------------+ | +---------------------------------------------+
|
|
109
|
-
* | | click (DOM Event)
|
|
110
|
-
* +-----------------------------------------+
|
|
111
|
-
* fire( click, DOM Event )
|
|
112
|
-
*/
|
|
113
|
-
class ProxyEmitter extends EmitterMixin() {
|
|
114
|
-
/**
|
|
115
|
-
* @param node DOM Node that fires events.
|
|
116
|
-
* @param options Additional options.
|
|
117
|
-
* @param options.useCapture Indicates that events of this type will be dispatched to the registered
|
|
118
|
-
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
119
|
-
* @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
|
|
120
|
-
* and prevents blocking browser's main thread by this event handler.
|
|
121
|
-
*/
|
|
122
|
-
constructor(node, options) {
|
|
123
|
-
super();
|
|
124
|
-
// Set emitter ID to match DOM Node "expando" property.
|
|
125
|
-
_setEmitterId(this, getProxyEmitterId(node, options));
|
|
126
|
-
// Remember the DOM Node this ProxyEmitter is bound to.
|
|
127
|
-
this._domNode = node;
|
|
128
|
-
// And given options.
|
|
129
|
-
this._options = options;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Registers a callback function to be executed when an event is fired.
|
|
133
|
-
*
|
|
134
|
-
* It attaches a native DOM listener to the DOM Node. When fired,
|
|
135
|
-
* a corresponding Emitter event will also fire with DOM Event object as an argument.
|
|
136
|
-
*
|
|
137
|
-
* **Note**: This is automatically called by the
|
|
138
|
-
* {@link module:utils/emittermixin~Emitter#listenTo `Emitter#listenTo()`}.
|
|
139
|
-
*
|
|
140
|
-
* @param event The name of the event.
|
|
141
|
-
*/
|
|
142
|
-
attach(event) {
|
|
143
|
-
// If the DOM Listener for given event already exist it is pointless
|
|
144
|
-
// to attach another one.
|
|
145
|
-
if (this._domListeners && this._domListeners[event]) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
const domListener = this._createDomListener(event);
|
|
149
|
-
// Attach the native DOM listener to DOM Node.
|
|
150
|
-
this._domNode.addEventListener(event, domListener, this._options);
|
|
151
|
-
if (!this._domListeners) {
|
|
152
|
-
this._domListeners = {};
|
|
153
|
-
}
|
|
154
|
-
// Store the native DOM listener in this ProxyEmitter. It will be helpful
|
|
155
|
-
// when stopping listening to the event.
|
|
156
|
-
this._domListeners[event] = domListener;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Stops executing the callback on the given event.
|
|
160
|
-
*
|
|
161
|
-
* **Note**: This is automatically called by the
|
|
162
|
-
* {@link module:utils/emittermixin~Emitter#stopListening `Emitter#stopListening()`}.
|
|
163
|
-
*
|
|
164
|
-
* @param event The name of the event.
|
|
165
|
-
*/
|
|
166
|
-
detach(event) {
|
|
167
|
-
let events;
|
|
168
|
-
// Remove native DOM listeners which are orphans. If no callbacks
|
|
169
|
-
// are awaiting given event, detach native DOM listener from DOM Node.
|
|
170
|
-
// See: {@link attach}.
|
|
171
|
-
if (this._domListeners[event] && (!(events = this._events[event]) || !events.callbacks.length)) {
|
|
172
|
-
this._domListeners[event].removeListener();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Adds callback to emitter for given event.
|
|
177
|
-
*
|
|
178
|
-
* @internal
|
|
179
|
-
* @param event The name of the event.
|
|
180
|
-
* @param callback The function to be called on event.
|
|
181
|
-
* @param options Additional options.
|
|
182
|
-
*/
|
|
183
|
-
_addEventListener(event, callback, options) {
|
|
184
|
-
this.attach(event);
|
|
185
|
-
EmitterMixin().prototype._addEventListener.call(this, event, callback, options);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Removes callback from emitter for given event.
|
|
189
|
-
*
|
|
190
|
-
* @internal
|
|
191
|
-
* @param event The name of the event.
|
|
192
|
-
* @param callback The function to stop being called.
|
|
193
|
-
*/
|
|
194
|
-
_removeEventListener(event, callback) {
|
|
195
|
-
EmitterMixin().prototype._removeEventListener.call(this, event, callback);
|
|
196
|
-
this.detach(event);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Creates a native DOM listener callback. When the native DOM event
|
|
200
|
-
* is fired it will fire corresponding event on this ProxyEmitter.
|
|
201
|
-
* Note: A native DOM Event is passed as an argument.
|
|
202
|
-
*
|
|
203
|
-
* @param event The name of the event.
|
|
204
|
-
* @returns The DOM listener callback.
|
|
205
|
-
*/
|
|
206
|
-
_createDomListener(event) {
|
|
207
|
-
const domListener = (domEvt) => {
|
|
208
|
-
this.fire(event, domEvt);
|
|
209
|
-
};
|
|
210
|
-
// Supply the DOM listener callback with a function that will help
|
|
211
|
-
// detach it from the DOM Node, when it is no longer necessary.
|
|
212
|
-
// See: {@link detach}.
|
|
213
|
-
domListener.removeListener = () => {
|
|
214
|
-
this._domNode.removeEventListener(event, domListener, this._options);
|
|
215
|
-
delete this._domListeners[event];
|
|
216
|
-
};
|
|
217
|
-
return domListener;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Gets an unique DOM Node identifier. The identifier will be set if not defined.
|
|
222
|
-
*
|
|
223
|
-
* @returns UID for given DOM Node.
|
|
224
|
-
*/
|
|
225
|
-
function getNodeUID(node) {
|
|
226
|
-
return node['data-ck-expando'] || (node['data-ck-expando'] = uid());
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Gets id of the ProxyEmitter for the given node.
|
|
230
|
-
*/
|
|
231
|
-
function getProxyEmitterId(node, options) {
|
|
232
|
-
let id = getNodeUID(node);
|
|
233
|
-
for (const option of Object.keys(options).sort()) {
|
|
234
|
-
if (options[option]) {
|
|
235
|
-
id += '-' + option;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return id;
|
|
239
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module utils/dom/emittermixin
|
|
7
|
+
*/
|
|
8
|
+
import EmitterMixin, { _getEmitterListenedTo, _setEmitterId } from '../emittermixin';
|
|
9
|
+
import uid from '../uid';
|
|
10
|
+
import isNode from './isnode';
|
|
11
|
+
import isWindow from './iswindow';
|
|
12
|
+
const defaultEmitterClass = DomEmitterMixin(EmitterMixin());
|
|
13
|
+
export default function DomEmitterMixin(base) {
|
|
14
|
+
if (!base) {
|
|
15
|
+
return defaultEmitterClass;
|
|
16
|
+
}
|
|
17
|
+
class Mixin extends base {
|
|
18
|
+
listenTo(emitter, event, callback, options = {}) {
|
|
19
|
+
// Check if emitter is an instance of DOM Node. If so, use corresponding ProxyEmitter (or create one if not existing).
|
|
20
|
+
if (isNode(emitter) || isWindow(emitter)) {
|
|
21
|
+
const proxyOptions = {
|
|
22
|
+
capture: !!options.useCapture,
|
|
23
|
+
passive: !!options.usePassive
|
|
24
|
+
};
|
|
25
|
+
const proxyEmitter = this._getProxyEmitter(emitter, proxyOptions) || new ProxyEmitter(emitter, proxyOptions);
|
|
26
|
+
this.listenTo(proxyEmitter, event, callback, options);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
30
|
+
super.listenTo(emitter, event, callback, options);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
stopListening(emitter, event, callback) {
|
|
34
|
+
// Check if the emitter is an instance of DOM Node. If so, forward the call to the corresponding ProxyEmitters.
|
|
35
|
+
if (isNode(emitter) || isWindow(emitter)) {
|
|
36
|
+
const proxyEmitters = this._getAllProxyEmitters(emitter);
|
|
37
|
+
for (const proxy of proxyEmitters) {
|
|
38
|
+
this.stopListening(proxy, event, callback);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
43
|
+
super.stopListening(emitter, event, callback);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves ProxyEmitter instance for given DOM Node residing in this Host and given options.
|
|
48
|
+
*
|
|
49
|
+
* @param node DOM Node of the ProxyEmitter.
|
|
50
|
+
* @param options Additional options.
|
|
51
|
+
* @param options.useCapture Indicates that events of this type will be dispatched to the registered
|
|
52
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
53
|
+
* @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
|
|
54
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
55
|
+
* @returns ProxyEmitter instance bound to the DOM Node.
|
|
56
|
+
*/
|
|
57
|
+
_getProxyEmitter(node, options) {
|
|
58
|
+
return _getEmitterListenedTo(this, getProxyEmitterId(node, options));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves all the ProxyEmitter instances for given DOM Node residing in this Host.
|
|
62
|
+
*
|
|
63
|
+
* @param node DOM Node of the ProxyEmitter.
|
|
64
|
+
*/
|
|
65
|
+
_getAllProxyEmitters(node) {
|
|
66
|
+
return [
|
|
67
|
+
{ capture: false, passive: false },
|
|
68
|
+
{ capture: false, passive: true },
|
|
69
|
+
{ capture: true, passive: false },
|
|
70
|
+
{ capture: true, passive: true }
|
|
71
|
+
].map(options => this._getProxyEmitter(node, options)).filter(proxy => !!proxy);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return Mixin;
|
|
75
|
+
}
|
|
76
|
+
// Backward compatibility with `mix`
|
|
77
|
+
([
|
|
78
|
+
'_getProxyEmitter', '_getAllProxyEmitters',
|
|
79
|
+
'on', 'once', 'off', 'listenTo',
|
|
80
|
+
'stopListening', 'fire', 'delegate', 'stopDelegating',
|
|
81
|
+
'_addEventListener', '_removeEventListener'
|
|
82
|
+
]).forEach(key => {
|
|
83
|
+
DomEmitterMixin[key] = defaultEmitterClass.prototype[key];
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Creates a ProxyEmitter instance. Such an instance is a bridge between a DOM Node firing events
|
|
87
|
+
* and any Host listening to them. It is backwards compatible with {@link module:utils/emittermixin~Emitter#on}.
|
|
88
|
+
* There is a separate instance for each combination of modes (useCapture & usePassive). The mode is concatenated with
|
|
89
|
+
* UID stored in HTMLElement to give each instance unique identifier.
|
|
90
|
+
*
|
|
91
|
+
* listenTo( click, ... )
|
|
92
|
+
* +-----------------------------------------+
|
|
93
|
+
* | stopListening( ... ) |
|
|
94
|
+
* +----------------------------+ | addEventListener( click, ... )
|
|
95
|
+
* | Host | | +---------------------------------------------+
|
|
96
|
+
* +----------------------------+ | | removeEventListener( click, ... ) |
|
|
97
|
+
* | _listeningTo: { | +----------v-------------+ |
|
|
98
|
+
* | UID+mode: { | | ProxyEmitter | |
|
|
99
|
+
* | emitter: ProxyEmitter, | +------------------------+ +------------v----------+
|
|
100
|
+
* | callbacks: { | | events: { | | Node (HTMLElement) |
|
|
101
|
+
* | click: [ callbacks ] | | click: [ callbacks ] | +-----------------------+
|
|
102
|
+
* | } | | }, | | data-ck-expando: UID |
|
|
103
|
+
* | } | | _domNode: Node, | +-----------------------+
|
|
104
|
+
* | } | | _domListeners: {}, | |
|
|
105
|
+
* | +------------------------+ | | _emitterId: UID+mode | |
|
|
106
|
+
* | | DomEmitterMixin | | +--------------^---------+ |
|
|
107
|
+
* | +------------------------+ | | | |
|
|
108
|
+
* +--------------^-------------+ | +---------------------------------------------+
|
|
109
|
+
* | | click (DOM Event)
|
|
110
|
+
* +-----------------------------------------+
|
|
111
|
+
* fire( click, DOM Event )
|
|
112
|
+
*/
|
|
113
|
+
class ProxyEmitter extends EmitterMixin() {
|
|
114
|
+
/**
|
|
115
|
+
* @param node DOM Node that fires events.
|
|
116
|
+
* @param options Additional options.
|
|
117
|
+
* @param options.useCapture Indicates that events of this type will be dispatched to the registered
|
|
118
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
119
|
+
* @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
|
|
120
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
121
|
+
*/
|
|
122
|
+
constructor(node, options) {
|
|
123
|
+
super();
|
|
124
|
+
// Set emitter ID to match DOM Node "expando" property.
|
|
125
|
+
_setEmitterId(this, getProxyEmitterId(node, options));
|
|
126
|
+
// Remember the DOM Node this ProxyEmitter is bound to.
|
|
127
|
+
this._domNode = node;
|
|
128
|
+
// And given options.
|
|
129
|
+
this._options = options;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Registers a callback function to be executed when an event is fired.
|
|
133
|
+
*
|
|
134
|
+
* It attaches a native DOM listener to the DOM Node. When fired,
|
|
135
|
+
* a corresponding Emitter event will also fire with DOM Event object as an argument.
|
|
136
|
+
*
|
|
137
|
+
* **Note**: This is automatically called by the
|
|
138
|
+
* {@link module:utils/emittermixin~Emitter#listenTo `Emitter#listenTo()`}.
|
|
139
|
+
*
|
|
140
|
+
* @param event The name of the event.
|
|
141
|
+
*/
|
|
142
|
+
attach(event) {
|
|
143
|
+
// If the DOM Listener for given event already exist it is pointless
|
|
144
|
+
// to attach another one.
|
|
145
|
+
if (this._domListeners && this._domListeners[event]) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const domListener = this._createDomListener(event);
|
|
149
|
+
// Attach the native DOM listener to DOM Node.
|
|
150
|
+
this._domNode.addEventListener(event, domListener, this._options);
|
|
151
|
+
if (!this._domListeners) {
|
|
152
|
+
this._domListeners = {};
|
|
153
|
+
}
|
|
154
|
+
// Store the native DOM listener in this ProxyEmitter. It will be helpful
|
|
155
|
+
// when stopping listening to the event.
|
|
156
|
+
this._domListeners[event] = domListener;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Stops executing the callback on the given event.
|
|
160
|
+
*
|
|
161
|
+
* **Note**: This is automatically called by the
|
|
162
|
+
* {@link module:utils/emittermixin~Emitter#stopListening `Emitter#stopListening()`}.
|
|
163
|
+
*
|
|
164
|
+
* @param event The name of the event.
|
|
165
|
+
*/
|
|
166
|
+
detach(event) {
|
|
167
|
+
let events;
|
|
168
|
+
// Remove native DOM listeners which are orphans. If no callbacks
|
|
169
|
+
// are awaiting given event, detach native DOM listener from DOM Node.
|
|
170
|
+
// See: {@link attach}.
|
|
171
|
+
if (this._domListeners[event] && (!(events = this._events[event]) || !events.callbacks.length)) {
|
|
172
|
+
this._domListeners[event].removeListener();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Adds callback to emitter for given event.
|
|
177
|
+
*
|
|
178
|
+
* @internal
|
|
179
|
+
* @param event The name of the event.
|
|
180
|
+
* @param callback The function to be called on event.
|
|
181
|
+
* @param options Additional options.
|
|
182
|
+
*/
|
|
183
|
+
_addEventListener(event, callback, options) {
|
|
184
|
+
this.attach(event);
|
|
185
|
+
EmitterMixin().prototype._addEventListener.call(this, event, callback, options);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Removes callback from emitter for given event.
|
|
189
|
+
*
|
|
190
|
+
* @internal
|
|
191
|
+
* @param event The name of the event.
|
|
192
|
+
* @param callback The function to stop being called.
|
|
193
|
+
*/
|
|
194
|
+
_removeEventListener(event, callback) {
|
|
195
|
+
EmitterMixin().prototype._removeEventListener.call(this, event, callback);
|
|
196
|
+
this.detach(event);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Creates a native DOM listener callback. When the native DOM event
|
|
200
|
+
* is fired it will fire corresponding event on this ProxyEmitter.
|
|
201
|
+
* Note: A native DOM Event is passed as an argument.
|
|
202
|
+
*
|
|
203
|
+
* @param event The name of the event.
|
|
204
|
+
* @returns The DOM listener callback.
|
|
205
|
+
*/
|
|
206
|
+
_createDomListener(event) {
|
|
207
|
+
const domListener = (domEvt) => {
|
|
208
|
+
this.fire(event, domEvt);
|
|
209
|
+
};
|
|
210
|
+
// Supply the DOM listener callback with a function that will help
|
|
211
|
+
// detach it from the DOM Node, when it is no longer necessary.
|
|
212
|
+
// See: {@link detach}.
|
|
213
|
+
domListener.removeListener = () => {
|
|
214
|
+
this._domNode.removeEventListener(event, domListener, this._options);
|
|
215
|
+
delete this._domListeners[event];
|
|
216
|
+
};
|
|
217
|
+
return domListener;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Gets an unique DOM Node identifier. The identifier will be set if not defined.
|
|
222
|
+
*
|
|
223
|
+
* @returns UID for given DOM Node.
|
|
224
|
+
*/
|
|
225
|
+
function getNodeUID(node) {
|
|
226
|
+
return node['data-ck-expando'] || (node['data-ck-expando'] = uid());
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Gets id of the ProxyEmitter for the given node.
|
|
230
|
+
*/
|
|
231
|
+
function getProxyEmitterId(node, options) {
|
|
232
|
+
let id = getNodeUID(node);
|
|
233
|
+
for (const option of Object.keys(options).sort()) {
|
|
234
|
+
if (options[option]) {
|
|
235
|
+
id += '-' + option;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return id;
|
|
239
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Returns the closest scrollable ancestor of a DOM element.
|
|
7
|
-
*
|
|
8
|
-
* @param domElement DOM element.
|
|
9
|
-
* @returns First ancestor of `domElement` that is scrollable or null if such ancestor doesn't exist.
|
|
10
|
-
*/
|
|
11
|
-
export default function findClosestScrollableAncestor(domElement: HTMLElement): HTMLElement | null;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Returns the closest scrollable ancestor of a DOM element.
|
|
7
|
+
*
|
|
8
|
+
* @param domElement DOM element.
|
|
9
|
+
* @returns First ancestor of `domElement` that is scrollable or null if such ancestor doesn't exist.
|
|
10
|
+
*/
|
|
11
|
+
export default function findClosestScrollableAncestor(domElement: HTMLElement): HTMLElement | null;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/dom/findclosestscrollableancestor
|
|
7
|
-
*/
|
|
8
|
-
import global from './global';
|
|
9
|
-
/**
|
|
10
|
-
* Returns the closest scrollable ancestor of a DOM element.
|
|
11
|
-
*
|
|
12
|
-
* @param domElement DOM element.
|
|
13
|
-
* @returns First ancestor of `domElement` that is scrollable or null if such ancestor doesn't exist.
|
|
14
|
-
*/
|
|
15
|
-
export default function findClosestScrollableAncestor(domElement) {
|
|
16
|
-
let element = domElement.parentElement;
|
|
17
|
-
if (!element) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
while (element.tagName != 'BODY') {
|
|
21
|
-
const overflow = element.style.overflowY || global.window.getComputedStyle(element).overflowY;
|
|
22
|
-
if (overflow === 'auto' || overflow === 'scroll') {
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
element = element.parentElement;
|
|
26
|
-
if (!element) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return element;
|
|
31
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module utils/dom/findclosestscrollableancestor
|
|
7
|
+
*/
|
|
8
|
+
import global from './global';
|
|
9
|
+
/**
|
|
10
|
+
* Returns the closest scrollable ancestor of a DOM element.
|
|
11
|
+
*
|
|
12
|
+
* @param domElement DOM element.
|
|
13
|
+
* @returns First ancestor of `domElement` that is scrollable or null if such ancestor doesn't exist.
|
|
14
|
+
*/
|
|
15
|
+
export default function findClosestScrollableAncestor(domElement) {
|
|
16
|
+
let element = domElement.parentElement;
|
|
17
|
+
if (!element) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
while (element.tagName != 'BODY') {
|
|
21
|
+
const overflow = element.style.overflowY || global.window.getComputedStyle(element).overflowY;
|
|
22
|
+
if (overflow === 'auto' || overflow === 'scroll') {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
element = element.parentElement;
|
|
26
|
+
if (!element) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return element;
|
|
31
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/dom/getancestors
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Returns all ancestors of given DOM node, starting from the top-most (root). Includes the given node itself. If the
|
|
10
|
-
* node is a part of `DocumentFragment` that `DocumentFragment` will be returned. In contrary, if the node is
|
|
11
|
-
* appended to a `Document`, that `Document` will not be returned (algorithms operating on DOM tree care for `Document#documentElement`
|
|
12
|
-
* at most, which will be returned).
|
|
13
|
-
*
|
|
14
|
-
* @param node DOM node.
|
|
15
|
-
* @returns Array of given `node` parents.
|
|
16
|
-
*/
|
|
17
|
-
export default function getAncestors(node: Node): Array<Node>;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module utils/dom/getancestors
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Returns all ancestors of given DOM node, starting from the top-most (root). Includes the given node itself. If the
|
|
10
|
+
* node is a part of `DocumentFragment` that `DocumentFragment` will be returned. In contrary, if the node is
|
|
11
|
+
* appended to a `Document`, that `Document` will not be returned (algorithms operating on DOM tree care for `Document#documentElement`
|
|
12
|
+
* at most, which will be returned).
|
|
13
|
+
*
|
|
14
|
+
* @param node DOM node.
|
|
15
|
+
* @returns Array of given `node` parents.
|
|
16
|
+
*/
|
|
17
|
+
export default function getAncestors(node: Node): Array<Node>;
|