@ckeditor/ckeditor5-engine 42.0.2-alpha.2 → 43.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.
- package/CHANGELOG.md +1 -820
- package/dist/dev-utils/model.d.ts +2 -0
- package/dist/dev-utils/view.d.ts +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +466 -271
- package/dist/index.js.map +1 -1
- package/dist/model/schema.d.ts +149 -51
- package/dist/view/observer/focusobserver.d.ts +12 -0
- package/dist/view/observer/mutationobserver.d.ts +34 -5
- package/dist/view/observer/selectionobserver.d.ts +1 -2
- package/dist/view/renderer.d.ts +12 -0
- package/dist/view/view.d.ts +1 -4
- package/package.json +2 -2
- package/src/conversion/upcasthelpers.js +0 -7
- package/src/dev-utils/model.d.ts +2 -0
- package/src/dev-utils/model.js +4 -2
- package/src/dev-utils/utils.js +7 -0
- package/src/dev-utils/view.d.ts +1 -0
- package/src/dev-utils/view.js +3 -0
- package/src/index.d.ts +3 -1
- package/src/index.js +2 -0
- package/src/model/model.js +1 -5
- package/src/model/schema.d.ts +149 -51
- package/src/model/schema.js +200 -70
- package/src/model/utils/insertcontent.js +21 -65
- package/src/view/domconverter.js +13 -9
- package/src/view/observer/compositionobserver.js +2 -0
- package/src/view/observer/focusobserver.d.ts +12 -0
- package/src/view/observer/focusobserver.js +55 -25
- package/src/view/observer/inputobserver.js +7 -5
- package/src/view/observer/mutationobserver.d.ts +34 -5
- package/src/view/observer/mutationobserver.js +8 -11
- package/src/view/observer/selectionobserver.d.ts +1 -2
- package/src/view/observer/selectionobserver.js +27 -9
- package/src/view/renderer.d.ts +12 -0
- package/src/view/renderer.js +111 -63
- package/src/view/view.d.ts +1 -4
- package/src/view/view.js +9 -0
package/dist/model/schema.d.ts
CHANGED
|
@@ -41,6 +41,24 @@ export default class Schema extends /* #__PURE__ */ Schema_base {
|
|
|
41
41
|
* A dictionary containing attribute properties.
|
|
42
42
|
*/
|
|
43
43
|
private readonly _attributeProperties;
|
|
44
|
+
/**
|
|
45
|
+
* Stores additional callbacks registered for schema items, which are evaluated when {@link ~Schema#checkChild} is called.
|
|
46
|
+
*
|
|
47
|
+
* Keys are schema item names for which the callbacks are registered. Values are arrays with the callbacks.
|
|
48
|
+
*
|
|
49
|
+
* Some checks are added under {@link ~Schema#_genericCheckSymbol} key, these are evaluated for every {@link ~Schema#checkChild} call.
|
|
50
|
+
*/
|
|
51
|
+
private readonly _customChildChecks;
|
|
52
|
+
/**
|
|
53
|
+
* Stores additional callbacks registered for attribute names, which are evaluated when {@link ~Schema#checkAttribute} is called.
|
|
54
|
+
*
|
|
55
|
+
* Keys are schema attribute names for which the callbacks are registered. Values are arrays with the callbacks.
|
|
56
|
+
*
|
|
57
|
+
* Some checks are added under {@link ~Schema#_genericCheckSymbol} key, these are evaluated for every
|
|
58
|
+
* {@link ~Schema#checkAttribute} call.
|
|
59
|
+
*/
|
|
60
|
+
private readonly _customAttributeChecks;
|
|
61
|
+
private readonly _genericCheckSymbol;
|
|
44
62
|
private _compiledDefinitions?;
|
|
45
63
|
/**
|
|
46
64
|
* Creates a schema instance.
|
|
@@ -217,7 +235,7 @@ export default class Schema extends /* #__PURE__ */ Schema_base {
|
|
|
217
235
|
*/
|
|
218
236
|
isContent(item: string | Item | DocumentFragment | SchemaContextItem): boolean;
|
|
219
237
|
/**
|
|
220
|
-
* Checks whether the given node
|
|
238
|
+
* Checks whether the given node can be a child of the given context.
|
|
221
239
|
*
|
|
222
240
|
* ```ts
|
|
223
241
|
* schema.checkChild( model.document.getRoot(), paragraph ); // -> false
|
|
@@ -225,13 +243,20 @@ export default class Schema extends /* #__PURE__ */ Schema_base {
|
|
|
225
243
|
* schema.register( 'paragraph', {
|
|
226
244
|
* allowIn: '$root'
|
|
227
245
|
* } );
|
|
246
|
+
*
|
|
228
247
|
* schema.checkChild( model.document.getRoot(), paragraph ); // -> true
|
|
229
248
|
* ```
|
|
230
249
|
*
|
|
231
|
-
*
|
|
232
|
-
* schema
|
|
233
|
-
*
|
|
234
|
-
*
|
|
250
|
+
* Both {@link module:engine/model/schema~Schema#addChildCheck callback checks} and declarative rules (added when
|
|
251
|
+
* {@link module:engine/model/schema~Schema#register registering} and {@link module:engine/model/schema~Schema#extend extending} items)
|
|
252
|
+
* are evaluated when this method is called.
|
|
253
|
+
*
|
|
254
|
+
* Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
|
|
255
|
+
*
|
|
256
|
+
* Note that when verifying whether the given node can be a child of the given context, the schema also verifies the entire
|
|
257
|
+
* context – from its root to its last element. Therefore, it is possible for `checkChild()` to return `false` even though
|
|
258
|
+
* the `context` last element can contain the checked child. It happens if one of the `context` elements does not allow its child.
|
|
259
|
+
* When `context` is verified, {@link module:engine/model/schema~Schema#addChildCheck custom checks} are considered as well.
|
|
235
260
|
*
|
|
236
261
|
* @fires checkChild
|
|
237
262
|
* @param context The context in which the child will be checked.
|
|
@@ -239,8 +264,7 @@ export default class Schema extends /* #__PURE__ */ Schema_base {
|
|
|
239
264
|
*/
|
|
240
265
|
checkChild(context: SchemaContextDefinition, def: string | Node | DocumentFragment): boolean;
|
|
241
266
|
/**
|
|
242
|
-
* Checks whether the given attribute can be applied in the given context (on the last
|
|
243
|
-
* item of the context).
|
|
267
|
+
* Checks whether the given attribute can be applied in the given context (on the last item of the context).
|
|
244
268
|
*
|
|
245
269
|
* ```ts
|
|
246
270
|
* schema.checkAttribute( textNode, 'bold' ); // -> false
|
|
@@ -248,116 +272,152 @@ export default class Schema extends /* #__PURE__ */ Schema_base {
|
|
|
248
272
|
* schema.extend( '$text', {
|
|
249
273
|
* allowAttributes: 'bold'
|
|
250
274
|
* } );
|
|
275
|
+
*
|
|
251
276
|
* schema.checkAttribute( textNode, 'bold' ); // -> true
|
|
252
277
|
* ```
|
|
253
278
|
*
|
|
279
|
+
* Both {@link module:engine/model/schema~Schema#addAttributeCheck callback checks} and declarative rules (added when
|
|
280
|
+
* {@link module:engine/model/schema~Schema#register registering} and {@link module:engine/model/schema~Schema#extend extending} items)
|
|
281
|
+
* are evaluated when this method is called.
|
|
282
|
+
*
|
|
283
|
+
* Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
|
|
284
|
+
*
|
|
254
285
|
* @fires checkAttribute
|
|
255
286
|
* @param context The context in which the attribute will be checked.
|
|
287
|
+
* @param attributeName Name of attribute to check in the given context.
|
|
256
288
|
*/
|
|
257
289
|
checkAttribute(context: SchemaContextDefinition, attributeName: string): boolean;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
*
|
|
261
|
-
* In other words – whether `elementToMerge`'s children {@link #checkChild are allowed} in the `positionOrBaseElement`.
|
|
262
|
-
*
|
|
263
|
-
* This check ensures that elements merged with {@link module:engine/model/writer~Writer#merge `Writer#merge()`}
|
|
264
|
-
* will be valid.
|
|
265
|
-
*
|
|
266
|
-
* Instead of elements, you can pass the instance of the {@link module:engine/model/position~Position} class as the
|
|
267
|
-
* `positionOrBaseElement`. It means that the elements before and after the position will be checked whether they can be merged.
|
|
268
|
-
*
|
|
269
|
-
* @param positionOrBaseElement The position or base element to which the `elementToMerge` will be merged.
|
|
270
|
-
* @param elementToMerge The element to merge. Required if `positionOrBaseElement` is an element.
|
|
271
|
-
*/
|
|
272
|
-
checkMerge(positionOrBaseElement: Position | Element, elementToMerge: Element): boolean;
|
|
290
|
+
checkMerge(position: Position): boolean;
|
|
291
|
+
checkMerge(baseElement: Element, elementToMerge: Element): boolean;
|
|
273
292
|
/**
|
|
274
293
|
* Allows registering a callback to the {@link #checkChild} method calls.
|
|
275
294
|
*
|
|
276
295
|
* Callbacks allow you to implement rules which are not otherwise possible to achieve
|
|
277
296
|
* by using the declarative API of {@link module:engine/model/schema~SchemaItemDefinition}.
|
|
278
|
-
* For example, by using this method you can disallow elements in specific contexts.
|
|
279
297
|
*
|
|
280
|
-
*
|
|
281
|
-
* you can use that event instead.
|
|
298
|
+
* Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
|
|
282
299
|
*
|
|
283
|
-
*
|
|
300
|
+
* For example, by using this method you can disallow elements in specific contexts:
|
|
284
301
|
*
|
|
285
302
|
* ```ts
|
|
286
|
-
* // Disallow heading1
|
|
303
|
+
* // Disallow `heading1` inside a `blockQuote` that is inside a table.
|
|
287
304
|
* schema.addChildCheck( ( context, childDefinition ) => {
|
|
288
|
-
* if ( context.endsWith( 'blockQuote' )
|
|
305
|
+
* if ( context.endsWith( 'tableCell blockQuote' ) ) {
|
|
289
306
|
* return false;
|
|
290
307
|
* }
|
|
308
|
+
* }, 'heading1' );
|
|
309
|
+
* ```
|
|
310
|
+
*
|
|
311
|
+
* You can skip the optional `itemName` parameter to evaluate the callback for every `checkChild()` call.
|
|
312
|
+
*
|
|
313
|
+
* ```ts
|
|
314
|
+
* // Inside specific custom element, allow only children, which allows for a specific attribute.
|
|
315
|
+
* schema.addChildCheck( ( context, childDefinition ) => {
|
|
316
|
+
* if ( context.endsWith( 'myElement' ) ) {
|
|
317
|
+
* return childDefinition.allowAttributes.includes( 'myAttribute' );
|
|
318
|
+
* }
|
|
291
319
|
* } );
|
|
292
320
|
* ```
|
|
293
321
|
*
|
|
294
|
-
*
|
|
322
|
+
* Please note that the generic callbacks may affect the editor performance and should be avoided if possible.
|
|
323
|
+
*
|
|
324
|
+
* When one of the callbacks makes a decision (returns `true` or `false`) the processing is finished and other callbacks are not fired.
|
|
325
|
+
* Callbacks are fired in the order they were added, however generic callbacks are fired before callbacks added for a specified item.
|
|
326
|
+
*
|
|
327
|
+
* You can also use `checkChild` event, if you need even better control. The result from the example above could also be
|
|
328
|
+
* achieved with following event callback:
|
|
295
329
|
*
|
|
296
330
|
* ```ts
|
|
297
331
|
* schema.on( 'checkChild', ( evt, args ) => {
|
|
298
332
|
* const context = args[ 0 ];
|
|
299
333
|
* const childDefinition = args[ 1 ];
|
|
300
334
|
*
|
|
301
|
-
* if ( context.endsWith( '
|
|
335
|
+
* if ( context.endsWith( 'myElement' ) ) {
|
|
302
336
|
* // Prevent next listeners from being called.
|
|
303
337
|
* evt.stop();
|
|
304
|
-
* // Set the checkChild()
|
|
305
|
-
* evt.return =
|
|
338
|
+
* // Set the `checkChild()` return value.
|
|
339
|
+
* evt.return = childDefinition.allowAttributes.includes( 'myAttribute' );
|
|
306
340
|
* }
|
|
307
341
|
* }, { priority: 'high' } );
|
|
308
342
|
* ```
|
|
309
343
|
*
|
|
344
|
+
* Note that the callback checks and declarative rules checks are processed on `normal` priority.
|
|
345
|
+
*
|
|
346
|
+
* Adding callbacks this way can also negatively impact editor performance.
|
|
347
|
+
*
|
|
310
348
|
* @param callback The callback to be called. It is called with two parameters:
|
|
311
349
|
* {@link module:engine/model/schema~SchemaContext} (context) instance and
|
|
312
|
-
* {@link module:engine/model/schema~SchemaCompiledItemDefinition} (
|
|
313
|
-
*
|
|
314
|
-
*
|
|
350
|
+
* {@link module:engine/model/schema~SchemaCompiledItemDefinition} (definition). The callback may return `true/false` to override
|
|
351
|
+
* `checkChild()`'s return value. If it does not return a boolean value, the default algorithm (or other callbacks) will define
|
|
352
|
+
* `checkChild()`'s return value.
|
|
353
|
+
* @param itemName Name of the schema item for which the callback is registered. If specified, the callback will be run only for
|
|
354
|
+
* `checkChild()` calls which `def` parameter matches the `itemName`. Otherwise, the callback will run for every `checkChild` call.
|
|
315
355
|
*/
|
|
316
|
-
addChildCheck(callback: SchemaChildCheckCallback): void;
|
|
356
|
+
addChildCheck(callback: SchemaChildCheckCallback, itemName?: string): void;
|
|
317
357
|
/**
|
|
318
358
|
* Allows registering a callback to the {@link #checkAttribute} method calls.
|
|
319
359
|
*
|
|
320
360
|
* Callbacks allow you to implement rules which are not otherwise possible to achieve
|
|
321
361
|
* by using the declarative API of {@link module:engine/model/schema~SchemaItemDefinition}.
|
|
322
|
-
* For example, by using this method you can disallow attribute if node to which it is applied
|
|
323
|
-
* is contained within some other element (e.g. you want to disallow `bold` on `$text` within `heading1`).
|
|
324
362
|
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
363
|
+
* Note that callback checks have bigger priority than declarative rules checks and may overwrite them.
|
|
364
|
+
*
|
|
365
|
+
* For example, by using this method you can disallow setting attributes on nodes in specific contexts:
|
|
366
|
+
*
|
|
367
|
+
* ```ts
|
|
368
|
+
* // Disallow setting `bold` on text inside `heading1` element:
|
|
369
|
+
* schema.addAttributeCheck( context => {
|
|
370
|
+
* if ( context.endsWith( 'heading1 $text' ) ) {
|
|
371
|
+
* return false;
|
|
372
|
+
* }
|
|
373
|
+
* }, 'bold' );
|
|
374
|
+
* ```
|
|
327
375
|
*
|
|
328
|
-
*
|
|
376
|
+
* You can skip the optional `attributeName` parameter to evaluate the callback for every `checkAttribute()` call.
|
|
329
377
|
*
|
|
330
378
|
* ```ts
|
|
331
|
-
* // Disallow
|
|
379
|
+
* // Disallow formatting attributes on text inside custom `myTitle` element:
|
|
332
380
|
* schema.addAttributeCheck( ( context, attributeName ) => {
|
|
333
|
-
* if ( context.endsWith( '
|
|
381
|
+
* if ( context.endsWith( 'myTitle $text' ) && schema.getAttributeProperties( attributeName ).isFormatting ) {
|
|
334
382
|
* return false;
|
|
335
383
|
* }
|
|
336
384
|
* } );
|
|
337
385
|
* ```
|
|
338
386
|
*
|
|
339
|
-
*
|
|
387
|
+
* Please note that the generic callbacks may affect the editor performance and should be avoided if possible.
|
|
388
|
+
*
|
|
389
|
+
* When one of the callbacks makes a decision (returns `true` or `false`) the processing is finished and other callbacks are not fired.
|
|
390
|
+
* Callbacks are fired in the order they were added, however generic callbacks are fired before callbacks added for a specified item.
|
|
391
|
+
*
|
|
392
|
+
* You can also use {@link #event:checkAttribute} event, if you need even better control. The result from the example above could also
|
|
393
|
+
* be achieved with following event callback:
|
|
340
394
|
*
|
|
341
395
|
* ```ts
|
|
342
396
|
* schema.on( 'checkAttribute', ( evt, args ) => {
|
|
343
397
|
* const context = args[ 0 ];
|
|
344
398
|
* const attributeName = args[ 1 ];
|
|
345
399
|
*
|
|
346
|
-
* if ( context.endsWith( '
|
|
400
|
+
* if ( context.endsWith( 'myTitle $text' ) && schema.getAttributeProperties( attributeName ).isFormatting ) {
|
|
347
401
|
* // Prevent next listeners from being called.
|
|
348
402
|
* evt.stop();
|
|
349
|
-
* // Set the checkAttribute()
|
|
403
|
+
* // Set the `checkAttribute()` return value.
|
|
350
404
|
* evt.return = false;
|
|
351
405
|
* }
|
|
352
406
|
* }, { priority: 'high' } );
|
|
353
407
|
* ```
|
|
354
408
|
*
|
|
409
|
+
* Note that the callback checks and declarative rules checks are processed on `normal` priority.
|
|
410
|
+
*
|
|
411
|
+
* Adding callbacks this way can also negatively impact editor performance.
|
|
412
|
+
*
|
|
355
413
|
* @param callback The callback to be called. It is called with two parameters:
|
|
356
|
-
* {@link module:engine/model/schema~SchemaContext
|
|
357
|
-
*
|
|
358
|
-
*
|
|
414
|
+
* {@link module:engine/model/schema~SchemaContext `context`} and attribute name. The callback may return `true` or `false`, to
|
|
415
|
+
* override `checkAttribute()`'s return value. If it does not return a boolean value, the default algorithm (or other callbacks)
|
|
416
|
+
* will define `checkAttribute()`'s return value.
|
|
417
|
+
* @param attributeName Name of the attribute for which the callback is registered. If specified, the callback will be run only for
|
|
418
|
+
* `checkAttribute()` calls with matching `attributeName`. Otherwise, the callback will run for every `checkAttribute()` call.
|
|
359
419
|
*/
|
|
360
|
-
addAttributeCheck(callback: SchemaAttributeCheckCallback): void;
|
|
420
|
+
addAttributeCheck(callback: SchemaAttributeCheckCallback, attributeName?: string): void;
|
|
361
421
|
/**
|
|
362
422
|
* This method allows assigning additional metadata to the model attributes. For example,
|
|
363
423
|
* {@link module:engine/model/schema~AttributeProperties `AttributeProperties#isFormatting` property} is
|
|
@@ -500,6 +560,22 @@ export default class Schema extends /* #__PURE__ */ Schema_base {
|
|
|
500
560
|
private _clearCache;
|
|
501
561
|
private _compile;
|
|
502
562
|
private _checkContextMatch;
|
|
563
|
+
/**
|
|
564
|
+
* Calls child check callbacks to decide whether `def` is allowed in `context`. It uses both generic and specific (defined for `def`
|
|
565
|
+
* item) callbacks. If neither callback makes a decision, `undefined` is returned.
|
|
566
|
+
*
|
|
567
|
+
* Note that the first callback that makes a decision "wins", i.e., if any callback returns `true` or `false`, then the processing
|
|
568
|
+
* is over and that result is returned.
|
|
569
|
+
*/
|
|
570
|
+
private _evaluateChildChecks;
|
|
571
|
+
/**
|
|
572
|
+
* Calls attribute check callbacks to decide whether `attributeName` can be set on the last element of `context`. It uses both
|
|
573
|
+
* generic and specific (defined for `attributeName`) callbacks. If neither callback makes a decision, `undefined` is returned.
|
|
574
|
+
*
|
|
575
|
+
* Note that the first callback that makes a decision "wins", i.e., if any callback returns `true` or `false`, then the processing
|
|
576
|
+
* is over and that result is returned.
|
|
577
|
+
*/
|
|
578
|
+
private _evaluateAttributeChecks;
|
|
503
579
|
/**
|
|
504
580
|
* Takes a flat range and an attribute name. Traverses the range recursively and deeply to find and return all ranges
|
|
505
581
|
* inside the given range on which the attribute can be applied.
|
|
@@ -879,22 +955,32 @@ export interface SchemaItemDefinition {
|
|
|
879
955
|
disallowAttributes?: string | Array<string>;
|
|
880
956
|
/**
|
|
881
957
|
* Inherits "allowed children" from other items.
|
|
958
|
+
*
|
|
959
|
+
* Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
|
|
882
960
|
*/
|
|
883
961
|
allowContentOf?: string | Array<string>;
|
|
884
962
|
/**
|
|
885
963
|
* Inherits "allowed in" from other items.
|
|
964
|
+
*
|
|
965
|
+
* Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
|
|
886
966
|
*/
|
|
887
967
|
allowWhere?: string | Array<string>;
|
|
888
968
|
/**
|
|
889
969
|
* Inherits "allowed attributes" from other items.
|
|
970
|
+
*
|
|
971
|
+
* Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
|
|
890
972
|
*/
|
|
891
973
|
allowAttributesOf?: string | Array<string>;
|
|
892
974
|
/**
|
|
893
975
|
* Inherits `is*` properties of other items.
|
|
976
|
+
*
|
|
977
|
+
* Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
|
|
894
978
|
*/
|
|
895
979
|
inheritTypesFrom?: string | Array<string>;
|
|
896
980
|
/**
|
|
897
981
|
* A shorthand for `allowContentOf`, `allowWhere`, `allowAttributesOf`, `inheritTypesFrom`.
|
|
982
|
+
*
|
|
983
|
+
* Note that the item's "own" rules take precedence over "inherited" rules and can overwrite them.
|
|
898
984
|
*/
|
|
899
985
|
inheritAllFrom?: string;
|
|
900
986
|
/**
|
|
@@ -1064,6 +1150,18 @@ export declare class SchemaContext implements Iterable<SchemaContextItem> {
|
|
|
1064
1150
|
* @returns A new schema context instance with an additional item.
|
|
1065
1151
|
*/
|
|
1066
1152
|
push(item: string | Node): SchemaContext;
|
|
1153
|
+
/**
|
|
1154
|
+
* Returns a new schema context that is based on this context but has the last item removed.
|
|
1155
|
+
*
|
|
1156
|
+
* ```ts
|
|
1157
|
+
* const ctxParagraph = new SchemaContext( [ '$root', 'blockQuote', 'paragraph' ] );
|
|
1158
|
+
* const ctxBlockQuote = ctxParagraph.trimLast(); // Items in `ctxBlockQuote` are: `$root` an `blockQuote`.
|
|
1159
|
+
* const ctxRoot = ctxBlockQuote.trimLast(); // Items in `ctxRoot` are: `$root`.
|
|
1160
|
+
* ```
|
|
1161
|
+
*
|
|
1162
|
+
* @returns A new reduced schema context instance.
|
|
1163
|
+
*/
|
|
1164
|
+
trimLast(): SchemaContext;
|
|
1067
1165
|
/**
|
|
1068
1166
|
* Gets an item on the given index.
|
|
1069
1167
|
*/
|
|
@@ -1113,7 +1211,7 @@ export declare class SchemaContext implements Iterable<SchemaContextItem> {
|
|
|
1113
1211
|
* * By defining an **array of node names** (potentially, mixed with real nodes) – The same as **name of node**
|
|
1114
1212
|
* but it is possible to create a path.
|
|
1115
1213
|
* * By defining a {@link module:engine/model/schema~SchemaContext} instance - in this case the same instance as provided
|
|
1116
|
-
* will be
|
|
1214
|
+
* will be returned.
|
|
1117
1215
|
*
|
|
1118
1216
|
* Examples of context definitions passed to the {@link module:engine/model/schema~Schema#checkChild `Schema#checkChild()`}
|
|
1119
1217
|
* method:
|
|
@@ -51,6 +51,18 @@ export default class FocusObserver extends DomEventObserver<'focus' | 'blur'> {
|
|
|
51
51
|
* @inheritDoc
|
|
52
52
|
*/
|
|
53
53
|
destroy(): void;
|
|
54
|
+
/**
|
|
55
|
+
* The `focus` event handler.
|
|
56
|
+
*/
|
|
57
|
+
private _handleFocus;
|
|
58
|
+
/**
|
|
59
|
+
* The `blur` event handler.
|
|
60
|
+
*/
|
|
61
|
+
private _handleBlur;
|
|
62
|
+
/**
|
|
63
|
+
* Clears timeout.
|
|
64
|
+
*/
|
|
65
|
+
private _clearTimeout;
|
|
54
66
|
}
|
|
55
67
|
/**
|
|
56
68
|
* Fired when one of the editables gets focus.
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import Observer from './observer.js';
|
|
13
13
|
import type DomConverter from '../domconverter.js';
|
|
14
|
-
import type Renderer from '../renderer.js';
|
|
15
14
|
import type View from '../view.js';
|
|
15
|
+
import type ViewNode from '../node.js';
|
|
16
|
+
import type { ChangeType } from '../document.js';
|
|
16
17
|
/**
|
|
17
18
|
* Mutation observer's role is to watch for any DOM changes inside the editor that weren't
|
|
18
19
|
* done by the editor's {@link module:engine/view/renderer~Renderer} itself and reverting these changes.
|
|
@@ -29,10 +30,6 @@ export default class MutationObserver extends Observer {
|
|
|
29
30
|
* Reference to the {@link module:engine/view/view~View#domConverter}.
|
|
30
31
|
*/
|
|
31
32
|
readonly domConverter: DomConverter;
|
|
32
|
-
/**
|
|
33
|
-
* Reference to the {@link module:engine/view/view~View#_renderer}.
|
|
34
|
-
*/
|
|
35
|
-
readonly renderer: Renderer;
|
|
36
33
|
/**
|
|
37
34
|
* Native mutation observer config.
|
|
38
35
|
*/
|
|
@@ -88,3 +85,35 @@ export default class MutationObserver extends Observer {
|
|
|
88
85
|
*/
|
|
89
86
|
private _isBogusBrMutation;
|
|
90
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Event fired on DOM mutations detected.
|
|
90
|
+
*
|
|
91
|
+
* This event is introduced by {@link module:engine/view/observer/mutationobserver~MutationObserver} and available
|
|
92
|
+
* by default in all editor instances (attached by {@link module:engine/view/view~View}).
|
|
93
|
+
*
|
|
94
|
+
* @eventName module:engine/view/document~Document#mutations
|
|
95
|
+
* @param data Event data containing detailed information about the event.
|
|
96
|
+
*/
|
|
97
|
+
export type ViewDocumentMutationsEvent = {
|
|
98
|
+
name: 'mutations';
|
|
99
|
+
args: [data: MutationsEventData];
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* The value of {@link ~ViewDocumentMutationsEvent}.
|
|
103
|
+
*/
|
|
104
|
+
export type MutationsEventData = {
|
|
105
|
+
mutations: Array<MutationData>;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* A single entry in {@link ~MutationsEventData} mutations array.
|
|
109
|
+
*/
|
|
110
|
+
export type MutationData = {
|
|
111
|
+
/**
|
|
112
|
+
* Type of mutation detected.
|
|
113
|
+
*/
|
|
114
|
+
type: ChangeType;
|
|
115
|
+
/**
|
|
116
|
+
* The view node related to the detected mutation.
|
|
117
|
+
*/
|
|
118
|
+
node: ViewNode;
|
|
119
|
+
};
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import Observer from './observer.js';
|
|
13
13
|
import MutationObserver from './mutationobserver.js';
|
|
14
|
+
import FocusObserver from './focusobserver.js';
|
|
14
15
|
import type View from '../view.js';
|
|
15
16
|
import type DocumentSelection from '../documentselection.js';
|
|
16
17
|
import type DomConverter from '../domconverter.js';
|
|
17
18
|
import type Selection from '../selection.js';
|
|
18
|
-
import FocusObserver from './focusobserver.js';
|
|
19
19
|
type DomSelection = globalThis.Selection;
|
|
20
20
|
/**
|
|
21
21
|
* Selection observer class observes selection changes in the document. If a selection changes on the document this
|
|
@@ -92,7 +92,6 @@ export default class SelectionObserver extends Observer {
|
|
|
92
92
|
* a selection changes and fires {@link module:engine/view/document~Document#event:selectionChange} event on every change
|
|
93
93
|
* and {@link module:engine/view/document~Document#event:selectionChangeDone} when a selection stop changing.
|
|
94
94
|
*
|
|
95
|
-
* @param domEvent DOM event.
|
|
96
95
|
* @param domDocument DOM document.
|
|
97
96
|
*/
|
|
98
97
|
private _handleSelectionChange;
|
package/dist/view/renderer.d.ts
CHANGED
|
@@ -217,6 +217,18 @@ export default class Renderer extends /* #__PURE__ */ Renderer_base {
|
|
|
217
217
|
* @returns Actions array modified with the `update` actions.
|
|
218
218
|
*/
|
|
219
219
|
private _findUpdateActions;
|
|
220
|
+
/**
|
|
221
|
+
* Checks if text needs to be updated and possibly updates it by removing and inserting only parts
|
|
222
|
+
* of the data from the existing text node to reduce impact on the IME composition.
|
|
223
|
+
*
|
|
224
|
+
* @param domText DOM text node to update.
|
|
225
|
+
* @param expectedText The expected data of a text node.
|
|
226
|
+
*/
|
|
227
|
+
private _updateTextNode;
|
|
228
|
+
/**
|
|
229
|
+
* Part of the `_updateTextNode` method extracted for easier testing.
|
|
230
|
+
*/
|
|
231
|
+
private _updateTextNodeInternal;
|
|
220
232
|
/**
|
|
221
233
|
* Marks text nodes to be synchronized.
|
|
222
234
|
*
|
package/dist/view/view.d.ts
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import Document from './document.js';
|
|
13
13
|
import DowncastWriter from './downcastwriter.js';
|
|
14
|
-
import Renderer from './renderer.js';
|
|
15
14
|
import DomConverter from './domconverter.js';
|
|
16
15
|
import Position, { type PositionOffset } from './position.js';
|
|
17
16
|
import Range from './range.js';
|
|
@@ -99,10 +98,8 @@ export default class View extends /* #__PURE__ */ View_base {
|
|
|
99
98
|
hasDomSelection: boolean;
|
|
100
99
|
/**
|
|
101
100
|
* Instance of the {@link module:engine/view/renderer~Renderer renderer}.
|
|
102
|
-
*
|
|
103
|
-
* @internal
|
|
104
101
|
*/
|
|
105
|
-
readonly _renderer
|
|
102
|
+
private readonly _renderer;
|
|
106
103
|
/**
|
|
107
104
|
* A DOM root attributes cache. It saves the initial values of DOM root attributes before the DOM element
|
|
108
105
|
* is {@link module:engine/view/view~View#attachDomRoot attached} to the view so later on, when
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-engine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "43.0.0-alpha.0",
|
|
4
4
|
"description": "The editing engine of CKEditor 5 – the best browser-based rich text editor.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wysiwyg",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"type": "module",
|
|
25
25
|
"main": "src/index.js",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@ckeditor/ckeditor5-utils": "
|
|
27
|
+
"@ckeditor/ckeditor5-utils": "43.0.0-alpha.0",
|
|
28
28
|
"lodash-es": "4.17.21"
|
|
29
29
|
},
|
|
30
30
|
"author": "CKSource (http://cksource.com/)",
|
|
@@ -466,14 +466,7 @@ export function convertText() {
|
|
|
466
466
|
if (data.viewItem.data.trim().length == 0) {
|
|
467
467
|
return;
|
|
468
468
|
}
|
|
469
|
-
// Wrap `$text` in paragraph and include any marker that is directly before `$text`. See #13053.
|
|
470
|
-
const nodeBefore = position.nodeBefore;
|
|
471
469
|
position = wrapInParagraph(position, writer);
|
|
472
|
-
if (nodeBefore && nodeBefore.is('element', '$marker')) {
|
|
473
|
-
// Move `$marker` to the paragraph.
|
|
474
|
-
writer.move(writer.createRangeOn(nodeBefore), position);
|
|
475
|
-
position = writer.createPositionAfter(nodeBefore);
|
|
476
|
-
}
|
|
477
470
|
}
|
|
478
471
|
consumable.consume(data.viewItem);
|
|
479
472
|
const text = writer.createText(data.viewItem.data);
|
package/src/dev-utils/model.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ export declare function setData(model: Model, data: string, options?: {
|
|
|
75
75
|
selectionAttributes?: Record<string, unknown>;
|
|
76
76
|
lastRangeBackward?: boolean;
|
|
77
77
|
batchType?: BatchType;
|
|
78
|
+
inlineObjectElements?: Array<string>;
|
|
78
79
|
}): void;
|
|
79
80
|
export declare namespace setData {
|
|
80
81
|
var _parse: typeof parse;
|
|
@@ -118,6 +119,7 @@ export declare function parse(data: string, schema: Schema, options?: {
|
|
|
118
119
|
selectionAttributes?: Record<string, unknown> | Iterable<[string, unknown]>;
|
|
119
120
|
lastRangeBackward?: boolean;
|
|
120
121
|
context?: SchemaContextDefinition;
|
|
122
|
+
inlineObjectElements?: Array<string>;
|
|
121
123
|
}): ModelNode | ModelDocumentFragment | {
|
|
122
124
|
model: ModelNode | ModelDocumentFragment;
|
|
123
125
|
selection: ModelSelection;
|
package/src/dev-utils/model.js
CHANGED
|
@@ -97,7 +97,8 @@ export function setData(model, data, options = {}) {
|
|
|
97
97
|
const parsedResult = setData._parse(data, model.schema, {
|
|
98
98
|
lastRangeBackward: options.lastRangeBackward,
|
|
99
99
|
selectionAttributes: options.selectionAttributes,
|
|
100
|
-
context: [modelRoot.name]
|
|
100
|
+
context: [modelRoot.name],
|
|
101
|
+
inlineObjectElements: options.inlineObjectElements
|
|
101
102
|
});
|
|
102
103
|
// Retrieve DocumentFragment and Selection from parsed model.
|
|
103
104
|
if ('model' in parsedResult) {
|
|
@@ -266,7 +267,8 @@ export function parse(data, schema, options = {}) {
|
|
|
266
267
|
// Parse data to view using view utils.
|
|
267
268
|
const parsedResult = viewParse(data, {
|
|
268
269
|
sameSelectionCharacters: true,
|
|
269
|
-
lastRangeBackward: !!options.lastRangeBackward
|
|
270
|
+
lastRangeBackward: !!options.lastRangeBackward,
|
|
271
|
+
inlineObjectElements: options.inlineObjectElements
|
|
270
272
|
});
|
|
271
273
|
// Retrieve DocumentFragment and Selection from parsed view.
|
|
272
274
|
let viewDocumentFragment;
|
package/src/dev-utils/utils.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* @module engine/dev-utils/utils
|
|
11
11
|
*/
|
|
12
12
|
/* globals console */
|
|
13
|
+
// @if CK_DEBUG_TYPING // const { debounce } = require( 'lodash-es' );
|
|
13
14
|
/**
|
|
14
15
|
* Helper function, converts a map to the 'key1="value1" key2="value1"' format.
|
|
15
16
|
*
|
|
@@ -71,3 +72,9 @@ export function logDocument(document, version) {
|
|
|
71
72
|
console.log('Tree log unavailable for given version: ' + version);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
75
|
+
// @if CK_DEBUG_TYPING // export const _debouncedLine = debounce( () => {
|
|
76
|
+
// @if CK_DEBUG_TYPING // console.log(
|
|
77
|
+
// @if CK_DEBUG_TYPING // '%c───────────────────────────────────────────────────────────────────────────────────────────────────────',
|
|
78
|
+
// @if CK_DEBUG_TYPING // 'font-weight: bold; color: red'
|
|
79
|
+
// @if CK_DEBUG_TYPING // );
|
|
80
|
+
// @if CK_DEBUG_TYPING // }, 300 );
|
package/src/dev-utils/view.d.ts
CHANGED
|
@@ -313,6 +313,7 @@ export declare function parse(data: string, options?: {
|
|
|
313
313
|
lastRangeBackward?: boolean;
|
|
314
314
|
rootElement?: ViewElement | ViewDocumentFragment;
|
|
315
315
|
sameSelectionCharacters?: boolean;
|
|
316
|
+
inlineObjectElements?: Array<string>;
|
|
316
317
|
}): ViewNode | ViewDocumentFragment | {
|
|
317
318
|
view: ViewNode | ViewDocumentFragment;
|
|
318
319
|
selection: DocumentSelection;
|
package/src/dev-utils/view.js
CHANGED
|
@@ -364,6 +364,9 @@ export function parse(data, options = {}) {
|
|
|
364
364
|
const processor = new XmlDataProcessor(viewDocument, {
|
|
365
365
|
namespaces: Object.keys(allowedTypes)
|
|
366
366
|
});
|
|
367
|
+
if (options.inlineObjectElements) {
|
|
368
|
+
processor.domConverter.inlineObjectElements.push(...options.inlineObjectElements);
|
|
369
|
+
}
|
|
367
370
|
// Convert data to view.
|
|
368
371
|
let view = processor.toView(data);
|
|
369
372
|
// At this point we have a view tree with Elements that could have names like `attribute:b:1`. In the next step
|
package/src/index.d.ts
CHANGED
|
@@ -50,10 +50,11 @@ export type { default as Differ, DiffItem, DiffItemAttribute, DiffItemInsert, Di
|
|
|
50
50
|
export type { default as Item } from './model/item.js';
|
|
51
51
|
export type { default as Node, NodeAttributes } from './model/node.js';
|
|
52
52
|
export type { default as RootElement } from './model/rootelement.js';
|
|
53
|
-
export type { default as Schema, SchemaAttributeCheckCallback, SchemaChildCheckCallback, AttributeProperties, SchemaItemDefinition } from './model/schema.js';
|
|
53
|
+
export type { default as Schema, SchemaAttributeCheckCallback, SchemaChildCheckCallback, AttributeProperties, SchemaItemDefinition, SchemaContext } from './model/schema.js';
|
|
54
54
|
export type { default as Selection, Selectable } from './model/selection.js';
|
|
55
55
|
export type { default as TypeCheckable } from './model/typecheckable.js';
|
|
56
56
|
export type { default as Writer } from './model/writer.js';
|
|
57
|
+
export * from './model/utils/autoparagraphing.js';
|
|
57
58
|
export type { DocumentChangeEvent } from './model/document.js';
|
|
58
59
|
export type { DocumentSelectionChangeEvent } from './model/documentselection.js';
|
|
59
60
|
export type { ModelApplyOperationEvent, ModelDeleteContentEvent, ModelGetSelectedContentEvent, ModelInsertContentEvent, ModelInsertObjectEvent, ModelModifySelectionEvent, ModelCanEditAtEvent } from './model/model.js';
|
|
@@ -99,6 +100,7 @@ export type { BubblingEvent } from './view/observer/bubblingemittermixin.js';
|
|
|
99
100
|
export type { ViewDocumentArrowKeyEvent } from './view/observer/arrowkeysobserver.js';
|
|
100
101
|
export type { ViewDocumentCompositionStartEvent, ViewDocumentCompositionUpdateEvent, ViewDocumentCompositionEndEvent } from './view/observer/compositionobserver.js';
|
|
101
102
|
export type { ViewDocumentInputEvent } from './view/observer/inputobserver.js';
|
|
103
|
+
export type { ViewDocumentMutationsEvent, MutationData } from './view/observer/mutationobserver.js';
|
|
102
104
|
export type { ViewDocumentKeyDownEvent, ViewDocumentKeyUpEvent, KeyEventData } from './view/observer/keyobserver.js';
|
|
103
105
|
export type { ViewDocumentLayoutChangedEvent } from './view/document.js';
|
|
104
106
|
export type { ViewDocumentMouseDownEvent, ViewDocumentMouseUpEvent, ViewDocumentMouseOverEvent, ViewDocumentMouseOutEvent } from './view/observer/mouseobserver.js';
|
package/src/index.js
CHANGED
|
@@ -38,6 +38,8 @@ export { default as DocumentFragment } from './model/documentfragment.js';
|
|
|
38
38
|
export { default as History } from './model/history.js';
|
|
39
39
|
export { default as Text } from './model/text.js';
|
|
40
40
|
export { default as TextProxy } from './model/textproxy.js';
|
|
41
|
+
// Model utils.
|
|
42
|
+
export * from './model/utils/autoparagraphing.js';
|
|
41
43
|
// View.
|
|
42
44
|
export { default as DataTransfer } from './view/datatransfer.js';
|
|
43
45
|
export { default as DomConverter } from './view/domconverter.js';
|
package/src/model/model.js
CHANGED
|
@@ -90,11 +90,7 @@ export default class Model extends /* #__PURE__ */ ObservableMixin() {
|
|
|
90
90
|
// at the end of the conversion. `UpcastDispatcher` or at least `Conversion` class looks like a
|
|
91
91
|
// better place for this registration but both know nothing about `Schema`.
|
|
92
92
|
this.schema.register('$marker');
|
|
93
|
-
this.schema.addChildCheck((
|
|
94
|
-
if (childDefinition.name === '$marker') {
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
93
|
+
this.schema.addChildCheck(() => true, '$marker'); // Allow everywhere.
|
|
98
94
|
injectSelectionPostFixer(this);
|
|
99
95
|
// Post-fixer which takes care of adding empty paragraph elements to the empty roots.
|
|
100
96
|
this.document.registerPostFixer(autoParagraphEmptyRoots);
|