@ckeditor/ckeditor5-utils 39.0.2 → 40.0.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.
Files changed (131) hide show
  1. package/package.json +1 -1
  2. package/src/areconnectedthroughproperties.d.ts +11 -11
  3. package/src/areconnectedthroughproperties.js +73 -73
  4. package/src/ckeditorerror.d.ts +123 -123
  5. package/src/ckeditorerror.js +176 -176
  6. package/src/collection.d.ts +427 -427
  7. package/src/collection.js +575 -575
  8. package/src/comparearrays.d.ts +30 -30
  9. package/src/comparearrays.js +47 -47
  10. package/src/config.d.ts +163 -163
  11. package/src/config.js +162 -162
  12. package/src/count.d.ts +18 -18
  13. package/src/count.js +24 -24
  14. package/src/delay.d.ts +19 -19
  15. package/src/delay.js +26 -26
  16. package/src/diff.d.ts +31 -31
  17. package/src/diff.js +115 -115
  18. package/src/difftochanges.d.ts +59 -59
  19. package/src/difftochanges.js +79 -79
  20. package/src/dom/createelement.d.ts +57 -57
  21. package/src/dom/createelement.js +40 -40
  22. package/src/dom/emittermixin.d.ts +142 -142
  23. package/src/dom/emittermixin.js +239 -239
  24. package/src/dom/findclosestscrollableancestor.d.ts +11 -11
  25. package/src/dom/findclosestscrollableancestor.js +31 -31
  26. package/src/dom/getancestors.d.ts +17 -17
  27. package/src/dom/getancestors.js +27 -27
  28. package/src/dom/getborderwidths.d.ts +24 -24
  29. package/src/dom/getborderwidths.js +24 -24
  30. package/src/dom/getcommonancestor.d.ts +12 -12
  31. package/src/dom/getcommonancestor.js +25 -25
  32. package/src/dom/getdatafromelement.d.ts +14 -14
  33. package/src/dom/getdatafromelement.js +20 -20
  34. package/src/dom/getpositionedancestor.d.ts +10 -10
  35. package/src/dom/getpositionedancestor.js +22 -22
  36. package/src/dom/global.d.ts +32 -32
  37. package/src/dom/global.js +35 -35
  38. package/src/dom/indexof.d.ts +14 -14
  39. package/src/dom/indexof.js +21 -21
  40. package/src/dom/insertat.d.ts +15 -15
  41. package/src/dom/insertat.js +17 -17
  42. package/src/dom/iscomment.d.ts +11 -11
  43. package/src/dom/iscomment.js +14 -14
  44. package/src/dom/isnode.d.ts +11 -11
  45. package/src/dom/isnode.js +21 -21
  46. package/src/dom/isrange.d.ts +11 -11
  47. package/src/dom/isrange.js +13 -13
  48. package/src/dom/istext.d.ts +11 -11
  49. package/src/dom/istext.js +13 -13
  50. package/src/dom/isvalidattributename.d.ts +10 -10
  51. package/src/dom/isvalidattributename.js +22 -22
  52. package/src/dom/isvisible.d.ts +18 -18
  53. package/src/dom/isvisible.js +20 -20
  54. package/src/dom/iswindow.d.ts +11 -11
  55. package/src/dom/iswindow.js +22 -22
  56. package/src/dom/position.d.ts +211 -208
  57. package/src/dom/position.js +313 -305
  58. package/src/dom/rect.d.ts +195 -191
  59. package/src/dom/rect.js +474 -388
  60. package/src/dom/remove.d.ts +13 -13
  61. package/src/dom/remove.js +18 -18
  62. package/src/dom/resizeobserver.d.ts +74 -74
  63. package/src/dom/resizeobserver.js +126 -126
  64. package/src/dom/scroll.d.ts +73 -73
  65. package/src/dom/scroll.js +383 -383
  66. package/src/dom/setdatainelement.d.ts +14 -14
  67. package/src/dom/setdatainelement.js +20 -20
  68. package/src/dom/tounit.d.ts +22 -22
  69. package/src/dom/tounit.js +16 -16
  70. package/src/elementreplacer.d.ts +31 -31
  71. package/src/elementreplacer.js +43 -43
  72. package/src/emittermixin.d.ts +312 -312
  73. package/src/emittermixin.js +453 -453
  74. package/src/env.d.ts +117 -117
  75. package/src/env.js +122 -122
  76. package/src/eventinfo.d.ts +58 -58
  77. package/src/eventinfo.js +26 -26
  78. package/src/fastdiff.d.ts +112 -112
  79. package/src/fastdiff.js +248 -248
  80. package/src/first.d.ts +11 -11
  81. package/src/first.js +17 -17
  82. package/src/focustracker.d.ts +75 -75
  83. package/src/focustracker.js +95 -95
  84. package/src/index.d.ts +61 -62
  85. package/src/index.js +60 -61
  86. package/src/inserttopriorityarray.d.ts +30 -30
  87. package/src/inserttopriorityarray.js +21 -21
  88. package/src/isiterable.d.ts +14 -14
  89. package/src/isiterable.js +16 -16
  90. package/src/keyboard.d.ts +126 -126
  91. package/src/keyboard.js +221 -221
  92. package/src/keystrokehandler.d.ts +87 -87
  93. package/src/keystrokehandler.js +122 -122
  94. package/src/language.d.ts +17 -17
  95. package/src/language.js +19 -19
  96. package/src/locale.d.ts +120 -120
  97. package/src/locale.js +76 -76
  98. package/src/mapsequal.d.ts +15 -15
  99. package/src/mapsequal.js +27 -27
  100. package/src/mix.d.ts +85 -85
  101. package/src/mix.js +50 -50
  102. package/src/nth.d.ts +16 -16
  103. package/src/nth.js +24 -24
  104. package/src/objecttomap.d.ts +23 -23
  105. package/src/objecttomap.js +27 -27
  106. package/src/observablemixin.d.ts +560 -560
  107. package/src/observablemixin.js +580 -580
  108. package/src/priorities.d.ts +33 -33
  109. package/src/priorities.js +23 -23
  110. package/src/splicearray.d.ts +26 -26
  111. package/src/splicearray.js +40 -40
  112. package/src/spy.d.ts +21 -21
  113. package/src/spy.js +22 -22
  114. package/src/toarray.d.ts +25 -25
  115. package/src/toarray.js +7 -7
  116. package/src/tomap.d.ts +19 -19
  117. package/src/tomap.js +29 -29
  118. package/src/translation-service.d.ts +168 -168
  119. package/src/translation-service.js +198 -198
  120. package/src/uid.d.ts +15 -15
  121. package/src/uid.js +57 -57
  122. package/src/unicode.d.ts +54 -54
  123. package/src/unicode.js +85 -85
  124. package/src/verifylicense.d.ts +15 -15
  125. package/src/verifylicense.js +87 -87
  126. package/src/version.d.ts +10 -10
  127. package/src/version.js +153 -153
  128. package/src/dom/getelementsintersectionrect.d.ts +0 -14
  129. package/src/dom/getelementsintersectionrect.js +0 -43
  130. package/src/dom/getscrollableancestors.d.ts +0 -14
  131. package/src/dom/getscrollableancestors.js +0 -28
@@ -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>;