@ckeditor/ckeditor5-utils 35.3.2 → 36.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.
- package/LICENSE.md +1 -1
- package/package.json +5 -5
- package/src/areconnectedthroughproperties.js +7 -9
- package/src/ckeditorerror.js +52 -71
- package/src/collection.js +108 -150
- package/src/comparearrays.js +11 -9
- package/src/config.js +30 -84
- package/src/count.js +6 -4
- package/src/diff.js +8 -6
- package/src/difftochanges.js +18 -15
- package/src/dom/createelement.js +12 -10
- package/src/dom/emittermixin.js +44 -85
- package/src/dom/findclosestscrollableancestor.js +30 -0
- package/src/dom/getancestors.js +3 -3
- package/src/dom/getborderwidths.js +3 -3
- package/src/dom/getcommonancestor.js +4 -4
- package/src/dom/getdatafromelement.js +3 -3
- package/src/dom/getpositionedancestor.js +2 -3
- package/src/dom/global.js +13 -15
- package/src/dom/indexof.js +3 -3
- package/src/dom/insertat.js +4 -4
- package/src/dom/iscomment.js +1 -4
- package/src/dom/isnode.js +1 -4
- package/src/dom/isrange.js +1 -4
- package/src/dom/istext.js +1 -4
- package/src/dom/isvisible.js +1 -4
- package/src/dom/iswindow.js +1 -4
- package/src/dom/position.js +111 -134
- package/src/dom/rect.js +43 -53
- package/src/dom/remove.js +2 -2
- package/src/dom/resizeobserver.js +11 -36
- package/src/dom/scroll.js +86 -92
- package/src/dom/setdatainelement.js +3 -3
- package/src/dom/tounit.js +2 -11
- package/src/elementreplacer.js +3 -3
- package/src/emittermixin.js +49 -49
- package/src/env.js +15 -76
- package/src/eventinfo.js +3 -3
- package/src/fastdiff.js +116 -97
- package/src/first.js +1 -4
- package/src/focustracker.js +12 -20
- package/src/index.js +19 -1
- package/src/inserttopriorityarray.js +3 -3
- package/src/isiterable.js +3 -3
- package/src/keyboard.js +21 -22
- package/src/keystrokehandler.js +27 -25
- package/src/language.js +2 -3
- package/src/locale.js +12 -15
- package/src/mapsequal.js +5 -5
- package/src/mix.js +16 -14
- package/src/nth.js +1 -5
- package/src/objecttomap.js +7 -5
- package/src/observablemixin.js +127 -151
- package/src/priorities.js +1 -10
- package/src/splicearray.js +13 -12
- package/src/spy.js +2 -2
- package/src/toarray.js +1 -1
- package/src/tomap.js +8 -6
- package/src/translation-service.js +71 -53
- package/src/uid.js +6 -4
- package/src/unicode.js +10 -16
- package/src/version.js +33 -27
package/src/diff.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -12,17 +12,19 @@ import fastDiff from './fastdiff';
|
|
|
12
12
|
* Calculates the difference between two arrays or strings producing an array containing a list of changes
|
|
13
13
|
* necessary to transform input into output.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* diff( 'aba', 'acca' ); // [ 'equal', 'insert', 'insert', 'delete', 'equal' ]
|
|
17
|
+
* ```
|
|
16
18
|
*
|
|
17
19
|
* This function is based on the "O(NP) Sequence Comparison Algorithm" by Sun Wu, Udi Manber, Gene Myers, Webb Miller.
|
|
18
20
|
* Unfortunately, while it gives the most precise results, its to complex for longer strings/arrow (above 200 items).
|
|
19
21
|
* Therefore, `diff()` automatically switches to {@link module:utils/fastdiff~fastDiff `fastDiff()`} when detecting
|
|
20
22
|
* such a scenario. The return formats of both functions are identical.
|
|
21
23
|
*
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @returns
|
|
24
|
+
* @param a Input array or string.
|
|
25
|
+
* @param b Output array or string.
|
|
26
|
+
* @param cmp Optional function used to compare array values, by default === is used.
|
|
27
|
+
* @returns Array of changes.
|
|
26
28
|
*/
|
|
27
29
|
export default function diff(a, b, cmp) {
|
|
28
30
|
// Set the comparator function.
|
package/src/difftochanges.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -9,23 +9,26 @@
|
|
|
9
9
|
* Creates a set of changes which need to be applied to the input in order to transform
|
|
10
10
|
* it into the output. This function can be used with strings or arrays.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const input = Array.from( 'abc' );
|
|
14
|
+
* const output = Array.from( 'xaby' );
|
|
15
|
+
* const changes = diffToChanges( diff( input, output ), output );
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
17
|
+
* changes.forEach( change => {
|
|
18
|
+
* if ( change.type == 'insert' ) {
|
|
19
|
+
* input.splice( change.index, 0, ...change.values );
|
|
20
|
+
* } else if ( change.type == 'delete' ) {
|
|
21
|
+
* input.splice( change.index, change.howMany );
|
|
22
|
+
* }
|
|
23
|
+
* } );
|
|
23
24
|
*
|
|
24
|
-
*
|
|
25
|
+
* input.join( '' ) == output.join( '' ); // -> true
|
|
26
|
+
* ```
|
|
25
27
|
*
|
|
26
|
-
* @
|
|
27
|
-
* @param
|
|
28
|
-
* @
|
|
28
|
+
* @typeParam T The type of output array element.
|
|
29
|
+
* @param diff Result of {@link module:utils/diff~diff}.
|
|
30
|
+
* @param output The string or array which was passed as diff's output.
|
|
31
|
+
* @returns Set of changes (insert or delete) which need to be applied to the input
|
|
29
32
|
* in order to transform it into the output.
|
|
30
33
|
*/
|
|
31
34
|
export default function diffToChanges(diff, output) {
|
package/src/dom/createelement.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -10,17 +10,19 @@ import { isString } from 'lodash-es';
|
|
|
10
10
|
/**
|
|
11
11
|
* Creates element with attributes and children.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* createElement( document, 'p' ); // <p>
|
|
15
|
+
* createElement( document, 'p', { class: 'foo' } ); // <p class="foo">
|
|
16
|
+
* createElement( document, 'p', null, 'foo' ); // <p>foo</p>
|
|
17
|
+
* createElement( document, 'p', null, [ 'foo', createElement( document, 'img' ) ] ); // <p>foo<img></p>
|
|
18
|
+
* ```
|
|
17
19
|
*
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
20
|
+
* @param doc Document used to create element.
|
|
21
|
+
* @param name Name of the element.
|
|
22
|
+
* @param attributes Object keys will become attributes keys and object values will became attributes values.
|
|
23
|
+
* @param children Child or any iterable of children. Strings will be automatically turned
|
|
22
24
|
* into Text nodes.
|
|
23
|
-
* @returns
|
|
25
|
+
* @returns Created element.
|
|
24
26
|
*/
|
|
25
27
|
export default function createElement(doc, name, attributes = {}, children = []) {
|
|
26
28
|
const namespace = attributes && attributes.xmlns;
|
package/src/dom/emittermixin.js
CHANGED
|
@@ -1,38 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
-
/* eslint-disable new-cap */
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/dom/emittermixin
|
|
8
7
|
*/
|
|
9
|
-
import { _getEmitterListenedTo, _setEmitterId
|
|
8
|
+
import EmitterMixin, { _getEmitterListenedTo, _setEmitterId } from '../emittermixin';
|
|
10
9
|
import uid from '../uid';
|
|
11
10
|
import isNode from './isnode';
|
|
12
11
|
import isWindow from './iswindow';
|
|
13
|
-
|
|
14
|
-
* Mixin that injects the DOM events API into its host. It provides the API
|
|
15
|
-
* compatible with {@link module:utils/emittermixin~EmitterMixin}.
|
|
16
|
-
*
|
|
17
|
-
* DOM emitter mixin is by default available in the {@link module:ui/view~View} class,
|
|
18
|
-
* but it can also be mixed into any other class:
|
|
19
|
-
*
|
|
20
|
-
* import mix from '../utils/mix.js';
|
|
21
|
-
* import DomEmitterMixin from '../utils/dom/emittermixin.js';
|
|
22
|
-
* import { Emitter } from '../utils/emittermixin.js';
|
|
23
|
-
*
|
|
24
|
-
* class SomeView extends DomEmitterMixin( Emitter ) {}
|
|
25
|
-
*
|
|
26
|
-
* const view = new SomeView();
|
|
27
|
-
* view.listenTo( domElement, ( evt, domEvt ) => {
|
|
28
|
-
* console.log( evt, domEvt );
|
|
29
|
-
* } );
|
|
30
|
-
*
|
|
31
|
-
* @mixin EmitterMixin
|
|
32
|
-
* @mixes module:utils/emittermixin~EmitterMixin
|
|
33
|
-
* @implements module:utils/dom/emittermixin~Emitter
|
|
34
|
-
*/
|
|
12
|
+
const defaultEmitterClass = DomEmitterMixin(EmitterMixin());
|
|
35
13
|
export default function DomEmitterMixin(base) {
|
|
14
|
+
if (!base) {
|
|
15
|
+
return defaultEmitterClass;
|
|
16
|
+
}
|
|
36
17
|
class Mixin extends base {
|
|
37
18
|
listenTo(emitter, event, callback, options = {}) {
|
|
38
19
|
// Check if emitter is an instance of DOM Node. If so, use corresponding ProxyEmitter (or create one if not existing).
|
|
@@ -46,7 +27,7 @@ export default function DomEmitterMixin(base) {
|
|
|
46
27
|
}
|
|
47
28
|
else {
|
|
48
29
|
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
49
|
-
|
|
30
|
+
super.listenTo(emitter, event, callback, options);
|
|
50
31
|
}
|
|
51
32
|
}
|
|
52
33
|
stopListening(emitter, event, callback) {
|
|
@@ -59,20 +40,19 @@ export default function DomEmitterMixin(base) {
|
|
|
59
40
|
}
|
|
60
41
|
else {
|
|
61
42
|
// Execute parent class method with Emitter (or ProxyEmitter) instance.
|
|
62
|
-
|
|
43
|
+
super.stopListening(emitter, event, callback);
|
|
63
44
|
}
|
|
64
45
|
}
|
|
65
46
|
/**
|
|
66
47
|
* Retrieves ProxyEmitter instance for given DOM Node residing in this Host and given options.
|
|
67
48
|
*
|
|
68
|
-
* @
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
|
|
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
|
|
72
52
|
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
73
|
-
* @param
|
|
53
|
+
* @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
|
|
74
54
|
* and prevents blocking browser's main thread by this event handler.
|
|
75
|
-
* @returns
|
|
55
|
+
* @returns ProxyEmitter instance bound to the DOM Node.
|
|
76
56
|
*/
|
|
77
57
|
_getProxyEmitter(node, options) {
|
|
78
58
|
return _getEmitterListenedTo(this, getProxyEmitterId(node, options));
|
|
@@ -80,9 +60,7 @@ export default function DomEmitterMixin(base) {
|
|
|
80
60
|
/**
|
|
81
61
|
* Retrieves all the ProxyEmitter instances for given DOM Node residing in this Host.
|
|
82
62
|
*
|
|
83
|
-
* @
|
|
84
|
-
* @param {Node|Window} node DOM Node of the ProxyEmitter.
|
|
85
|
-
* @returns {Array.<module:utils/dom/emittermixin~ProxyEmitter>}
|
|
63
|
+
* @param node DOM Node of the ProxyEmitter.
|
|
86
64
|
*/
|
|
87
65
|
_getAllProxyEmitters(node) {
|
|
88
66
|
return [
|
|
@@ -95,7 +73,6 @@ export default function DomEmitterMixin(base) {
|
|
|
95
73
|
}
|
|
96
74
|
return Mixin;
|
|
97
75
|
}
|
|
98
|
-
export const Emitter = DomEmitterMixin(BaseEmitter);
|
|
99
76
|
// Backward compatibility with `mix`
|
|
100
77
|
([
|
|
101
78
|
'_getProxyEmitter', '_getAllProxyEmitters',
|
|
@@ -103,11 +80,11 @@ export const Emitter = DomEmitterMixin(BaseEmitter);
|
|
|
103
80
|
'stopListening', 'fire', 'delegate', 'stopDelegating',
|
|
104
81
|
'_addEventListener', '_removeEventListener'
|
|
105
82
|
]).forEach(key => {
|
|
106
|
-
DomEmitterMixin[key] =
|
|
83
|
+
DomEmitterMixin[key] = defaultEmitterClass.prototype[key];
|
|
107
84
|
});
|
|
108
85
|
/**
|
|
109
86
|
* Creates a ProxyEmitter instance. Such an instance is a bridge between a DOM Node firing events
|
|
110
|
-
* and any Host listening to them. It is backwards compatible with {@link module:utils/emittermixin~
|
|
87
|
+
* and any Host listening to them. It is backwards compatible with {@link module:utils/emittermixin~Emitter#on}.
|
|
111
88
|
* There is a separate instance for each combination of modes (useCapture & usePassive). The mode is concatenated with
|
|
112
89
|
* UID stored in HTMLElement to give each instance unique identifier.
|
|
113
90
|
*
|
|
@@ -132,18 +109,14 @@ export const Emitter = DomEmitterMixin(BaseEmitter);
|
|
|
132
109
|
* | | click (DOM Event)
|
|
133
110
|
* +-----------------------------------------+
|
|
134
111
|
* fire( click, DOM Event )
|
|
135
|
-
*
|
|
136
|
-
* @mixes module:utils/emittermixin~EmitterMixin
|
|
137
|
-
* @implements module:utils/dom/emittermixin~Emitter
|
|
138
|
-
* @private
|
|
139
112
|
*/
|
|
140
|
-
class ProxyEmitter extends
|
|
113
|
+
class ProxyEmitter extends EmitterMixin() {
|
|
141
114
|
/**
|
|
142
|
-
* @param
|
|
143
|
-
* @param
|
|
144
|
-
* @param
|
|
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
|
|
145
118
|
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
146
|
-
* @param
|
|
119
|
+
* @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
|
|
147
120
|
* and prevents blocking browser's main thread by this event handler.
|
|
148
121
|
*/
|
|
149
122
|
constructor(node, options) {
|
|
@@ -162,10 +135,9 @@ class ProxyEmitter extends BaseEmitter {
|
|
|
162
135
|
* a corresponding Emitter event will also fire with DOM Event object as an argument.
|
|
163
136
|
*
|
|
164
137
|
* **Note**: This is automatically called by the
|
|
165
|
-
* {@link module:utils/emittermixin~
|
|
138
|
+
* {@link module:utils/emittermixin~Emitter#listenTo `Emitter#listenTo()`}.
|
|
166
139
|
*
|
|
167
|
-
* @
|
|
168
|
-
* @param {String} event The name of the event.
|
|
140
|
+
* @param event The name of the event.
|
|
169
141
|
*/
|
|
170
142
|
attach(event) {
|
|
171
143
|
// If the DOM Listener for given event already exist it is pointless
|
|
@@ -187,10 +159,9 @@ class ProxyEmitter extends BaseEmitter {
|
|
|
187
159
|
* Stops executing the callback on the given event.
|
|
188
160
|
*
|
|
189
161
|
* **Note**: This is automatically called by the
|
|
190
|
-
* {@link module:utils/emittermixin~
|
|
162
|
+
* {@link module:utils/emittermixin~Emitter#stopListening `Emitter#stopListening()`}.
|
|
191
163
|
*
|
|
192
|
-
* @
|
|
193
|
-
* @param {String} event The name of the event.
|
|
164
|
+
* @param event The name of the event.
|
|
194
165
|
*/
|
|
195
166
|
detach(event) {
|
|
196
167
|
let events;
|
|
@@ -204,29 +175,24 @@ class ProxyEmitter extends BaseEmitter {
|
|
|
204
175
|
/**
|
|
205
176
|
* Adds callback to emitter for given event.
|
|
206
177
|
*
|
|
207
|
-
* @
|
|
208
|
-
* @
|
|
209
|
-
* @param
|
|
210
|
-
* @param
|
|
211
|
-
* @param {Object} [options={}] Additional options.
|
|
212
|
-
* @param {module:utils/priorities~PriorityString} [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.
|
|
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.
|
|
215
182
|
*/
|
|
216
183
|
_addEventListener(event, callback, options) {
|
|
217
184
|
this.attach(event);
|
|
218
|
-
|
|
185
|
+
EmitterMixin().prototype._addEventListener.call(this, event, callback, options);
|
|
219
186
|
}
|
|
220
187
|
/**
|
|
221
188
|
* Removes callback from emitter for given event.
|
|
222
189
|
*
|
|
223
|
-
* @
|
|
224
|
-
* @
|
|
225
|
-
* @param
|
|
226
|
-
* @param {Function} callback The function to stop being called.
|
|
190
|
+
* @internal
|
|
191
|
+
* @param event The name of the event.
|
|
192
|
+
* @param callback The function to stop being called.
|
|
227
193
|
*/
|
|
228
194
|
_removeEventListener(event, callback) {
|
|
229
|
-
|
|
195
|
+
EmitterMixin().prototype._removeEventListener.call(this, event, callback);
|
|
230
196
|
this.detach(event);
|
|
231
197
|
}
|
|
232
198
|
/**
|
|
@@ -234,10 +200,8 @@ class ProxyEmitter extends BaseEmitter {
|
|
|
234
200
|
* is fired it will fire corresponding event on this ProxyEmitter.
|
|
235
201
|
* Note: A native DOM Event is passed as an argument.
|
|
236
202
|
*
|
|
237
|
-
* @
|
|
238
|
-
* @
|
|
239
|
-
* @param {String} event The name of the event.
|
|
240
|
-
* @returns {Function} The DOM listener callback.
|
|
203
|
+
* @param event The name of the event.
|
|
204
|
+
* @returns The DOM listener callback.
|
|
241
205
|
*/
|
|
242
206
|
_createDomListener(event) {
|
|
243
207
|
const domListener = (domEvt) => {
|
|
@@ -253,22 +217,17 @@ class ProxyEmitter extends BaseEmitter {
|
|
|
253
217
|
return domListener;
|
|
254
218
|
}
|
|
255
219
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
+
*/
|
|
261
225
|
function getNodeUID(node) {
|
|
262
226
|
return node['data-ck-expando'] || (node['data-ck-expando'] = uid());
|
|
263
227
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
//
|
|
268
|
-
// @private
|
|
269
|
-
// @param {Node} node
|
|
270
|
-
// @param {Object} options Additional options.
|
|
271
|
-
// @returns {String} ProxyEmitter id.
|
|
228
|
+
/**
|
|
229
|
+
* Gets id of the ProxyEmitter for the given node.
|
|
230
|
+
*/
|
|
272
231
|
function getProxyEmitterId(node, options) {
|
|
273
232
|
let id = getNodeUID(node);
|
|
274
233
|
for (const option of Object.keys(options).sort()) {
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Returns the closest scrollable ancestor of a DOM element.
|
|
10
|
+
*
|
|
11
|
+
* @param domElement DOM element.
|
|
12
|
+
* @returns First ancestor of `domElement` that is scrollable or null if such ancestor doesn't exist.
|
|
13
|
+
*/
|
|
14
|
+
export default function findClosestScrollableAncestor(domElement) {
|
|
15
|
+
let element = domElement.parentElement;
|
|
16
|
+
if (!element) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
while (element.tagName != 'BODY') {
|
|
20
|
+
const overflow = element.style.overflowY || global.window.getComputedStyle(element).overflowY;
|
|
21
|
+
if (overflow === 'auto' || overflow === 'scroll') {
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
element = element.parentElement;
|
|
25
|
+
if (!element) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return element;
|
|
30
|
+
}
|
package/src/dom/getancestors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/* globals Node */
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* appended to a `Document`, that `Document` will not be returned (algorithms operating on DOM tree care for `Document#documentElement`
|
|
13
13
|
* at most, which will be returned).
|
|
14
14
|
*
|
|
15
|
-
* @param
|
|
16
|
-
* @returns
|
|
15
|
+
* @param node DOM node.
|
|
16
|
+
* @returns Array of given `node` parents.
|
|
17
17
|
*/
|
|
18
18
|
export default function getAncestors(node) {
|
|
19
19
|
const nodes = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Returns an object containing CSS border widths of a specified HTML element.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @returns
|
|
11
|
+
* @param element An element which has CSS borders.
|
|
12
|
+
* @returns An object containing `top`, `left`, `right` and `bottom` properties
|
|
13
13
|
* with numerical values of the `border-[top,left,right,bottom]-width` CSS styles.
|
|
14
14
|
*/
|
|
15
15
|
export default function getBorderWidths(element) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -9,9 +9,9 @@ import getAncestors from './getancestors';
|
|
|
9
9
|
/**
|
|
10
10
|
* Searches and returns the lowest common ancestor of two given nodes.
|
|
11
11
|
*
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @returns
|
|
12
|
+
* @param nodeA First node.
|
|
13
|
+
* @param nodeB Second node.
|
|
14
|
+
* @returns Lowest common ancestor of both nodes or `null` if nodes do not have a common ancestor.
|
|
15
15
|
*/
|
|
16
16
|
export default function getCommonAncestor(nodeA, nodeB) {
|
|
17
17
|
const ancestorsA = getAncestors(nodeA);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/* globals HTMLTextAreaElement */
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* Gets data from a given source element.
|
|
11
11
|
*
|
|
12
|
-
* @param
|
|
13
|
-
* @returns
|
|
12
|
+
* @param el The element from which the data will be retrieved.
|
|
13
|
+
* @returns The data string.
|
|
14
14
|
*/
|
|
15
15
|
export default function getDataFromElement(el) {
|
|
16
16
|
if (el instanceof HTMLTextAreaElement) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -9,8 +9,7 @@ import global from './global';
|
|
|
9
9
|
/**
|
|
10
10
|
* For a given element, returns the nearest ancestor element which CSS position is not "static".
|
|
11
11
|
*
|
|
12
|
-
* @param
|
|
13
|
-
* @returns {HTMLElement|null}
|
|
12
|
+
* @param element The native DOM element to be checked.
|
|
14
13
|
*/
|
|
15
14
|
export default function getPositionedAncestor(element) {
|
|
16
15
|
if (!element || !element.parentNode) {
|
package/src/dom/global.js
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
-
/* globals window, document */
|
|
6
|
-
/**
|
|
7
|
-
* @module utils/dom/global
|
|
8
|
-
*/
|
|
9
5
|
/**
|
|
10
6
|
* A helper (module) giving an access to the global DOM objects such as `window` and
|
|
11
7
|
* `document`. Accessing these objects using this helper allows easy and bulletproof
|
|
12
8
|
* testing, i.e. stubbing native properties:
|
|
13
9
|
*
|
|
14
|
-
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { global } from 'ckeditor5/utils';
|
|
15
12
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
13
|
+
* // This stub will work for any code using global module.
|
|
14
|
+
* testUtils.sinon.stub( global, 'window', {
|
|
15
|
+
* innerWidth: 10000
|
|
16
|
+
* } );
|
|
20
17
|
*
|
|
21
|
-
*
|
|
18
|
+
* console.log( global.window.innerWidth );
|
|
19
|
+
* ```
|
|
22
20
|
*/
|
|
23
|
-
let global
|
|
21
|
+
let globalVar; // named globalVar instead of global: https://github.com/ckeditor/ckeditor5/issues/12971
|
|
24
22
|
// In some environments window and document API might not be available.
|
|
25
23
|
try {
|
|
26
|
-
|
|
24
|
+
globalVar = { window, document };
|
|
27
25
|
}
|
|
28
26
|
catch (e) {
|
|
29
27
|
// It's not possible to mock a window object to simulate lack of a window object without writing extremely convoluted code.
|
|
@@ -32,6 +30,6 @@ catch (e) {
|
|
|
32
30
|
// We only handle this so loading editor in environments without window and document doesn't fail.
|
|
33
31
|
// For better DX we shouldn't introduce mixed types and require developers to check the type manually.
|
|
34
32
|
// This module should not be used on purpose in any environment outside browser.
|
|
35
|
-
|
|
33
|
+
globalVar = { window: {}, document: {} };
|
|
36
34
|
}
|
|
37
|
-
export default
|
|
35
|
+
export default globalVar;
|
package/src/dom/indexof.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Returns index of the node in the parent element.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @returns
|
|
11
|
+
* @param node Node which index is tested.
|
|
12
|
+
* @returns Index of the node in the parent element. Returns 0 if node has no parent.
|
|
13
13
|
*/
|
|
14
14
|
export default function indexOf(node) {
|
|
15
15
|
let index = 0;
|
package/src/dom/insertat.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Inserts node to the parent at given index.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
11
|
+
* @param parentElement Parent element.
|
|
12
|
+
* @param index Insertions index.
|
|
13
|
+
* @param nodeToInsert Node to insert.
|
|
14
14
|
*/
|
|
15
15
|
export default function insertAt(parentElement, index, nodeToInsert) {
|
|
16
16
|
parentElement.insertBefore(nodeToInsert, parentElement.childNodes[index] || null);
|
package/src/dom/iscomment.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/* globals Node */
|
|
@@ -8,9 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
10
|
* Checks whether the object is a native DOM Comment node.
|
|
11
|
-
*
|
|
12
|
-
* @param {*} obj
|
|
13
|
-
* @returns {Boolean}
|
|
14
11
|
*/
|
|
15
12
|
export default function isComment(obj) {
|
|
16
13
|
return obj && obj.nodeType === Node.COMMENT_NODE;
|
package/src/dom/isnode.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Checks if the object is a native DOM Node.
|
|
10
|
-
*
|
|
11
|
-
* @param {*} obj
|
|
12
|
-
* @returns {Boolean}
|
|
13
10
|
*/
|
|
14
11
|
export default function isNode(obj) {
|
|
15
12
|
if (obj) {
|
package/src/dom/isrange.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Checks if the object is a native DOM Range.
|
|
10
|
-
*
|
|
11
|
-
* @param {*} obj
|
|
12
|
-
* @returns {Boolean}
|
|
13
10
|
*/
|
|
14
11
|
export default function isRange(obj) {
|
|
15
12
|
return Object.prototype.toString.apply(obj) == '[object Range]';
|
package/src/dom/istext.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
/**
|
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Checks if the object is a native DOM Text node.
|
|
10
|
-
*
|
|
11
|
-
* @param {*} obj
|
|
12
|
-
* @returns {Boolean}
|
|
13
10
|
*/
|
|
14
11
|
export default function isText(obj) {
|
|
15
12
|
return Object.prototype.toString.call(obj) == '[object Text]';
|