@ckeditor/ckeditor5-utils 34.1.0 → 35.0.1
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 +324 -0
- package/LICENSE.md +1 -1
- package/package.json +19 -8
- package/src/areconnectedthroughproperties.js +54 -71
- package/src/ckeditorerror.js +92 -114
- package/src/collection.js +594 -760
- package/src/comparearrays.js +22 -28
- package/src/config.js +193 -223
- package/src/count.js +8 -12
- package/src/diff.js +85 -110
- package/src/difftochanges.js +47 -57
- package/src/dom/createelement.js +17 -25
- package/src/dom/emittermixin.js +217 -257
- package/src/dom/getancestors.js +9 -13
- package/src/dom/getborderwidths.js +10 -13
- package/src/dom/getcommonancestor.js +9 -15
- package/src/dom/getdatafromelement.js +5 -9
- package/src/dom/getpositionedancestor.js +9 -14
- package/src/dom/global.js +0 -3
- package/src/dom/indexof.js +7 -11
- package/src/dom/insertat.js +2 -4
- package/src/dom/iscomment.js +2 -5
- package/src/dom/isnode.js +10 -12
- package/src/dom/isrange.js +2 -4
- package/src/dom/istext.js +2 -4
- package/src/dom/isvisible.js +2 -4
- package/src/dom/iswindow.js +11 -16
- package/src/dom/position.js +220 -410
- package/src/dom/rect.js +335 -414
- package/src/dom/remove.js +5 -8
- package/src/dom/resizeobserver.js +109 -342
- package/src/dom/scroll.js +151 -183
- package/src/dom/setdatainelement.js +5 -9
- package/src/dom/tounit.js +10 -12
- package/src/elementreplacer.js +30 -44
- package/src/emittermixin.js +383 -631
- package/src/env.js +93 -115
- package/src/eventinfo.js +12 -65
- package/src/fastdiff.js +96 -128
- package/src/first.js +8 -12
- package/src/focustracker.js +77 -131
- package/src/index.js +0 -9
- package/src/inserttopriorityarray.js +9 -30
- package/src/isiterable.js +2 -4
- package/src/keyboard.js +117 -196
- package/src/keystrokehandler.js +72 -88
- package/src/language.js +9 -15
- package/src/locale.js +61 -158
- package/src/mapsequal.js +12 -17
- package/src/mix.js +13 -16
- package/src/nth.js +8 -11
- package/src/objecttomap.js +7 -11
- package/src/observablemixin.js +465 -768
- package/src/priorities.js +20 -32
- package/src/spy.js +3 -6
- package/src/toarray.js +2 -13
- package/src/tomap.js +8 -10
- package/src/translation-service.js +51 -87
- package/src/uid.js +34 -38
- package/src/unicode.js +28 -43
- package/src/version.js +134 -143
package/src/dom/emittermixin.js
CHANGED
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/dom/emittermixin
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { default as EmitterMixin, _getEmitterListenedTo, _setEmitterId } from '../emittermixin';
|
|
11
9
|
import uid from '../uid';
|
|
12
10
|
import isNode from './isnode';
|
|
13
11
|
import isWindow from './iswindow';
|
|
14
12
|
import { extend } from 'lodash-es';
|
|
15
|
-
|
|
13
|
+
import mix from '../mix';
|
|
16
14
|
/**
|
|
17
15
|
* Mixin that injects the DOM events API into its host. It provides the API
|
|
18
16
|
* compatible with {@link module:utils/emittermixin~EmitterMixin}.
|
|
@@ -35,104 +33,99 @@ import { extend } from 'lodash-es';
|
|
|
35
33
|
* @mixes module:utils/emittermixin~EmitterMixin
|
|
36
34
|
* @implements module:utils/dom/emittermixin~Emitter
|
|
37
35
|
*/
|
|
38
|
-
const DomEmitterMixin = extend(
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
].map( options => this._getProxyEmitter( node, options ) ).filter( proxy => !!proxy );
|
|
131
|
-
}
|
|
132
|
-
} );
|
|
133
|
-
|
|
36
|
+
const DomEmitterMixin = extend({}, EmitterMixin, {
|
|
37
|
+
/**
|
|
38
|
+
* Registers a callback function to be executed when an event is fired in a specific Emitter or DOM Node.
|
|
39
|
+
* It is backwards compatible with {@link module:utils/emittermixin~EmitterMixin#listenTo}.
|
|
40
|
+
*
|
|
41
|
+
* @param {module:utils/emittermixin~Emitter|Node|Window} emitter The object that fires the event.
|
|
42
|
+
* @param {String} event The name of the event.
|
|
43
|
+
* @param {Function} callback The function to be called on event.
|
|
44
|
+
* @param {Object} [options={}] Additional options.
|
|
45
|
+
* @param {module:utils/priorities~PriorityString|Number} [options.priority='normal'] The priority of this event callback. The higher
|
|
46
|
+
* the priority value the sooner the callback will be fired. Events having the same priority are called in the
|
|
47
|
+
* order they were added.
|
|
48
|
+
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
|
|
49
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
50
|
+
* @param {Boolean} [options.usePassive=false] Indicates that the function specified by listener will never call preventDefault()
|
|
51
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
52
|
+
*/
|
|
53
|
+
listenTo(emitter, event, callback, options = {}) {
|
|
54
|
+
// Check if emitter is an instance of DOM Node. If so, use corresponding ProxyEmitter (or create one if not existing).
|
|
55
|
+
if (isNode(emitter) || isWindow(emitter)) {
|
|
56
|
+
const proxyOptions = {
|
|
57
|
+
capture: !!options.useCapture,
|
|
58
|
+
passive: !!options.usePassive
|
|
59
|
+
};
|
|
60
|
+
const proxyEmitter = this._getProxyEmitter(emitter, proxyOptions) || new ProxyEmitter(emitter, proxyOptions);
|
|
61
|
+
this.listenTo(proxyEmitter, event, callback, options);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
65
|
+
EmitterMixin.listenTo.call(this, emitter, event, callback, options);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Stops listening for events. It can be used at different levels:
|
|
70
|
+
* It is backwards compatible with {@link module:utils/emittermixin~EmitterMixin#listenTo}.
|
|
71
|
+
*
|
|
72
|
+
* * To stop listening to a specific callback.
|
|
73
|
+
* * To stop listening to a specific event.
|
|
74
|
+
* * To stop listening to all events fired by a specific object.
|
|
75
|
+
* * To stop listening to all events fired by all object.
|
|
76
|
+
*
|
|
77
|
+
* @param {module:utils/emittermixin~Emitter|Node|Window} [emitter] The object to stop listening to.
|
|
78
|
+
* If omitted, stops it for all objects.
|
|
79
|
+
* @param {String} [event] (Requires the `emitter`) The name of the event to stop listening to. If omitted, stops it
|
|
80
|
+
* for all events from `emitter`.
|
|
81
|
+
* @param {Function} [callback] (Requires the `event`) The function to be removed from the call list for the given
|
|
82
|
+
* `event`.
|
|
83
|
+
*/
|
|
84
|
+
stopListening(emitter, event, callback) {
|
|
85
|
+
// Check if the emitter is an instance of DOM Node. If so, forward the call to the corresponding ProxyEmitters.
|
|
86
|
+
if (isNode(emitter) || isWindow(emitter)) {
|
|
87
|
+
const proxyEmitters = this._getAllProxyEmitters(emitter);
|
|
88
|
+
for (const proxy of proxyEmitters) {
|
|
89
|
+
this.stopListening(proxy, event, callback);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
94
|
+
EmitterMixin.stopListening.call(this, emitter, event, callback);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves ProxyEmitter instance for given DOM Node residing in this Host and given options.
|
|
99
|
+
*
|
|
100
|
+
* @private
|
|
101
|
+
* @param {Node|Window} node DOM Node of the ProxyEmitter.
|
|
102
|
+
* @param {Object} [options] Additional options.
|
|
103
|
+
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
|
|
104
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
105
|
+
* @param {Boolean} [options.usePassive=false] Indicates that the function specified by listener will never call preventDefault()
|
|
106
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
107
|
+
* @returns {module:utils/dom/emittermixin~ProxyEmitter|null} ProxyEmitter instance bound to the DOM Node.
|
|
108
|
+
*/
|
|
109
|
+
_getProxyEmitter(node, options) {
|
|
110
|
+
return _getEmitterListenedTo(this, getProxyEmitterId(node, options));
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves all the ProxyEmitter instances for given DOM Node residing in this Host.
|
|
114
|
+
*
|
|
115
|
+
* @private
|
|
116
|
+
* @param {Node|Window} node DOM Node of the ProxyEmitter.
|
|
117
|
+
* @returns {Array.<module:utils/dom/emittermixin~ProxyEmitter>}
|
|
118
|
+
*/
|
|
119
|
+
_getAllProxyEmitters(node) {
|
|
120
|
+
return [
|
|
121
|
+
{ capture: false, passive: false },
|
|
122
|
+
{ capture: false, passive: true },
|
|
123
|
+
{ capture: true, passive: false },
|
|
124
|
+
{ capture: true, passive: true }
|
|
125
|
+
].map(options => this._getProxyEmitter(node, options)).filter(proxy => !!proxy);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
134
128
|
export default DomEmitterMixin;
|
|
135
|
-
|
|
136
129
|
/**
|
|
137
130
|
* Creates a ProxyEmitter instance. Such an instance is a bridge between a DOM Node firing events
|
|
138
131
|
* and any Host listening to them. It is backwards compatible with {@link module:utils/emittermixin~EmitterMixin#on}.
|
|
@@ -166,154 +159,129 @@ export default DomEmitterMixin;
|
|
|
166
159
|
* @private
|
|
167
160
|
*/
|
|
168
161
|
class ProxyEmitter {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
162
|
+
/**
|
|
163
|
+
* @param {Node|Window} node DOM Node that fires events.
|
|
164
|
+
* @param {Object} [options] Additional options.
|
|
165
|
+
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
|
|
166
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
167
|
+
* @param {Boolean} [options.usePassive=false] Indicates that the function specified by listener will never call preventDefault()
|
|
168
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
169
|
+
*/
|
|
170
|
+
constructor(node, options) {
|
|
171
|
+
// Set emitter ID to match DOM Node "expando" property.
|
|
172
|
+
_setEmitterId(this, getProxyEmitterId(node, options));
|
|
173
|
+
// Remember the DOM Node this ProxyEmitter is bound to.
|
|
174
|
+
this._domNode = node;
|
|
175
|
+
// And given options.
|
|
176
|
+
this._options = options;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Registers a callback function to be executed when an event is fired.
|
|
180
|
+
*
|
|
181
|
+
* It attaches a native DOM listener to the DOM Node. When fired,
|
|
182
|
+
* a corresponding Emitter event will also fire with DOM Event object as an argument.
|
|
183
|
+
*
|
|
184
|
+
* **Note**: This is automatically called by the
|
|
185
|
+
* {@link module:utils/emittermixin~EmitterMixin#listenTo `EmitterMixin#listenTo()`}.
|
|
186
|
+
*
|
|
187
|
+
* @method module:utils/dom/emittermixin~ProxyEmitter#attach
|
|
188
|
+
* @param {String} event The name of the event.
|
|
189
|
+
*/
|
|
190
|
+
attach(event) {
|
|
191
|
+
// If the DOM Listener for given event already exist it is pointless
|
|
192
|
+
// to attach another one.
|
|
193
|
+
if (this._domListeners && this._domListeners[event]) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const domListener = this._createDomListener(event);
|
|
197
|
+
// Attach the native DOM listener to DOM Node.
|
|
198
|
+
this._domNode.addEventListener(event, domListener, this._options);
|
|
199
|
+
if (!this._domListeners) {
|
|
200
|
+
this._domListeners = {};
|
|
201
|
+
}
|
|
202
|
+
// Store the native DOM listener in this ProxyEmitter. It will be helpful
|
|
203
|
+
// when stopping listening to the event.
|
|
204
|
+
this._domListeners[event] = domListener;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Stops executing the callback on the given event.
|
|
208
|
+
*
|
|
209
|
+
* **Note**: This is automatically called by the
|
|
210
|
+
* {@link module:utils/emittermixin~EmitterMixin#stopListening `EmitterMixin#stopListening()`}.
|
|
211
|
+
*
|
|
212
|
+
* @method module:utils/dom/emittermixin~ProxyEmitter#detach
|
|
213
|
+
* @param {String} event The name of the event.
|
|
214
|
+
*/
|
|
215
|
+
detach(event) {
|
|
216
|
+
let events;
|
|
217
|
+
// Remove native DOM listeners which are orphans. If no callbacks
|
|
218
|
+
// are awaiting given event, detach native DOM listener from DOM Node.
|
|
219
|
+
// See: {@link attach}.
|
|
220
|
+
if (this._domListeners[event] && (!(events = this._events[event]) || !events.callbacks.length)) {
|
|
221
|
+
this._domListeners[event].removeListener();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Adds callback to emitter for given event.
|
|
226
|
+
*
|
|
227
|
+
* @protected
|
|
228
|
+
* @method module:utils/dom/emittermixin~ProxyEmitter#_addEventListener
|
|
229
|
+
* @param {String} event The name of the event.
|
|
230
|
+
* @param {Function} callback The function to be called on event.
|
|
231
|
+
* @param {Object} [options={}] Additional options.
|
|
232
|
+
* @param {module:utils/priorities~PriorityString|Number} [options.priority='normal'] The priority of this event callback. The higher
|
|
233
|
+
* the priority value the sooner the callback will be fired. Events having the same priority are called in the
|
|
234
|
+
* order they were added.
|
|
235
|
+
*/
|
|
236
|
+
_addEventListener(event, callback, options) {
|
|
237
|
+
this.attach(event);
|
|
238
|
+
EmitterMixin._addEventListener.call(this, event, callback, options);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Removes callback from emitter for given event.
|
|
242
|
+
*
|
|
243
|
+
* @protected
|
|
244
|
+
* @method module:utils/dom/emittermixin~ProxyEmitter#_removeEventListener
|
|
245
|
+
* @param {String} event The name of the event.
|
|
246
|
+
* @param {Function} callback The function to stop being called.
|
|
247
|
+
*/
|
|
248
|
+
_removeEventListener(event, callback) {
|
|
249
|
+
EmitterMixin._removeEventListener.call(this, event, callback);
|
|
250
|
+
this.detach(event);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Creates a native DOM listener callback. When the native DOM event
|
|
254
|
+
* is fired it will fire corresponding event on this ProxyEmitter.
|
|
255
|
+
* Note: A native DOM Event is passed as an argument.
|
|
256
|
+
*
|
|
257
|
+
* @private
|
|
258
|
+
* @method module:utils/dom/emittermixin~ProxyEmitter#_createDomListener
|
|
259
|
+
* @param {String} event The name of the event.
|
|
260
|
+
* @returns {Function} The DOM listener callback.
|
|
261
|
+
*/
|
|
262
|
+
_createDomListener(event) {
|
|
263
|
+
const domListener = (domEvt) => {
|
|
264
|
+
this.fire(event, domEvt);
|
|
265
|
+
};
|
|
266
|
+
// Supply the DOM listener callback with a function that will help
|
|
267
|
+
// detach it from the DOM Node, when it is no longer necessary.
|
|
268
|
+
// See: {@link detach}.
|
|
269
|
+
domListener.removeListener = () => {
|
|
270
|
+
this._domNode.removeEventListener(event, domListener, this._options);
|
|
271
|
+
delete this._domListeners[event];
|
|
272
|
+
};
|
|
273
|
+
return domListener;
|
|
274
|
+
}
|
|
187
275
|
}
|
|
188
|
-
|
|
189
|
-
extend( ProxyEmitter.prototype, EmitterMixin, {
|
|
190
|
-
/**
|
|
191
|
-
* Collection of native DOM listeners.
|
|
192
|
-
*
|
|
193
|
-
* @private
|
|
194
|
-
* @member {Object} module:utils/dom/emittermixin~ProxyEmitter#_domListeners
|
|
195
|
-
*/
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Registers a callback function to be executed when an event is fired.
|
|
199
|
-
*
|
|
200
|
-
* It attaches a native DOM listener to the DOM Node. When fired,
|
|
201
|
-
* a corresponding Emitter event will also fire with DOM Event object as an argument.
|
|
202
|
-
*
|
|
203
|
-
* **Note**: This is automatically called by the
|
|
204
|
-
* {@link module:utils/emittermixin~EmitterMixin#listenTo `EmitterMixin#listenTo()`}.
|
|
205
|
-
*
|
|
206
|
-
* @method module:utils/dom/emittermixin~ProxyEmitter#attach
|
|
207
|
-
* @param {String} event The name of the event.
|
|
208
|
-
*/
|
|
209
|
-
attach( event ) {
|
|
210
|
-
// If the DOM Listener for given event already exist it is pointless
|
|
211
|
-
// to attach another one.
|
|
212
|
-
if ( this._domListeners && this._domListeners[ event ] ) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const domListener = this._createDomListener( event );
|
|
217
|
-
|
|
218
|
-
// Attach the native DOM listener to DOM Node.
|
|
219
|
-
this._domNode.addEventListener( event, domListener, this._options );
|
|
220
|
-
|
|
221
|
-
if ( !this._domListeners ) {
|
|
222
|
-
this._domListeners = {};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Store the native DOM listener in this ProxyEmitter. It will be helpful
|
|
226
|
-
// when stopping listening to the event.
|
|
227
|
-
this._domListeners[ event ] = domListener;
|
|
228
|
-
},
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Stops executing the callback on the given event.
|
|
232
|
-
*
|
|
233
|
-
* **Note**: This is automatically called by the
|
|
234
|
-
* {@link module:utils/emittermixin~EmitterMixin#stopListening `EmitterMixin#stopListening()`}.
|
|
235
|
-
*
|
|
236
|
-
* @method module:utils/dom/emittermixin~ProxyEmitter#detach
|
|
237
|
-
* @param {String} event The name of the event.
|
|
238
|
-
*/
|
|
239
|
-
detach( event ) {
|
|
240
|
-
let events;
|
|
241
|
-
|
|
242
|
-
// Remove native DOM listeners which are orphans. If no callbacks
|
|
243
|
-
// are awaiting given event, detach native DOM listener from DOM Node.
|
|
244
|
-
// See: {@link attach}.
|
|
245
|
-
|
|
246
|
-
if ( this._domListeners[ event ] && ( !( events = this._events[ event ] ) || !events.callbacks.length ) ) {
|
|
247
|
-
this._domListeners[ event ].removeListener();
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Adds callback to emitter for given event.
|
|
253
|
-
*
|
|
254
|
-
* @protected
|
|
255
|
-
* @method module:utils/dom/emittermixin~ProxyEmitter#_addEventListener
|
|
256
|
-
* @param {String} event The name of the event.
|
|
257
|
-
* @param {Function} callback The function to be called on event.
|
|
258
|
-
* @param {Object} [options={}] Additional options.
|
|
259
|
-
* @param {module:utils/priorities~PriorityString|Number} [options.priority='normal'] The priority of this event callback. The higher
|
|
260
|
-
* the priority value the sooner the callback will be fired. Events having the same priority are called in the
|
|
261
|
-
* order they were added.
|
|
262
|
-
*/
|
|
263
|
-
_addEventListener( event, callback, options ) {
|
|
264
|
-
this.attach( event );
|
|
265
|
-
EmitterMixin._addEventListener.call( this, event, callback, options );
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Removes callback from emitter for given event.
|
|
270
|
-
*
|
|
271
|
-
* @protected
|
|
272
|
-
* @method module:utils/dom/emittermixin~ProxyEmitter#_removeEventListener
|
|
273
|
-
* @param {String} event The name of the event.
|
|
274
|
-
* @param {Function} callback The function to stop being called.
|
|
275
|
-
*/
|
|
276
|
-
_removeEventListener( event, callback ) {
|
|
277
|
-
EmitterMixin._removeEventListener.call( this, event, callback );
|
|
278
|
-
this.detach( event );
|
|
279
|
-
},
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Creates a native DOM listener callback. When the native DOM event
|
|
283
|
-
* is fired it will fire corresponding event on this ProxyEmitter.
|
|
284
|
-
* Note: A native DOM Event is passed as an argument.
|
|
285
|
-
*
|
|
286
|
-
* @private
|
|
287
|
-
* @method module:utils/dom/emittermixin~ProxyEmitter#_createDomListener
|
|
288
|
-
* @param {String} event The name of the event.
|
|
289
|
-
* @returns {Function} The DOM listener callback.
|
|
290
|
-
*/
|
|
291
|
-
_createDomListener( event ) {
|
|
292
|
-
const domListener = domEvt => {
|
|
293
|
-
this.fire( event, domEvt );
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
// Supply the DOM listener callback with a function that will help
|
|
297
|
-
// detach it from the DOM Node, when it is no longer necessary.
|
|
298
|
-
// See: {@link detach}.
|
|
299
|
-
domListener.removeListener = () => {
|
|
300
|
-
this._domNode.removeEventListener( event, domListener, this._options );
|
|
301
|
-
delete this._domListeners[ event ];
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
return domListener;
|
|
305
|
-
}
|
|
306
|
-
} );
|
|
307
|
-
|
|
276
|
+
mix(ProxyEmitter, EmitterMixin);
|
|
308
277
|
// Gets an unique DOM Node identifier. The identifier will be set if not defined.
|
|
309
278
|
//
|
|
310
279
|
// @private
|
|
311
280
|
// @param {Node} node
|
|
312
281
|
// @returns {String} UID for given DOM Node.
|
|
313
|
-
function getNodeUID(
|
|
314
|
-
|
|
282
|
+
function getNodeUID(node) {
|
|
283
|
+
return node['data-ck-expando'] || (node['data-ck-expando'] = uid());
|
|
315
284
|
}
|
|
316
|
-
|
|
317
285
|
// Gets id of the ProxyEmitter for the given node.
|
|
318
286
|
//
|
|
319
287
|
// Combines DOM Node identifier and additional options.
|
|
@@ -322,20 +290,12 @@ function getNodeUID( node ) {
|
|
|
322
290
|
// @param {Node} node
|
|
323
291
|
// @param {Object} options Additional options.
|
|
324
292
|
// @returns {String} ProxyEmitter id.
|
|
325
|
-
function getProxyEmitterId(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return id;
|
|
293
|
+
function getProxyEmitterId(node, options) {
|
|
294
|
+
let id = getNodeUID(node);
|
|
295
|
+
for (const option of Object.keys(options).sort()) {
|
|
296
|
+
if (options[option]) {
|
|
297
|
+
id += '-' + option;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return id;
|
|
335
301
|
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Interface representing classes which mix in {@link module:utils/dom/emittermixin~EmitterMixin}.
|
|
339
|
-
*
|
|
340
|
-
* @interface Emitter
|
|
341
|
-
*/
|
package/src/dom/getancestors.js
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/* globals Node */
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* @module utils/dom/getancestors
|
|
10
8
|
*/
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Returns all ancestors of given DOM node, starting from the top-most (root). Includes the given node itself. If the
|
|
14
11
|
* node is a part of `DocumentFragment` that `DocumentFragment` will be returned. In contrary, if the node is
|
|
@@ -18,14 +15,13 @@
|
|
|
18
15
|
* @param {Node} node DOM node.
|
|
19
16
|
* @returns {Array.<Node|DocumentFragment>} Array of given `node` parents.
|
|
20
17
|
*/
|
|
21
|
-
export default function getAncestors(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return nodes;
|
|
18
|
+
export default function getAncestors(node) {
|
|
19
|
+
const nodes = [];
|
|
20
|
+
let currentNode = node;
|
|
21
|
+
// We are interested in `Node`s `DocumentFragment`s only.
|
|
22
|
+
while (currentNode && currentNode.nodeType != Node.DOCUMENT_NODE) {
|
|
23
|
+
nodes.unshift(currentNode);
|
|
24
|
+
currentNode = currentNode.parentNode;
|
|
25
|
+
}
|
|
26
|
+
return nodes;
|
|
31
27
|
}
|
|
@@ -2,26 +2,23 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/dom/getborderwidths
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Returns an object containing CSS border widths of a specified HTML element.
|
|
12
10
|
*
|
|
13
11
|
* @param {HTMLElement} element An element which has CSS borders.
|
|
14
|
-
* @returns {
|
|
12
|
+
* @returns {module:utils/dom/getborderwidths~BorderWidths} An object containing `top`, `left`, `right` and `bottom` properties
|
|
15
13
|
* with numerical values of the `border-[top,left,right,bottom]-width` CSS styles.
|
|
16
14
|
*/
|
|
17
|
-
export default function getBorderWidths(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
15
|
+
export default function getBorderWidths(element) {
|
|
16
|
+
// Call getComputedStyle on the window the element document belongs to.
|
|
17
|
+
const style = element.ownerDocument.defaultView.getComputedStyle(element);
|
|
18
|
+
return {
|
|
19
|
+
top: parseInt(style.borderTopWidth, 10),
|
|
20
|
+
right: parseInt(style.borderRightWidth, 10),
|
|
21
|
+
bottom: parseInt(style.borderBottomWidth, 10),
|
|
22
|
+
left: parseInt(style.borderLeftWidth, 10)
|
|
23
|
+
};
|
|
27
24
|
}
|
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/dom/getcommonancestor
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import getAncestors from './getancestors';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Searches and returns the lowest common ancestor of two given nodes.
|
|
14
11
|
*
|
|
@@ -16,16 +13,13 @@ import getAncestors from './getancestors';
|
|
|
16
13
|
* @param {Node} nodeB Second node.
|
|
17
14
|
* @returns {Node|DocumentFragment|Document|null} Lowest common ancestor of both nodes or `null` if nodes do not have a common ancestor.
|
|
18
15
|
*/
|
|
19
|
-
export default function getCommonAncestor(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return i === 0 ? null : ancestorsA[ i - 1 ];
|
|
16
|
+
export default function getCommonAncestor(nodeA, nodeB) {
|
|
17
|
+
const ancestorsA = getAncestors(nodeA);
|
|
18
|
+
const ancestorsB = getAncestors(nodeB);
|
|
19
|
+
let i = 0;
|
|
20
|
+
// It does not matter which array is shorter.
|
|
21
|
+
while (ancestorsA[i] == ancestorsB[i] && ancestorsA[i]) {
|
|
22
|
+
i++;
|
|
23
|
+
}
|
|
24
|
+
return i === 0 ? null : ancestorsA[i - 1];
|
|
31
25
|
}
|
|
@@ -2,23 +2,19 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/* globals HTMLTextAreaElement */
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* @module utils/dom/getdatafromelement
|
|
10
8
|
*/
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Gets data from a given source element.
|
|
14
11
|
*
|
|
15
12
|
* @param {HTMLElement} el The element from which the data will be retrieved.
|
|
16
13
|
* @returns {String} The data string.
|
|
17
14
|
*/
|
|
18
|
-
export default function getDataFromElement(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return el.innerHTML;
|
|
15
|
+
export default function getDataFromElement(el) {
|
|
16
|
+
if (el instanceof HTMLTextAreaElement) {
|
|
17
|
+
return el.value;
|
|
18
|
+
}
|
|
19
|
+
return el.innerHTML;
|
|
24
20
|
}
|