@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,575 +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
- /* eslint-disable @typescript-eslint/unified-signatures */
6
- /**
7
- * @module utils/observablemixin
8
- */
9
- import { EmitterMixin } from './emittermixin.js';
10
- import { CKEditorError } from './ckeditorerror.js';
11
- import { isObject } from 'es-toolkit/compat';
12
- const observablePropertiesSymbol = Symbol('observableProperties');
13
- const boundObservablesSymbol = Symbol('boundObservables');
14
- const boundPropertiesSymbol = Symbol('boundProperties');
15
- const decoratedMethods = Symbol('decoratedMethods');
16
- const decoratedOriginal = Symbol('decoratedOriginal');
17
- const defaultObservableClass = /* #__PURE__ */ ObservableMixin(/* #__PURE__ */ EmitterMixin());
18
- export function ObservableMixin(base) {
19
- if (!base) {
20
- return defaultObservableClass;
21
- }
22
- class Mixin extends base {
23
- set(name, value) {
24
- // If the first parameter is an Object, iterate over its properties.
25
- if (isObject(name)) {
26
- Object.keys(name).forEach(property => {
27
- this.set(property, name[property]);
28
- }, this);
29
- return;
30
- }
31
- initObservable(this);
32
- const properties = this[observablePropertiesSymbol];
33
- if ((name in this) && !properties.has(name)) {
34
- /**
35
- * Cannot override an existing property.
36
- *
37
- * This error is thrown when trying to {@link module:utils/observablemixin~Observable#set set} a property with
38
- * a name of an already existing property. For example:
39
- *
40
- * ```ts
41
- * let observable = new Model();
42
- * observable.property = 1;
43
- * observable.set( 'property', 2 ); // throws
44
- *
45
- * observable.set( 'property', 1 );
46
- * observable.set( 'property', 2 ); // ok, because this is an existing property.
47
- * ```
48
- *
49
- * @error observable-set-cannot-override
50
- */
51
- throw new CKEditorError('observable-set-cannot-override', this);
52
- }
53
- Object.defineProperty(this, name, {
54
- enumerable: true,
55
- configurable: true,
56
- get() {
57
- return properties.get(name);
58
- },
59
- set(value) {
60
- const oldValue = properties.get(name);
61
- // Fire `set` event before the new value will be set to make it possible
62
- // to override observable property without affecting `change` event.
63
- // See https://github.com/ckeditor/ckeditor5-utils/issues/171.
64
- let newValue = this.fire(`set:${name}`, name, value, oldValue);
65
- if (newValue === undefined) {
66
- newValue = value;
67
- }
68
- // Allow undefined as an initial value like A.define( 'x', undefined ) (#132).
69
- // Note: When properties map has no such own property, then its value is undefined.
70
- if (oldValue !== newValue || !properties.has(name)) {
71
- properties.set(name, newValue);
72
- this.fire(`change:${name}`, name, newValue, oldValue);
73
- }
74
- }
75
- });
76
- this[name] = value;
77
- }
78
- bind(...bindProperties) {
79
- if (!bindProperties.length || !isStringArray(bindProperties)) {
80
- /**
81
- * All properties must be strings.
82
- *
83
- * @error observable-bind-wrong-properties
84
- */
85
- throw new CKEditorError('observable-bind-wrong-properties', this);
86
- }
87
- if ((new Set(bindProperties)).size !== bindProperties.length) {
88
- /**
89
- * Properties must be unique.
90
- *
91
- * @error observable-bind-duplicate-properties
92
- */
93
- throw new CKEditorError('observable-bind-duplicate-properties', this);
94
- }
95
- initObservable(this);
96
- const boundProperties = this[boundPropertiesSymbol];
97
- bindProperties.forEach(propertyName => {
98
- if (boundProperties.has(propertyName)) {
99
- /**
100
- * Cannot bind the same property more than once.
101
- *
102
- * @error observable-bind-rebind
103
- */
104
- throw new CKEditorError('observable-bind-rebind', this);
105
- }
106
- });
107
- const bindings = new Map();
108
- bindProperties.forEach(a => {
109
- const binding = { property: a, to: [] };
110
- boundProperties.set(a, binding);
111
- bindings.set(a, binding);
112
- });
113
- return {
114
- to: bindTo,
115
- toMany: bindToMany,
116
- _observable: this,
117
- _bindProperties: bindProperties,
118
- _to: [],
119
- _bindings: bindings
120
- };
121
- }
122
- unbind(...unbindProperties) {
123
- // Nothing to do here if not inited yet.
124
- if (!(this[observablePropertiesSymbol])) {
125
- return;
126
- }
127
- const boundProperties = this[boundPropertiesSymbol];
128
- const boundObservables = this[boundObservablesSymbol];
129
- if (unbindProperties.length) {
130
- if (!isStringArray(unbindProperties)) {
131
- /**
132
- * Properties must be strings.
133
- *
134
- * @error observable-unbind-wrong-properties
135
- */
136
- throw new CKEditorError('observable-unbind-wrong-properties', this);
137
- }
138
- unbindProperties.forEach(propertyName => {
139
- const binding = boundProperties.get(propertyName);
140
- // Nothing to do if the binding is not defined
141
- if (!binding) {
142
- return;
143
- }
144
- binding.to.forEach(([toObservable, toProperty]) => {
145
- const toProperties = boundObservables.get(toObservable);
146
- const toPropertyBindings = toProperties[toProperty];
147
- toPropertyBindings.delete(binding);
148
- if (!toPropertyBindings.size) {
149
- delete toProperties[toProperty];
150
- }
151
- if (!Object.keys(toProperties).length) {
152
- boundObservables.delete(toObservable);
153
- this.stopListening(toObservable, 'change');
154
- }
155
- });
156
- boundProperties.delete(propertyName);
157
- });
158
- }
159
- else {
160
- boundObservables.forEach((bindings, boundObservable) => {
161
- this.stopListening(boundObservable, 'change');
162
- });
163
- boundObservables.clear();
164
- boundProperties.clear();
165
- }
166
- }
167
- decorate(methodName) {
168
- initObservable(this);
169
- const originalMethod = this[methodName];
170
- if (!originalMethod) {
171
- /**
172
- * Cannot decorate an undefined method.
173
- *
174
- * @error observablemixin-cannot-decorate-undefined
175
- * @param {object} object The object which method should be decorated.
176
- * @param {string} methodName Name of the method which does not exist.
177
- */
178
- throw new CKEditorError('observablemixin-cannot-decorate-undefined', this, { object: this, methodName });
179
- }
180
- this.on(methodName, (evt, args) => {
181
- evt.return = originalMethod.apply(this, args);
182
- });
183
- this[methodName] = function (...args) {
184
- return this.fire(methodName, args);
185
- };
186
- this[methodName][decoratedOriginal] = originalMethod;
187
- if (!this[decoratedMethods]) {
188
- this[decoratedMethods] = [];
189
- }
190
- this[decoratedMethods].push(methodName);
191
- }
192
- // Override the EmitterMixin stopListening method to be able to clean (and restore) decorated methods.
193
- // This is needed in case of:
194
- // 1. Have x.foo() decorated.
195
- // 2. Call x.stopListening()
196
- // 3. Call x.foo(). Problem: nothing happens (the original foo() method is not executed)
197
- stopListening(emitter, event, callback) {
198
- // Removing all listeners so let's clean the decorated methods to the original state.
199
- if (!emitter && this[decoratedMethods]) {
200
- for (const methodName of this[decoratedMethods]) {
201
- this[methodName] = this[methodName][decoratedOriginal];
202
- }
203
- delete this[decoratedMethods];
204
- }
205
- super.stopListening(emitter, event, callback);
206
- }
207
- [observablePropertiesSymbol];
208
- [decoratedMethods];
209
- [boundPropertiesSymbol];
210
- [boundObservablesSymbol];
211
- }
212
- return Mixin;
213
- }
214
- // Init symbol properties needed for the observable mechanism to work.
215
- function initObservable(observable) {
216
- // Do nothing if already inited.
217
- if (observable[observablePropertiesSymbol]) {
218
- return;
219
- }
220
- // The internal hash containing the observable's state.
221
- Object.defineProperty(observable, observablePropertiesSymbol, {
222
- value: new Map()
223
- });
224
- // Map containing bindings to external observables. It shares the binding objects
225
- // (`{ observable: A, property: 'a', to: ... }`) with {@link module:utils/observablemixin~Observable#_boundProperties} and
226
- // it is used to observe external observables to update own properties accordingly.
227
- // See {@link module:utils/observablemixin~Observable#bind}.
228
- //
229
- // A.bind( 'a', 'b', 'c' ).to( B, 'x', 'y', 'x' );
230
- // console.log( A._boundObservables );
231
- //
232
- // Map( {
233
- // B: {
234
- // x: Set( [
235
- // { observable: A, property: 'a', to: [ [ B, 'x' ] ] },
236
- // { observable: A, property: 'c', to: [ [ B, 'x' ] ] }
237
- // ] ),
238
- // y: Set( [
239
- // { observable: A, property: 'b', to: [ [ B, 'y' ] ] },
240
- // ] )
241
- // }
242
- // } )
243
- //
244
- // A.bind( 'd' ).to( B, 'z' ).to( C, 'w' ).as( callback );
245
- // console.log( A._boundObservables );
246
- //
247
- // Map( {
248
- // B: {
249
- // x: Set( [
250
- // { observable: A, property: 'a', to: [ [ B, 'x' ] ] },
251
- // { observable: A, property: 'c', to: [ [ B, 'x' ] ] }
252
- // ] ),
253
- // y: Set( [
254
- // { observable: A, property: 'b', to: [ [ B, 'y' ] ] },
255
- // ] ),
256
- // z: Set( [
257
- // { observable: A, property: 'd', to: [ [ B, 'z' ], [ C, 'w' ] ], callback: callback }
258
- // ] )
259
- // },
260
- // C: {
261
- // w: Set( [
262
- // { observable: A, property: 'd', to: [ [ B, 'z' ], [ C, 'w' ] ], callback: callback }
263
- // ] )
264
- // }
265
- // } )
266
- //
267
- Object.defineProperty(observable, boundObservablesSymbol, {
268
- value: new Map()
269
- });
270
- // Object that stores which properties of this observable are bound and how. It shares
271
- // the binding objects (`{ observable: A, property: 'a', to: ... }`) with
272
- // {@link module:utils/observablemixin~Observable#_boundObservables}. This data structure is
273
- // a reverse of {@link module:utils/observablemixin~Observable#_boundObservables} and it is helpful for
274
- // {@link module:utils/observablemixin~Observable#unbind}.
275
- //
276
- // See {@link module:utils/observablemixin~Observable#bind}.
277
- //
278
- // A.bind( 'a', 'b', 'c' ).to( B, 'x', 'y', 'x' );
279
- // console.log( A._boundProperties );
280
- //
281
- // Map( {
282
- // a: { observable: A, property: 'a', to: [ [ B, 'x' ] ] },
283
- // b: { observable: A, property: 'b', to: [ [ B, 'y' ] ] },
284
- // c: { observable: A, property: 'c', to: [ [ B, 'x' ] ] }
285
- // } )
286
- //
287
- // A.bind( 'd' ).to( B, 'z' ).to( C, 'w' ).as( callback );
288
- // console.log( A._boundProperties );
289
- //
290
- // Map( {
291
- // a: { observable: A, property: 'a', to: [ [ B, 'x' ] ] },
292
- // b: { observable: A, property: 'b', to: [ [ B, 'y' ] ] },
293
- // c: { observable: A, property: 'c', to: [ [ B, 'x' ] ] },
294
- // d: { observable: A, property: 'd', to: [ [ B, 'z' ], [ C, 'w' ] ], callback: callback }
295
- // } )
296
- Object.defineProperty(observable, boundPropertiesSymbol, {
297
- value: new Map()
298
- });
299
- }
300
- /**
301
- * A chaining for {@link module:utils/observablemixin~Observable#bind} providing `.to()` interface.
302
- *
303
- * @param args Arguments of the `.to( args )` binding.
304
- */
305
- function bindTo(...args) {
306
- const parsedArgs = parseBindToArgs(...args);
307
- const bindingsKeys = Array.from(this._bindings.keys());
308
- const numberOfBindings = bindingsKeys.length;
309
- // Eliminate A.bind( 'x' ).to( B, C )
310
- if (!parsedArgs.callback && parsedArgs.to.length > 1) {
311
- /**
312
- * Binding multiple observables only possible with callback.
313
- *
314
- * @error observable-bind-to-no-callback
315
- */
316
- throw new CKEditorError('observable-bind-to-no-callback', this);
317
- }
318
- // Eliminate A.bind( 'x', 'y' ).to( B, callback )
319
- if (numberOfBindings > 1 && parsedArgs.callback) {
320
- /**
321
- * Cannot bind multiple properties and use a callback in one binding.
322
- *
323
- * @error observable-bind-to-extra-callback
324
- */
325
- throw new CKEditorError('observable-bind-to-extra-callback', this);
326
- }
327
- parsedArgs.to.forEach(to => {
328
- // Eliminate A.bind( 'x', 'y' ).to( B, 'a' )
329
- if (to.properties.length && to.properties.length !== numberOfBindings) {
330
- /**
331
- * The number of properties must match.
332
- *
333
- * @error observable-bind-to-properties-length
334
- */
335
- throw new CKEditorError('observable-bind-to-properties-length', this);
336
- }
337
- // When no to.properties specified, observing source properties instead i.e.
338
- // A.bind( 'x', 'y' ).to( B ) -> Observe B.x and B.y
339
- if (!to.properties.length) {
340
- to.properties = this._bindProperties;
341
- }
342
- });
343
- this._to = parsedArgs.to;
344
- // Fill {@link BindChain#_bindings} with callback. When the callback is set there's only one binding.
345
- if (parsedArgs.callback) {
346
- this._bindings.get(bindingsKeys[0]).callback = parsedArgs.callback;
347
- }
348
- attachBindToListeners(this._observable, this._to);
349
- // Update observable._boundProperties and observable._boundObservables.
350
- updateBindToBound(this);
351
- // Set initial values of bound properties.
352
- this._bindProperties.forEach(propertyName => {
353
- updateBoundObservableProperty(this._observable, propertyName);
354
- });
355
- }
356
- /**
357
- * Binds to an attribute in a set of iterable observables.
358
- */
359
- function bindToMany(observables, attribute, callback) {
360
- if (this._bindings.size > 1) {
361
- /**
362
- * Binding one attribute to many observables only possible with one attribute.
363
- *
364
- * @error observable-bind-to-many-not-one-binding
365
- */
366
- throw new CKEditorError('observable-bind-to-many-not-one-binding', this);
367
- }
368
- this.to(
369
- // Bind to #attribute of each observable...
370
- ...getBindingTargets(observables, attribute),
371
- // ...using given callback to parse attribute values.
372
- callback);
373
- }
374
- /**
375
- * Returns an array of binding components for
376
- * {@link Observable#bind} from a set of iterable observables.
377
- */
378
- function getBindingTargets(observables, attribute) {
379
- const observableAndAttributePairs = observables.map(observable => [observable, attribute]);
380
- // Merge pairs to one-dimension array of observables and attributes.
381
- return Array.prototype.concat.apply([], observableAndAttributePairs);
382
- }
383
- /**
384
- * Check if all entries of the array are of `String` type.
385
- */
386
- function isStringArray(arr) {
387
- return arr.every(a => typeof a == 'string');
388
- }
389
- /**
390
- * Parses and validates {@link Observable#bind}`.to( args )` arguments and returns
391
- * an object with a parsed structure. For example
392
- *
393
- * ```ts
394
- * A.bind( 'x' ).to( B, 'a', C, 'b', call );
395
- * ```
396
- *
397
- * becomes
398
- *
399
- * ```ts
400
- * {
401
- * to: [
402
- * { observable: B, properties: [ 'a' ] },
403
- * { observable: C, properties: [ 'b' ] },
404
- * ],
405
- * callback: call
406
- * }
407
- *
408
- * @param args Arguments of {@link Observable#bind}`.to( args )`.
409
- */
410
- function parseBindToArgs(...args) {
411
- // Eliminate A.bind( 'x' ).to()
412
- if (!args.length) {
413
- /**
414
- * Invalid argument syntax in `to()`.
415
- *
416
- * @error observable-bind-to-parse-error
417
- */
418
- throw new CKEditorError('observable-bind-to-parse-error', null);
419
- }
420
- const parsed = { to: [] };
421
- let lastObservable;
422
- if (typeof args[args.length - 1] == 'function') {
423
- parsed.callback = args.pop();
424
- }
425
- args.forEach(a => {
426
- if (typeof a == 'string') {
427
- lastObservable.properties.push(a);
428
- }
429
- else if (typeof a == 'object') {
430
- lastObservable = { observable: a, properties: [] };
431
- parsed.to.push(lastObservable);
432
- }
433
- else {
434
- throw new CKEditorError('observable-bind-to-parse-error', null);
435
- }
436
- });
437
- return parsed;
438
- }
439
- /**
440
- * Synchronizes {@link module:utils/observable#_boundObservables} with {@link Binding}.
441
- *
442
- * @param binding A binding to store in {@link Observable#_boundObservables}.
443
- * @param toObservable A observable, which is a new component of `binding`.
444
- * @param toPropertyName A name of `toObservable`'s property, a new component of the `binding`.
445
- */
446
- function updateBoundObservables(observable, binding, toObservable, toPropertyName) {
447
- const boundObservables = observable[boundObservablesSymbol];
448
- const bindingsToObservable = boundObservables.get(toObservable);
449
- const bindings = bindingsToObservable || {};
450
- if (!bindings[toPropertyName]) {
451
- bindings[toPropertyName] = new Set();
452
- }
453
- // Pass the binding to a corresponding Set in `observable._boundObservables`.
454
- bindings[toPropertyName].add(binding);
455
- if (!bindingsToObservable) {
456
- boundObservables.set(toObservable, bindings);
457
- }
458
- }
459
- /**
460
- * Synchronizes {@link Observable#_boundProperties} and {@link Observable#_boundObservables}
461
- * with {@link BindChain}.
462
- *
463
- * Assuming the following binding being created
464
- *
465
- * ```ts
466
- * A.bind( 'a', 'b' ).to( B, 'x', 'y' );
467
- * ```
468
- *
469
- * the following bindings were initialized by {@link Observable#bind} in {@link BindChain#_bindings}:
470
- *
471
- * ```ts
472
- * {
473
- * a: { observable: A, property: 'a', to: [] },
474
- * b: { observable: A, property: 'b', to: [] },
475
- * }
476
- * ```
477
- *
478
- * Iterate over all bindings in this chain and fill their `to` properties with
479
- * corresponding to( ... ) arguments (components of the binding), so
480
- *
481
- * ```ts
482
- * {
483
- * a: { observable: A, property: 'a', to: [ B, 'x' ] },
484
- * b: { observable: A, property: 'b', to: [ B, 'y' ] },
485
- * }
486
- * ```
487
- *
488
- * Then update the structure of {@link Observable#_boundObservables} with updated
489
- * binding, so it becomes:
490
- *
491
- * ```ts
492
- * Map( {
493
- * B: {
494
- * x: Set( [
495
- * { observable: A, property: 'a', to: [ [ B, 'x' ] ] }
496
- * ] ),
497
- * y: Set( [
498
- * { observable: A, property: 'b', to: [ [ B, 'y' ] ] },
499
- * ] )
500
- * }
501
- * } )
502
- * ```
503
- *
504
- * @param chain The binding initialized by {@link Observable#bind}.
505
- */
506
- function updateBindToBound(chain) {
507
- let toProperty;
508
- chain._bindings.forEach((binding, propertyName) => {
509
- // Note: For a binding without a callback, this will run only once
510
- // like in A.bind( 'x', 'y' ).to( B, 'a', 'b' )
511
- // TODO: ES6 destructuring.
512
- chain._to.forEach(to => {
513
- toProperty = to.properties[binding.callback ? 0 : chain._bindProperties.indexOf(propertyName)];
514
- binding.to.push([to.observable, toProperty]);
515
- updateBoundObservables(chain._observable, binding, to.observable, toProperty);
516
- });
517
- });
518
- }
519
- /**
520
- * Updates an property of a {@link Observable} with a value
521
- * determined by an entry in {@link Observable#_boundProperties}.
522
- *
523
- * @param observable A observable which property is to be updated.
524
- * @param propertyName An property to be updated.
525
- */
526
- function updateBoundObservableProperty(observable, propertyName) {
527
- const boundProperties = observable[boundPropertiesSymbol];
528
- const binding = boundProperties.get(propertyName);
529
- let propertyValue;
530
- // When a binding with callback is created like
531
- //
532
- // A.bind( 'a' ).to( B, 'b', C, 'c', callback );
533
- //
534
- // collect B.b and C.c, then pass them to callback to set A.a.
535
- if (binding.callback) {
536
- propertyValue = binding.callback.apply(observable, binding.to.map(to => to[0][to[1]]));
537
- }
538
- else {
539
- propertyValue = binding.to[0];
540
- propertyValue = propertyValue[0][propertyValue[1]];
541
- }
542
- if (Object.prototype.hasOwnProperty.call(observable, propertyName)) {
543
- observable[propertyName] = propertyValue;
544
- }
545
- else {
546
- observable.set(propertyName, propertyValue);
547
- }
548
- }
549
- /**
550
- * Starts listening to changes in {@link BindChain._to} observables to update
551
- * {@link BindChain._observable} {@link BindChain._bindProperties}. Also sets the
552
- * initial state of {@link BindChain._observable}.
553
- *
554
- * @param chain The chain initialized by {@link Observable#bind}.
555
- */
556
- function attachBindToListeners(observable, toBindings) {
557
- toBindings.forEach(to => {
558
- const boundObservables = observable[boundObservablesSymbol];
559
- let bindings;
560
- // If there's already a chain between the observables (`observable` listens to
561
- // `to.observable`), there's no need to create another `change` event listener.
562
- if (!boundObservables.get(to.observable)) {
563
- observable.listenTo(to.observable, 'change', (evt, propertyName) => {
564
- bindings = boundObservables.get(to.observable)[propertyName];
565
- // Note: to.observable will fire for any property change, react
566
- // to changes of properties which are bound only.
567
- if (bindings) {
568
- bindings.forEach(binding => {
569
- updateBoundObservableProperty(observable, binding.property);
570
- });
571
- }
572
- });
573
- }
574
- });
575
- }
@@ -1,22 +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/parsebase64encodedobject
7
- */
8
- /**
9
- * Parses a base64-encoded object and returns the decoded object, or null if the decoding was unsuccessful.
10
- */
11
- export function parseBase64EncodedObject(encoded) {
12
- try {
13
- if (!encoded.startsWith('ey')) {
14
- return null;
15
- }
16
- const decoded = atob(encoded.replace(/-/g, '+').replace(/_/g, '/'));
17
- return JSON.parse(decoded);
18
- }
19
- catch {
20
- return null;
21
- }
22
- }
package/src/priorities.js DELETED
@@ -1,22 +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
- * Provides group of constants to use instead of hardcoding numeric priority values.
7
- */
8
- export const priorities = {
9
- get(priority = 'normal') {
10
- if (typeof priority != 'number') {
11
- return this[priority] || this.normal;
12
- }
13
- else {
14
- return priority;
15
- }
16
- },
17
- highest: 100000,
18
- high: 1000,
19
- normal: 0,
20
- low: -1000,
21
- lowest: -100000
22
- };
package/src/retry.js DELETED
@@ -1,48 +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/retry
7
- */
8
- import { wait } from './wait.js';
9
- /**
10
- * Tries calling the given callback until it sucessfully resolves.
11
- *
12
- * If the callback fails `maxAttempts` times, the returned promise is rejected with the last error.
13
- *
14
- * @typeParam TResult The result of a successful callback invocation.
15
- * @param callback The function to call until it succeeds.
16
- * @param options Configuration options.
17
- * @param options.maxAttempts Maximum number of attempts.
18
- * @param options.retryDelay The time in milliseconds between attempts. By default it implements exponential back-off policy.
19
- * @param options.signal The signal to abort further retries. The callback itself is not aborted automatically.
20
- */
21
- export async function retry(callback, options = {}) {
22
- const { maxAttempts = 4, retryDelay = exponentialDelay(), signal = (new AbortController()).signal } = options;
23
- signal.throwIfAborted();
24
- for (let attempt = 0;; attempt++) {
25
- try {
26
- return await callback();
27
- }
28
- catch (err) {
29
- const isLast = attempt + 1 >= maxAttempts;
30
- if (isLast) {
31
- throw err;
32
- }
33
- }
34
- await wait(retryDelay(attempt), { signal });
35
- }
36
- }
37
- /**
38
- * Creates a function that calculates exponential back-off delay. Pass it as `options.retryDelay` to {@link ~retry}.
39
- *
40
- * @param options.delay Base delay between invocations. Defaults to 1s.
41
- * @param options.factor How much to increase the delay. Defaults to 2x.
42
- * @param options.maxDelay Maximum timeout. Even if higher timeout is calculated, it cannot get higher than this value. Default to 10s.
43
- * @returns The function calculating the delay.
44
- */
45
- export function exponentialDelay(options = {}) {
46
- const { delay = 1000, factor = 2, maxDelay = 10000 } = options;
47
- return attempt => Math.min(factor ** attempt * delay, maxDelay);
48
- }