@ckeditor/ckeditor5-utils 47.6.1 → 48.0.0-alpha.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 (154) hide show
  1. package/LICENSE.md +1 -1
  2. package/{src → dist}/dom/global.d.ts +1 -1
  3. package/{src → dist}/dom/rect.d.ts +8 -0
  4. package/dist/index.css +3 -0
  5. package/dist/index.css.map +1 -0
  6. package/dist/index.js +24 -5
  7. package/dist/index.js.map +1 -1
  8. package/{src → dist}/version.d.ts +1 -1
  9. package/package.json +20 -38
  10. package/src/abortabledebounce.js +0 -22
  11. package/src/areconnectedthroughproperties.js +0 -71
  12. package/src/ckeditorerror.js +0 -187
  13. package/src/collection.js +0 -620
  14. package/src/collectstylesheets.js +0 -52
  15. package/src/comparearrays.js +0 -47
  16. package/src/config.js +0 -167
  17. package/src/count.js +0 -25
  18. package/src/crc32.js +0 -61
  19. package/src/decodelicensekey.js +0 -30
  20. package/src/delay.js +0 -25
  21. package/src/diff.js +0 -115
  22. package/src/difftochanges.js +0 -79
  23. package/src/dom/createelement.js +0 -40
  24. package/src/dom/emittermixin.js +0 -237
  25. package/src/dom/findclosestscrollableancestor.js +0 -31
  26. package/src/dom/getancestors.js +0 -26
  27. package/src/dom/getborderwidths.js +0 -24
  28. package/src/dom/getcommonancestor.js +0 -25
  29. package/src/dom/getdatafromelement.js +0 -19
  30. package/src/dom/getpositionedancestor.js +0 -22
  31. package/src/dom/getrangefrommouseevent.js +0 -33
  32. package/src/dom/getvisualviewportoffset.js +0 -21
  33. package/src/dom/global.js +0 -35
  34. package/src/dom/indexof.js +0 -21
  35. package/src/dom/insertat.js +0 -17
  36. package/src/dom/iscomment.js +0 -13
  37. package/src/dom/isnode.js +0 -21
  38. package/src/dom/isrange.js +0 -13
  39. package/src/dom/istext.js +0 -13
  40. package/src/dom/isvalidattributename.js +0 -22
  41. package/src/dom/isvisible.js +0 -30
  42. package/src/dom/iswindow.js +0 -22
  43. package/src/dom/position.js +0 -322
  44. package/src/dom/rect.js +0 -498
  45. package/src/dom/remove.js +0 -18
  46. package/src/dom/resizeobserver.js +0 -134
  47. package/src/dom/scroll.js +0 -406
  48. package/src/dom/setdatainelement.js +0 -19
  49. package/src/dom/tounit.js +0 -16
  50. package/src/elementreplacer.js +0 -47
  51. package/src/emittermixin.js +0 -443
  52. package/src/env.js +0 -158
  53. package/src/eventinfo.js +0 -63
  54. package/src/fastdiff.js +0 -248
  55. package/src/first.js +0 -17
  56. package/src/focustracker.js +0 -329
  57. package/src/formathtml.js +0 -164
  58. package/src/index.js +0 -78
  59. package/src/inserttopriorityarray.js +0 -28
  60. package/src/isfeatureblockedbylicensekey.js +0 -17
  61. package/src/isiterable.js +0 -16
  62. package/src/keyboard.js +0 -256
  63. package/src/keystrokehandler.js +0 -126
  64. package/src/language.js +0 -21
  65. package/src/legacyerrors.js +0 -18
  66. package/src/locale.js +0 -135
  67. package/src/mapsequal.js +0 -27
  68. package/src/mix.js +0 -5
  69. package/src/nth.js +0 -24
  70. package/src/objecttomap.js +0 -27
  71. package/src/observablemixin.js +0 -575
  72. package/src/parsebase64encodedobject.js +0 -22
  73. package/src/priorities.js +0 -22
  74. package/src/retry.js +0 -48
  75. package/src/splicearray.js +0 -37
  76. package/src/spy.js +0 -21
  77. package/src/toarray.js +0 -7
  78. package/src/tomap.js +0 -29
  79. package/src/translation-service.js +0 -209
  80. package/src/uid.js +0 -45
  81. package/src/unicode.js +0 -85
  82. package/src/version.js +0 -177
  83. package/src/wait.js +0 -29
  84. /package/{src → dist}/abortabledebounce.d.ts +0 -0
  85. /package/{src → dist}/areconnectedthroughproperties.d.ts +0 -0
  86. /package/{src → dist}/ckeditorerror.d.ts +0 -0
  87. /package/{src → dist}/collection.d.ts +0 -0
  88. /package/{src → dist}/collectstylesheets.d.ts +0 -0
  89. /package/{src → dist}/comparearrays.d.ts +0 -0
  90. /package/{src → dist}/config.d.ts +0 -0
  91. /package/{src → dist}/count.d.ts +0 -0
  92. /package/{src → dist}/crc32.d.ts +0 -0
  93. /package/{src → dist}/decodelicensekey.d.ts +0 -0
  94. /package/{src → dist}/delay.d.ts +0 -0
  95. /package/{src → dist}/diff.d.ts +0 -0
  96. /package/{src → dist}/difftochanges.d.ts +0 -0
  97. /package/{src → dist}/dom/createelement.d.ts +0 -0
  98. /package/{src → dist}/dom/emittermixin.d.ts +0 -0
  99. /package/{src → dist}/dom/findclosestscrollableancestor.d.ts +0 -0
  100. /package/{src → dist}/dom/getancestors.d.ts +0 -0
  101. /package/{src → dist}/dom/getborderwidths.d.ts +0 -0
  102. /package/{src → dist}/dom/getcommonancestor.d.ts +0 -0
  103. /package/{src → dist}/dom/getdatafromelement.d.ts +0 -0
  104. /package/{src → dist}/dom/getpositionedancestor.d.ts +0 -0
  105. /package/{src → dist}/dom/getrangefrommouseevent.d.ts +0 -0
  106. /package/{src → dist}/dom/getvisualviewportoffset.d.ts +0 -0
  107. /package/{src → dist}/dom/indexof.d.ts +0 -0
  108. /package/{src → dist}/dom/insertat.d.ts +0 -0
  109. /package/{src → dist}/dom/iscomment.d.ts +0 -0
  110. /package/{src → dist}/dom/isnode.d.ts +0 -0
  111. /package/{src → dist}/dom/isrange.d.ts +0 -0
  112. /package/{src → dist}/dom/istext.d.ts +0 -0
  113. /package/{src → dist}/dom/isvalidattributename.d.ts +0 -0
  114. /package/{src → dist}/dom/isvisible.d.ts +0 -0
  115. /package/{src → dist}/dom/iswindow.d.ts +0 -0
  116. /package/{src → dist}/dom/position.d.ts +0 -0
  117. /package/{src → dist}/dom/remove.d.ts +0 -0
  118. /package/{src → dist}/dom/resizeobserver.d.ts +0 -0
  119. /package/{src → dist}/dom/scroll.d.ts +0 -0
  120. /package/{src → dist}/dom/setdatainelement.d.ts +0 -0
  121. /package/{src → dist}/dom/tounit.d.ts +0 -0
  122. /package/{src → dist}/elementreplacer.d.ts +0 -0
  123. /package/{src → dist}/emittermixin.d.ts +0 -0
  124. /package/{src → dist}/env.d.ts +0 -0
  125. /package/{src → dist}/eventinfo.d.ts +0 -0
  126. /package/{src → dist}/fastdiff.d.ts +0 -0
  127. /package/{src → dist}/first.d.ts +0 -0
  128. /package/{src → dist}/focustracker.d.ts +0 -0
  129. /package/{src → dist}/formathtml.d.ts +0 -0
  130. /package/{src → dist}/index.d.ts +0 -0
  131. /package/{src → dist}/inserttopriorityarray.d.ts +0 -0
  132. /package/{src → dist}/isfeatureblockedbylicensekey.d.ts +0 -0
  133. /package/{src → dist}/isiterable.d.ts +0 -0
  134. /package/{src → dist}/keyboard.d.ts +0 -0
  135. /package/{src → dist}/keystrokehandler.d.ts +0 -0
  136. /package/{src → dist}/language.d.ts +0 -0
  137. /package/{src → dist}/legacyerrors.d.ts +0 -0
  138. /package/{src → dist}/locale.d.ts +0 -0
  139. /package/{src → dist}/mapsequal.d.ts +0 -0
  140. /package/{src → dist}/mix.d.ts +0 -0
  141. /package/{src → dist}/nth.d.ts +0 -0
  142. /package/{src → dist}/objecttomap.d.ts +0 -0
  143. /package/{src → dist}/observablemixin.d.ts +0 -0
  144. /package/{src → dist}/parsebase64encodedobject.d.ts +0 -0
  145. /package/{src → dist}/priorities.d.ts +0 -0
  146. /package/{src → dist}/retry.d.ts +0 -0
  147. /package/{src → dist}/splicearray.d.ts +0 -0
  148. /package/{src → dist}/spy.d.ts +0 -0
  149. /package/{src → dist}/toarray.d.ts +0 -0
  150. /package/{src → dist}/tomap.d.ts +0 -0
  151. /package/{src → dist}/translation-service.d.ts +0 -0
  152. /package/{src → dist}/uid.d.ts +0 -0
  153. /package/{src → dist}/unicode.d.ts +0 -0
  154. /package/{src → dist}/wait.d.ts +0 -0
