@ckeditor/ckeditor5-utils 34.2.0 → 35.1.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 +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 -762
- 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 +202 -263
- 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 +15 -4
- 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 +368 -634
- package/src/env.js +109 -116
- package/src/eventinfo.js +12 -65
- package/src/fastdiff.js +96 -128
- package/src/first.js +8 -12
- package/src/focustracker.js +77 -133
- 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 +17 -16
- package/src/nth.js +8 -11
- package/src/objecttomap.js +7 -11
- package/src/observablemixin.js +474 -778
- 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 +57 -93
- 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,14 @@
|
|
|
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
|
-
|
|
5
|
+
/* eslint-disable new-cap */
|
|
6
6
|
/**
|
|
7
7
|
* @module utils/dom/emittermixin
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
import { default as EmitterMixin, _getEmitterListenedTo, _setEmitterId } from '../emittermixin';
|
|
9
|
+
import { _getEmitterListenedTo, _setEmitterId, Emitter as BaseEmitter } from '../emittermixin';
|
|
11
10
|
import uid from '../uid';
|
|
12
11
|
import isNode from './isnode';
|
|
13
12
|
import isWindow from './iswindow';
|
|
14
|
-
import { extend } from 'lodash-es';
|
|
15
|
-
|
|
16
13
|
/**
|
|
17
14
|
* Mixin that injects the DOM events API into its host. It provides the API
|
|
18
15
|
* compatible with {@link module:utils/emittermixin~EmitterMixin}.
|
|
@@ -22,9 +19,9 @@ import { extend } from 'lodash-es';
|
|
|
22
19
|
*
|
|
23
20
|
* import mix from '../utils/mix.js';
|
|
24
21
|
* import DomEmitterMixin from '../utils/dom/emittermixin.js';
|
|
22
|
+
* import { Emitter } from '../utils/emittermixin.js';
|
|
25
23
|
*
|
|
26
|
-
* class SomeView {}
|
|
27
|
-
* mix( SomeView, DomEmitterMixin );
|
|
24
|
+
* class SomeView extends DomEmitterMixin( Emitter ) {}
|
|
28
25
|
*
|
|
29
26
|
* const view = new SomeView();
|
|
30
27
|
* view.listenTo( domElement, ( evt, domEvt ) => {
|
|
@@ -35,104 +32,79 @@ import { extend } from 'lodash-es';
|
|
|
35
32
|
* @mixes module:utils/emittermixin~EmitterMixin
|
|
36
33
|
* @implements module:utils/dom/emittermixin~Emitter
|
|
37
34
|
*/
|
|
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
|
-
|
|
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
|
-
* @returns {module:utils/dom/emittermixin~ProxyEmitter|null} ProxyEmitter instance bound to the DOM Node.
|
|
112
|
-
*/
|
|
113
|
-
_getProxyEmitter( node, options ) {
|
|
114
|
-
return _getEmitterListenedTo( this, getProxyEmitterId( node, options ) );
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Retrieves all the ProxyEmitter instances for given DOM Node residing in this Host.
|
|
119
|
-
*
|
|
120
|
-
* @private
|
|
121
|
-
* @param {Node} node DOM Node of the ProxyEmitter.
|
|
122
|
-
* @returns {Array.<module:utils/dom/emittermixin~ProxyEmitter>}
|
|
123
|
-
*/
|
|
124
|
-
_getAllProxyEmitters( node ) {
|
|
125
|
-
return [
|
|
126
|
-
{ capture: false, passive: false },
|
|
127
|
-
{ capture: false, passive: true },
|
|
128
|
-
{ capture: true, passive: false },
|
|
129
|
-
{ capture: true, passive: true }
|
|
130
|
-
].map( options => this._getProxyEmitter( node, options ) ).filter( proxy => !!proxy );
|
|
131
|
-
}
|
|
132
|
-
} );
|
|
133
|
-
|
|
134
|
-
export default DomEmitterMixin;
|
|
135
|
-
|
|
35
|
+
export default function DomEmitterMixin(base) {
|
|
36
|
+
class Mixin extends base {
|
|
37
|
+
listenTo(emitter, event, callback, options = {}) {
|
|
38
|
+
// Check if emitter is an instance of DOM Node. If so, use corresponding ProxyEmitter (or create one if not existing).
|
|
39
|
+
if (isNode(emitter) || isWindow(emitter)) {
|
|
40
|
+
const proxyOptions = {
|
|
41
|
+
capture: !!options.useCapture,
|
|
42
|
+
passive: !!options.usePassive
|
|
43
|
+
};
|
|
44
|
+
const proxyEmitter = this._getProxyEmitter(emitter, proxyOptions) || new ProxyEmitter(emitter, proxyOptions);
|
|
45
|
+
this.listenTo(proxyEmitter, event, callback, options);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
49
|
+
BaseEmitter.prototype.listenTo.call(this, emitter, event, callback, options);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
stopListening(emitter, event, callback) {
|
|
53
|
+
// Check if the emitter is an instance of DOM Node. If so, forward the call to the corresponding ProxyEmitters.
|
|
54
|
+
if (isNode(emitter) || isWindow(emitter)) {
|
|
55
|
+
const proxyEmitters = this._getAllProxyEmitters(emitter);
|
|
56
|
+
for (const proxy of proxyEmitters) {
|
|
57
|
+
this.stopListening(proxy, event, callback);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
62
|
+
BaseEmitter.prototype.stopListening.call(this, emitter, event, callback);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves ProxyEmitter instance for given DOM Node residing in this Host and given options.
|
|
67
|
+
*
|
|
68
|
+
* @private
|
|
69
|
+
* @param {Node|Window} node DOM Node of the ProxyEmitter.
|
|
70
|
+
* @param {Object} [options] Additional options.
|
|
71
|
+
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
|
|
72
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
73
|
+
* @param {Boolean} [options.usePassive=false] Indicates that the function specified by listener will never call preventDefault()
|
|
74
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
75
|
+
* @returns {module:utils/dom/emittermixin~ProxyEmitter|null} ProxyEmitter instance bound to the DOM Node.
|
|
76
|
+
*/
|
|
77
|
+
_getProxyEmitter(node, options) {
|
|
78
|
+
return _getEmitterListenedTo(this, getProxyEmitterId(node, options));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves all the ProxyEmitter instances for given DOM Node residing in this Host.
|
|
82
|
+
*
|
|
83
|
+
* @private
|
|
84
|
+
* @param {Node|Window} node DOM Node of the ProxyEmitter.
|
|
85
|
+
* @returns {Array.<module:utils/dom/emittermixin~ProxyEmitter>}
|
|
86
|
+
*/
|
|
87
|
+
_getAllProxyEmitters(node) {
|
|
88
|
+
return [
|
|
89
|
+
{ capture: false, passive: false },
|
|
90
|
+
{ capture: false, passive: true },
|
|
91
|
+
{ capture: true, passive: false },
|
|
92
|
+
{ capture: true, passive: true }
|
|
93
|
+
].map(options => this._getProxyEmitter(node, options)).filter(proxy => !!proxy);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return Mixin;
|
|
97
|
+
}
|
|
98
|
+
export const Emitter = DomEmitterMixin(BaseEmitter);
|
|
99
|
+
// Backward compatibility with `mix`
|
|
100
|
+
([
|
|
101
|
+
'_getProxyEmitter', '_getAllProxyEmitters',
|
|
102
|
+
'on', 'once', 'off', 'listenTo',
|
|
103
|
+
'stopListening', 'fire', 'delegate', 'stopDelegating',
|
|
104
|
+
'_addEventListener', '_removeEventListener'
|
|
105
|
+
]).forEach(key => {
|
|
106
|
+
DomEmitterMixin[key] = Emitter.prototype[key];
|
|
107
|
+
});
|
|
136
108
|
/**
|
|
137
109
|
* Creates a ProxyEmitter instance. Such an instance is a bridge between a DOM Node firing events
|
|
138
110
|
* and any Host listening to them. It is backwards compatible with {@link module:utils/emittermixin~EmitterMixin#on}.
|
|
@@ -165,155 +137,130 @@ export default DomEmitterMixin;
|
|
|
165
137
|
* @implements module:utils/dom/emittermixin~Emitter
|
|
166
138
|
* @private
|
|
167
139
|
*/
|
|
168
|
-
class ProxyEmitter {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
140
|
+
class ProxyEmitter extends BaseEmitter {
|
|
141
|
+
/**
|
|
142
|
+
* @param {Node|Window} node DOM Node that fires events.
|
|
143
|
+
* @param {Object} [options] Additional options.
|
|
144
|
+
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
|
|
145
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
146
|
+
* @param {Boolean} [options.usePassive=false] Indicates that the function specified by listener will never call preventDefault()
|
|
147
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
148
|
+
*/
|
|
149
|
+
constructor(node, options) {
|
|
150
|
+
super();
|
|
151
|
+
// Set emitter ID to match DOM Node "expando" property.
|
|
152
|
+
_setEmitterId(this, getProxyEmitterId(node, options));
|
|
153
|
+
// Remember the DOM Node this ProxyEmitter is bound to.
|
|
154
|
+
this._domNode = node;
|
|
155
|
+
// And given options.
|
|
156
|
+
this._options = options;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Registers a callback function to be executed when an event is fired.
|
|
160
|
+
*
|
|
161
|
+
* It attaches a native DOM listener to the DOM Node. When fired,
|
|
162
|
+
* a corresponding Emitter event will also fire with DOM Event object as an argument.
|
|
163
|
+
*
|
|
164
|
+
* **Note**: This is automatically called by the
|
|
165
|
+
* {@link module:utils/emittermixin~EmitterMixin#listenTo `EmitterMixin#listenTo()`}.
|
|
166
|
+
*
|
|
167
|
+
* @method module:utils/dom/emittermixin~ProxyEmitter#attach
|
|
168
|
+
* @param {String} event The name of the event.
|
|
169
|
+
*/
|
|
170
|
+
attach(event) {
|
|
171
|
+
// If the DOM Listener for given event already exist it is pointless
|
|
172
|
+
// to attach another one.
|
|
173
|
+
if (this._domListeners && this._domListeners[event]) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const domListener = this._createDomListener(event);
|
|
177
|
+
// Attach the native DOM listener to DOM Node.
|
|
178
|
+
this._domNode.addEventListener(event, domListener, this._options);
|
|
179
|
+
if (!this._domListeners) {
|
|
180
|
+
this._domListeners = {};
|
|
181
|
+
}
|
|
182
|
+
// Store the native DOM listener in this ProxyEmitter. It will be helpful
|
|
183
|
+
// when stopping listening to the event.
|
|
184
|
+
this._domListeners[event] = domListener;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Stops executing the callback on the given event.
|
|
188
|
+
*
|
|
189
|
+
* **Note**: This is automatically called by the
|
|
190
|
+
* {@link module:utils/emittermixin~EmitterMixin#stopListening `EmitterMixin#stopListening()`}.
|
|
191
|
+
*
|
|
192
|
+
* @method module:utils/dom/emittermixin~ProxyEmitter#detach
|
|
193
|
+
* @param {String} event The name of the event.
|
|
194
|
+
*/
|
|
195
|
+
detach(event) {
|
|
196
|
+
let events;
|
|
197
|
+
// Remove native DOM listeners which are orphans. If no callbacks
|
|
198
|
+
// are awaiting given event, detach native DOM listener from DOM Node.
|
|
199
|
+
// See: {@link attach}.
|
|
200
|
+
if (this._domListeners[event] && (!(events = this._events[event]) || !events.callbacks.length)) {
|
|
201
|
+
this._domListeners[event].removeListener();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Adds callback to emitter for given event.
|
|
206
|
+
*
|
|
207
|
+
* @protected
|
|
208
|
+
* @method module:utils/dom/emittermixin~ProxyEmitter#_addEventListener
|
|
209
|
+
* @param {String} event The name of the event.
|
|
210
|
+
* @param {Function} callback The function to be called on event.
|
|
211
|
+
* @param {Object} [options={}] Additional options.
|
|
212
|
+
* @param {module:utils/priorities~PriorityString|Number} [options.priority='normal'] The priority of this event callback. The higher
|
|
213
|
+
* the priority value the sooner the callback will be fired. Events having the same priority are called in the
|
|
214
|
+
* order they were added.
|
|
215
|
+
*/
|
|
216
|
+
_addEventListener(event, callback, options) {
|
|
217
|
+
this.attach(event);
|
|
218
|
+
BaseEmitter.prototype._addEventListener.call(this, event, callback, options);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Removes callback from emitter for given event.
|
|
222
|
+
*
|
|
223
|
+
* @protected
|
|
224
|
+
* @method module:utils/dom/emittermixin~ProxyEmitter#_removeEventListener
|
|
225
|
+
* @param {String} event The name of the event.
|
|
226
|
+
* @param {Function} callback The function to stop being called.
|
|
227
|
+
*/
|
|
228
|
+
_removeEventListener(event, callback) {
|
|
229
|
+
BaseEmitter.prototype._removeEventListener.call(this, event, callback);
|
|
230
|
+
this.detach(event);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Creates a native DOM listener callback. When the native DOM event
|
|
234
|
+
* is fired it will fire corresponding event on this ProxyEmitter.
|
|
235
|
+
* Note: A native DOM Event is passed as an argument.
|
|
236
|
+
*
|
|
237
|
+
* @private
|
|
238
|
+
* @method module:utils/dom/emittermixin~ProxyEmitter#_createDomListener
|
|
239
|
+
* @param {String} event The name of the event.
|
|
240
|
+
* @returns {Function} The DOM listener callback.
|
|
241
|
+
*/
|
|
242
|
+
_createDomListener(event) {
|
|
243
|
+
const domListener = (domEvt) => {
|
|
244
|
+
this.fire(event, domEvt);
|
|
245
|
+
};
|
|
246
|
+
// Supply the DOM listener callback with a function that will help
|
|
247
|
+
// detach it from the DOM Node, when it is no longer necessary.
|
|
248
|
+
// See: {@link detach}.
|
|
249
|
+
domListener.removeListener = () => {
|
|
250
|
+
this._domNode.removeEventListener(event, domListener, this._options);
|
|
251
|
+
delete this._domListeners[event];
|
|
252
|
+
};
|
|
253
|
+
return domListener;
|
|
254
|
+
}
|
|
187
255
|
}
|
|
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
|
-
|
|
308
256
|
// Gets an unique DOM Node identifier. The identifier will be set if not defined.
|
|
309
257
|
//
|
|
310
258
|
// @private
|
|
311
259
|
// @param {Node} node
|
|
312
260
|
// @returns {String} UID for given DOM Node.
|
|
313
|
-
function getNodeUID(
|
|
314
|
-
|
|
261
|
+
function getNodeUID(node) {
|
|
262
|
+
return node['data-ck-expando'] || (node['data-ck-expando'] = uid());
|
|
315
263
|
}
|
|
316
|
-
|
|
317
264
|
// Gets id of the ProxyEmitter for the given node.
|
|
318
265
|
//
|
|
319
266
|
// Combines DOM Node identifier and additional options.
|
|
@@ -322,20 +269,12 @@ function getNodeUID( node ) {
|
|
|
322
269
|
// @param {Node} node
|
|
323
270
|
// @param {Object} options Additional options.
|
|
324
271
|
// @returns {String} ProxyEmitter id.
|
|
325
|
-
function getProxyEmitterId(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return id;
|
|
272
|
+
function getProxyEmitterId(node, options) {
|
|
273
|
+
let id = getNodeUID(node);
|
|
274
|
+
for (const option of Object.keys(options).sort()) {
|
|
275
|
+
if (options[option]) {
|
|
276
|
+
id += '-' + option;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return id;
|
|
335
280
|
}
|
|
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
|
}
|