@@ -1,443 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module utils/emittermixin
7
- */
8
- import { EventInfo } from './eventinfo.js';
9
- import { uid } from './uid.js';
10
- import { priorities } from './priorities.js';
11
- import { insertToPriorityArray } from './inserttopriorityarray.js';
12
- // To check if component is loaded more than once.
13
- import './version.js';
14
- import { CKEditorError } from './ckeditorerror.js';
15
- const _listeningTo = Symbol('listeningTo');
16
- const _emitterId = Symbol('emitterId');
17
- const _delegations = Symbol('delegations');
18
- const defaultEmitterClass = /* #__PURE__ */ EmitterMixin(Object);
19
- export function EmitterMixin(base) {
20
- if (!base) {
21
- return defaultEmitterClass;
22
- }
23
- class Mixin extends base {
24
- on(event, callback, options) {
25
- this.listenTo(this, event, callback, options);
26
- }
27
- once(event, callback, options) {
28
- let wasFired = false;
29
- const onceCallback = (event, ...args) => {
30
- // Ensure the callback is called only once even if the callback itself leads to re-firing the event
31
- // (which would call the callback again).
32
- if (!wasFired) {
33
- wasFired = true;
34
- // Go off() at the first call.
35
- event.off();
36
- // Go with the original callback.
37
- callback.call(this, event, ...args);
38
- }
39
- };
40
- // Make a similar on() call, simply replacing the callback.
41
- this.listenTo(this, event, onceCallback, options);
42
- }
43
- off(event, callback) {
44
- this.stopListening(this, event, callback);
45
- }
46
- listenTo(emitter, event, callback, options = {}) {
47
- let emitterInfo, eventCallbacks;
48
- // _listeningTo contains a list of emitters that this object is listening to.
49
- // This list has the following format:
50
- //
51
- // _listeningTo: {
52
- // emitterId: {
53
- // emitter: emitter,
54
- // callbacks: {
55
- // event1: [ callback1, callback2, ... ]
56
- // ....
57
- // }
58
- // },
59
- // ...
60
- // }
61
- if (!this[_listeningTo]) {
62
- this[_listeningTo] = {};
63
- }
64
- const emitters = this[_listeningTo];
65
- if (!_getEmitterId(emitter)) {
66
- _setEmitterId(emitter);
67
- }
68
- const emitterId = _getEmitterId(emitter);
69
- if (!(emitterInfo = emitters[emitterId])) {
70
- emitterInfo = emitters[emitterId] = {
71
- emitter,
72
- callbacks: {}
73
- };
74
- }
75
- if (!(eventCallbacks = emitterInfo.callbacks[event])) {
76
- eventCallbacks = emitterInfo.callbacks[event] = [];
77
- }
78
- eventCallbacks.push(callback);
79
- // Finally register the callback to the event.
80
- addEventListener(this, emitter, event, callback, options);
81
- }
82
- stopListening(emitter, event, callback) {
83
- const emitters = this[_listeningTo];
84
- let emitterId = emitter && _getEmitterId(emitter);
85
- const emitterInfo = (emitters && emitterId) ? emitters[emitterId] : undefined;
86
- const eventCallbacks = (emitterInfo && event) ? emitterInfo.callbacks[event] : undefined;
87
- // Stop if nothing has been listened.
88
- if (!emitters || (emitter && !emitterInfo) || (event && !eventCallbacks)) {
89
- return;
90
- }
91
- // All params provided. off() that single callback.
92
- if (callback) {
93
- removeEventListener(this, emitter, event, callback);
94
- // We must remove callbacks as well in order to prevent memory leaks.
95
- // See https://github.com/ckeditor/ckeditor5/pull/8480
96
- const index = eventCallbacks.indexOf(callback);
97
- if (index !== -1) {
98
- if (eventCallbacks.length === 1) {
99
- delete emitterInfo.callbacks[event];
100
- }
101
- else {
102
- removeEventListener(this, emitter, event, callback);
103
- }
104
- }
105
- }
106
- // Only `emitter` and `event` provided. off() all callbacks for that event.
107
- else if (eventCallbacks) {
108
- while ((callback = eventCallbacks.pop())) {
109
- removeEventListener(this, emitter, event, callback);
110
- }
111
- delete emitterInfo.callbacks[event];
112
- }
113
- // Only `emitter` provided. off() all events for that emitter.
114
- else if (emitterInfo) {
115
- for (event in emitterInfo.callbacks) {
116
- this.stopListening(emitter, event);
117
- }
118
- delete emitters[emitterId];
119
- }
120
- // No params provided. off() all emitters.
121
- else {
122
- for (emitterId in emitters) {
123
- this.stopListening(emitters[emitterId].emitter);
124
- }
125
- delete this[_listeningTo];
126
- }
127
- }
128
- fire(eventOrInfo, ...args) {
129
- try {
130
- const eventInfo = eventOrInfo instanceof EventInfo ? eventOrInfo : new EventInfo(this, eventOrInfo);
131
- const event = eventInfo.name;
132
- let callbacks = getCallbacksForEvent(this, event);
133
- // Record that the event passed this emitter on its path.
134
- eventInfo.path.push(this);
135
- // Handle event listener callbacks first.
136
- if (callbacks) {
137
- // Copying callbacks array is the easiest and most secure way of preventing infinite loops, when event callbacks
138
- // are added while processing other callbacks. Previous solution involved adding counters (unique ids) but
139
- // failed if callbacks were added to the queue before currently processed callback.
140
- // If this proves to be too inefficient, another method is to change `.on()` so callbacks are stored if same
141
- // event is currently processed. Then, `.fire()` at the end, would have to add all stored events.
142
- callbacks = callbacks.slice();
143
- for (let i = 0; i < callbacks.length; i++) {
144
- const fn = callbacks[i].callback;
145
- fn.call(this, eventInfo, ...args);
146
- // Remove the callback from future requests if off() has been called.
147
- if (eventInfo.off.called) {
148
- // Remove the called mark for the next calls.
149
- delete eventInfo.off.called;
150
- this._removeEventListener(event, fn);
151
- }
152
- // Do not execute next callbacks if stop() was called.
153
- if (eventInfo.stop.called) {
154
- break;
155
- }
156
- }
157
- }
158
- // Delegate event to other emitters if needed.
159
- const delegations = this[_delegations];
160
- if (delegations) {
161
- const destinations = delegations.get(event);
162
- const passAllDestinations = delegations.get('*');
163
- if (destinations) {
164
- fireDelegatedEvents(destinations, eventInfo, args);
165
- }
166
- if (passAllDestinations) {
167
- fireDelegatedEvents(passAllDestinations, eventInfo, args);
168
- }
169
- }
170
- return eventInfo.return;
171
- }
172
- catch (err) {
173
- // @if CK_DEBUG // throw err;
174
- /* istanbul ignore next -- @preserve */
175
- CKEditorError.rethrowUnexpectedError(err, this);
176
- }
177
- }
178
- delegate(...events) {
179
- return {
180
- to: (emitter, nameOrFunction) => {
181
- if (!this[_delegations]) {
182
- this[_delegations] = new Map();
183
- }
184
- // Originally there was a for..of loop which unfortunately caused an error in Babel that didn't allow
185
- // build an application. See: https://github.com/ckeditor/ckeditor5-react/issues/40.
186
- events.forEach(eventName => {
187
- const destinations = this[_delegations].get(eventName);
188
- if (!destinations) {
189
- this[_delegations].set(eventName, new Map([[emitter, nameOrFunction]]));
190
- }
191
- else {
192
- destinations.set(emitter, nameOrFunction);
193
- }
194
- });
195
- }
196
- };
197
- }
198
- stopDelegating(event, emitter) {
199
- if (!this[_delegations]) {
200
- return;
201
- }
202
- if (!event) {
203
- this[_delegations].clear();
204
- }
205
- else if (!emitter) {
206
- this[_delegations].delete(event);
207
- }
208
- else {
209
- const destinations = this[_delegations].get(event);
210
- if (destinations) {
211
- destinations.delete(emitter);
212
- }
213
- }
214
- }
215
- _addEventListener(event, callback, options) {
216
- createEventNamespace(this, event);
217
- const lists = getCallbacksListsForNamespace(this, event);
218
- const priority = priorities.get(options.priority);
219
- const callbackDefinition = {
220
- callback,
221
- priority
222
- };
223
- // Add the callback to all callbacks list.
224
- for (const callbacks of lists) {
225
- // Add the callback to the list in the right priority position.
226
- insertToPriorityArray(callbacks, callbackDefinition);
227
- }
228
- }
229
- _removeEventListener(event, callback) {
230
- const lists = getCallbacksListsForNamespace(this, event);
231
- for (const callbacks of lists) {
232
- for (let i = 0; i < callbacks.length; i++) {
233
- if (callbacks[i].callback == callback) {
234
- // Remove the callback from the list (fixing the next index).
235
- callbacks.splice(i, 1);
236
- i--;
237
- }
238
- }
239
- }
240
- }
241
- }
242
- return Mixin;
243
- }
244
- /**
245
- * Checks if `listeningEmitter` listens to an emitter with given `listenedToEmitterId` and if so, returns that emitter.
246
- * If not, returns `null`.
247
- *
248
- * @internal
249
- * @param listeningEmitter An emitter that listens.
250
- * @param listenedToEmitterId Unique emitter id of emitter listened to.
251
- */
252
- export function _getEmitterListenedTo(listeningEmitter, listenedToEmitterId) {
253
- const listeningTo = listeningEmitter[_listeningTo];
254
- if (listeningTo && listeningTo[listenedToEmitterId]) {
255
- return listeningTo[listenedToEmitterId].emitter;
256
- }
257
- return null;
258
- }
259
- /**
260
- * Sets emitter's unique id.
261
- *
262
- * **Note:** `_emitterId` can be set only once.
263
- *
264
- * @internal
265
- * @param emitter An emitter for which id will be set.
266
- * @param id Unique id to set. If not passed, random unique id will be set.
267
- */
268
- export function _setEmitterId(emitter, id) {
269
- if (!emitter[_emitterId]) {
270
- emitter[_emitterId] = id || uid();
271
- }
272
- }
273
- /**
274
- * Returns emitter's unique id.
275
- *
276
- * @internal
277
- * @param emitter An emitter which id will be returned.
278
- */
279
- export function _getEmitterId(emitter) {
280
- return emitter[_emitterId];
281
- }
282
- /**
283
- * Gets the internal `_events` property of the given object.
284
- * `_events` property store all lists with callbacks for registered event names.
285
- * If there were no events registered on the object, empty `_events` object is created.
286
- */
287
- function getEvents(source) {
288
- if (!source._events) {
289
- Object.defineProperty(source, '_events', {
290
- value: {}
291
- });
292
- }
293
- return source._events;
294
- }
295
- /**
296
- * Creates event node for generic-specific events relation architecture.
297
- */
298
- function makeEventNode() {
299
- return {
300
- callbacks: [],
301
- childEvents: []
302
- };
303
- }
304
- /**
305
- * Creates an architecture for generic-specific events relation.
306
- * If needed, creates all events for given eventName, i.e. if the first registered event
307
- * is foo:bar:abc, it will create foo:bar:abc, foo:bar and foo event and tie them together.
308
- * It also copies callbacks from more generic events to more specific events when
309
- * specific events are created.
310
- */
311
- function createEventNamespace(source, eventName) {
312
- const events = getEvents(source);
313
- // First, check if the event we want to add to the structure already exists.
314
- if (events[eventName]) {
315
- // If it exists, we don't have to do anything.
316
- return;
317
- }
318
- // In other case, we have to create the structure for the event.
319
- // Note, that we might need to create intermediate events too.
320
- // I.e. if foo:bar:abc is being registered and we only have foo in the structure,
321
- // we need to also register foo:bar.
322
- // Currently processed event name.
323
- let name = eventName;
324
- // Name of the event that is a child event for currently processed event.
325
- let childEventName = null;
326
- // Array containing all newly created specific events.
327
- const newEventNodes = [];
328
- // While loop can't check for ':' index because we have to handle generic events too.
329
- // In each loop, we truncate event name, going from the most specific name to the generic one.
330
- // I.e. foo:bar:abc -> foo:bar -> foo.
331
- while (name !== '') {
332
- if (events[name]) {
333
- // If the currently processed event name is already registered, we can be sure
334
- // that it already has all the structure created, so we can break the loop here
335
- // as no more events need to be registered.
336
- break;
337
- }
338
- // If this event is not yet registered, create a new object for it.
339
- events[name] = makeEventNode();
340
- // Add it to the array with newly created events.
341
- newEventNodes.push(events[name]);
342
- // Add previously processed event name as a child of this event.
343
- if (childEventName) {
344
- events[name].childEvents.push(childEventName);
345
- }
346
- childEventName = name;
347
- // If `.lastIndexOf()` returns -1, `.substr()` will return '' which will break the loop.
348
- name = name.substr(0, name.lastIndexOf(':'));
349
- }
350
- if (name !== '') {
351
- // If name is not empty, we found an already registered event that was a parent of the
352
- // event we wanted to register.
353
- // Copy that event's callbacks to newly registered events.
354
- for (const node of newEventNodes) {
355
- node.callbacks = events[name].callbacks.slice();
356
- }
357
- // Add last newly created event to the already registered event.
358
- events[name].childEvents.push(childEventName);
359
- }
360
- }
361
- /**
362
- * Gets an array containing callbacks list for a given event and it's more specific events.
363
- * I.e. if given event is foo:bar and there is also foo:bar:abc event registered, this will
364
- * return callback list of foo:bar and foo:bar:abc (but not foo).
365
- */
366
- function getCallbacksListsForNamespace(source, eventName) {
367
- const eventNode = getEvents(source)[eventName];
368
- if (!eventNode) {
369
- return [];
370
- }
371
- let callbacksLists = [eventNode.callbacks];
372
- for (let i = 0; i < eventNode.childEvents.length; i++) {
373
- const childCallbacksLists = getCallbacksListsForNamespace(source, eventNode.childEvents[i]);
374
- callbacksLists = callbacksLists.concat(childCallbacksLists);
375
- }
376
- return callbacksLists;
377
- }
378
- /**
379
- * Get the list of callbacks for a given event, but only if there any callbacks have been registered.
380
- * If there are no callbacks registered for given event, it checks if this is a specific event and looks
381
- * for callbacks for it's more generic version.
382
- */
383
- function getCallbacksForEvent(source, eventName) {
384
- if (!source._events) {
385
- return null;
386
- }
387
- let currentEventName = eventName;
388
- do {
389
- const event = source._events[currentEventName];
390
- if (event && event.callbacks && event.callbacks.length) {
391
- return event.callbacks;
392
- }
393
- const colonIndex = currentEventName.lastIndexOf(':');
394
- currentEventName = colonIndex > -1 ? currentEventName.substring(0, colonIndex) : '';
395
- } while (currentEventName);
396
- return null;
397
- }
398
- /**
399
- * Fires delegated events for given map of destinations.
400
- *
401
- * @param destinations A map containing `[ {@link module:utils/emittermixin~Emitter}, "event name" ]` pair destinations.
402
- * @param eventInfo The original event info object.
403
- * @param fireArgs Arguments the original event was fired with.
404
- */
405
- function fireDelegatedEvents(destinations, eventInfo, fireArgs) {
406
- for (let [emitter, name] of destinations) {
407
- if (!name) {
408
- name = eventInfo.name;
409
- }
410
- else if (typeof name == 'function') {
411
- name = name(eventInfo.name);
412
- }
413
- const delegatedInfo = new EventInfo(eventInfo.source, name);
414
- delegatedInfo.path = [...eventInfo.path];
415
- emitter.fire(delegatedInfo, ...fireArgs);
416
- }
417
- }
418
- /**
419
- * Helper for registering event callback on the emitter.
420
- */
421
- function addEventListener(listener, emitter, event, callback, options) {
422
- if (emitter._addEventListener) {
423
- emitter._addEventListener(event, callback, options);
424
- }
425
- else {
426
- // Allow listening on objects that do not implement Emitter interface.
427
- // This is needed in some tests that are using mocks instead of the real objects with EmitterMixin mixed.
428
- (listener._addEventListener).call(emitter, event, callback, options);
429
- }
430
- }
431
- /**
432
- * Helper for removing event callback from the emitter.
433
- */
434
- function removeEventListener(listener, emitter, event, callback) {
435
- if (emitter._removeEventListener) {
436
- emitter._removeEventListener(event, callback);
437
- }
438
- else {
439
- // Allow listening on objects that do not implement Emitter interface.
440
- // This is needed in some tests that are using mocks instead of the real objects with EmitterMixin mixed.
441
- listener._removeEventListener.call(emitter, event, callback);
442
- }
443
- }
package/src/env.js DELETED
@@ -1,158 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module utils/env
7
- */
8
- import { global } from './dom/global.js';
9
- /**
10
- * Safely returns `userAgent` from browser's navigator API in a lower case.
11
- * If navigator API is not available it will return an empty string.
12
- *
13
- * @internal
14
- */
15
- export function getUserAgent() {
16
- // In some environments navigator API might not be available.
17
- try {
18
- return navigator.userAgent.toLowerCase();
19
- }
20
- catch {
21
- return '';
22
- }
23
- }
24
- const userAgent = /* #__PURE__ */ getUserAgent();
25
- /**
26
- * A namespace containing environment and browser information.
27
- */
28
- export const env = {
29
- isMac: /* #__PURE__ */ isMac(userAgent),
30
- isWindows: /* #__PURE__ */ isWindows(userAgent),
31
- isGecko: /* #__PURE__ */ isGecko(userAgent),
32
- isSafari: /* #__PURE__ */ isSafari(userAgent),
33
- isiOS: /* #__PURE__ */ isiOS(userAgent),
34
- isAndroid: /* #__PURE__ */ isAndroid(userAgent),
35
- isBlink: /* #__PURE__ */ isBlink(userAgent),
36
- get isMediaForcedColors() {
37
- return isMediaForcedColors();
38
- },
39
- get isMotionReduced() {
40
- return isMotionReduced();
41
- },
42
- features: {
43
- isRegExpUnicodePropertySupported: /* #__PURE__ */ isRegExpUnicodePropertySupported()
44
- }
45
- };
46
- /**
47
- * Checks if User Agent represented by the string is running on Macintosh.
48
- *
49
- * @internal
50
- * @param userAgent **Lowercase** `navigator.userAgent` string.
51
- * @returns Whether User Agent is running on Macintosh or not.
52
- */
53
- export function isMac(userAgent) {
54
- return userAgent.indexOf('macintosh') > -1;
55
- }
56
- /**
57
- * Checks if User Agent represented by the string is running on Windows.
58
- *
59
- * @internal
60
- * @param userAgent **Lowercase** `navigator.userAgent` string.
61
- * @returns Whether User Agent is running on Windows or not.
62
- */
63
- export function isWindows(userAgent) {
64
- return userAgent.indexOf('windows') > -1;
65
- }
66
- /**
67
- * Checks if User Agent represented by the string is Firefox (Gecko).
68
- *
69
- * @internal
70
- * @param userAgent **Lowercase** `navigator.userAgent` string.
71
- * @returns Whether User Agent is Firefox or not.
72
- */
73
- export function isGecko(userAgent) {
74
- return !!userAgent.match(/gecko\/\d+/);
75
- }
76
- /**
77
- * Checks if User Agent represented by the string is Safari.
78
- *
79
- * @internal
80
- * @param userAgent **Lowercase** `navigator.userAgent` string.
81
- * @returns Whether User Agent is Safari or not.
82
- */
83
- export function isSafari(userAgent) {
84
- return userAgent.indexOf(' applewebkit/') > -1 && userAgent.indexOf('chrome') === -1;
85
- }
86
- /**
87
- * Checks if User Agent represented by the string is running in iOS.
88
- *
89
- * @internal
90
- * @param userAgent **Lowercase** `navigator.userAgent` string.
91
- * @returns Whether User Agent is running in iOS or not.
92
- */
93
- export function isiOS(userAgent) {
94
- // "Request mobile site" || "Request desktop site".
95
- return !!userAgent.match(/iphone|ipad/i) || (isMac(userAgent) && navigator.maxTouchPoints > 0);
96
- }
97
- /**
98
- * Checks if User Agent represented by the string is Android mobile device.
99
- *
100
- * @internal
101
- * @param userAgent **Lowercase** `navigator.userAgent` string.
102
- * @returns Whether User Agent is Safari or not.
103
- */
104
- export function isAndroid(userAgent) {
105
- return userAgent.indexOf('android') > -1;
106
- }
107
- /**
108
- * Checks if User Agent represented by the string is Blink engine.
109
- *
110
- * @internal
111
- * @param userAgent **Lowercase** `navigator.userAgent` string.
112
- * @returns Whether User Agent is Blink engine or not.
113
- */
114
- export function isBlink(userAgent) {
115
- // The Edge browser before switching to the Blink engine used to report itself as Chrome (and "Edge/")
116
- // but after switching to the Blink it replaced "Edge/" with "Edg/".
117
- return userAgent.indexOf('chrome/') > -1 && userAgent.indexOf('edge/') < 0;
118
- }
119
- /**
120
- * Checks if the current environment supports ES2018 Unicode properties like `\p{P}` or `\p{L}`.
121
- * More information about unicode properties might be found
122
- * [in Unicode Standard Annex #44](https://www.unicode.org/reports/tr44/#GC_Values_Table).
123
- *
124
- * @internal
125
- */
126
- export function isRegExpUnicodePropertySupported() {
127
- let isSupported = false;
128
- // Feature detection for Unicode properties. Added in ES2018. Currently Firefox does not support it.
129
- // See https://github.com/ckeditor/ckeditor5-mention/issues/44#issuecomment-487002174.
130
- try {
131
- // Usage of regular expression literal cause error during build (ckeditor/ckeditor5-dev#534).
132
- isSupported = 'ć'.search(new RegExp('[\\p{L}]', 'u')) === 0;
133
- }
134
- catch {
135
- // Firefox throws a SyntaxError when the group is unsupported.
136
- }
137
- return isSupported;
138
- }
139
- /**
140
- * Checks if the user agent has enabled a forced colors mode (e.g. Windows High Contrast mode).
141
- *
142
- * Returns `false` in environments where `window` global object is not available.
143
- *
144
- * @internal
145
- */
146
- export function isMediaForcedColors() {
147
- return global.window.matchMedia ? global.window.matchMedia('(forced-colors: active)').matches : false;
148
- }
149
- /**
150
- * Checks if the user enabled "prefers reduced motion" setting in browser.
151
- *
152
- * Returns `false` in environments where `window` global object is not available.
153
- *
154
- * @internal
155
- */
156
- export function isMotionReduced() {
157
- return global.window.matchMedia ? global.window.matchMedia('(prefers-reduced-motion)').matches : false;
158
- }
package/src/eventinfo.js DELETED
@@ -1,63 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module utils/eventinfo
7
- */
8
- import { spy } from './spy.js';
9
- /**
10
- * The event object passed to event callbacks. It is used to provide information about the event as well as a tool to
11
- * manipulate it.
12
- */
13
- export class EventInfo {
14
- /**
15
- * The object that fired the event.
16
- */
17
- source;
18
- /**
19
- * The event name.
20
- */
21
- name;
22
- /**
23
- * Path this event has followed. See {@link module:utils/emittermixin~Emitter#delegate}.
24
- */
25
- path;
26
- /**
27
- * Stops the event emitter to call further callbacks for this event interaction.
28
- */
29
- stop;
30
- /**
31
- * Removes the current callback from future interactions of this event.
32
- */
33
- off;
34
- /**
35
- * The value which will be returned by {@link module:utils/emittermixin~Emitter#fire}.
36
- *
37
- * It's `undefined` by default and can be changed by an event listener:
38
- *
39
- * ```ts
40
- * dataController.fire( 'getSelectedContent', ( evt ) => {
41
- * // This listener will make `dataController.fire( 'getSelectedContent' )`
42
- * // always return an empty DocumentFragment.
43
- * evt.return = new DocumentFragment();
44
- *
45
- * // Make sure no other listeners are executed.
46
- * evt.stop();
47
- * } );
48
- * ```
49
- */
50
- return;
51
- /**
52
- * @param source The emitter.
53
- * @param name The event name.
54
- */
55
- constructor(source, name) {
56
- this.source = source;
57
- this.name = name;
58
- this.path = [];
59
- // The following methods are defined in the constructor because they must be re-created per instance.
60
- this.stop = spy();
61
- this.off = spy();
62
- }
63
- }