@ckeditor/ckeditor5-engine 31.1.0 → 34.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE.md +2 -2
  2. package/README.md +2 -1
  3. package/package.json +25 -25
  4. package/src/controller/datacontroller.js +65 -74
  5. package/src/controller/editingcontroller.js +83 -6
  6. package/src/conversion/conversion.js +15 -14
  7. package/src/conversion/conversionhelpers.js +1 -1
  8. package/src/conversion/downcastdispatcher.js +298 -367
  9. package/src/conversion/downcasthelpers.js +860 -81
  10. package/src/conversion/mapper.js +105 -60
  11. package/src/conversion/modelconsumable.js +85 -35
  12. package/src/conversion/upcastdispatcher.js +34 -7
  13. package/src/conversion/upcasthelpers.js +4 -2
  14. package/src/conversion/viewconsumable.js +1 -1
  15. package/src/dataprocessor/basichtmlwriter.js +1 -1
  16. package/src/dataprocessor/dataprocessor.jsdoc +1 -1
  17. package/src/dataprocessor/htmldataprocessor.js +9 -31
  18. package/src/dataprocessor/htmlwriter.js +1 -1
  19. package/src/dataprocessor/xmldataprocessor.js +1 -1
  20. package/src/dev-utils/model.js +16 -14
  21. package/src/dev-utils/operationreplayer.js +1 -1
  22. package/src/dev-utils/utils.js +1 -1
  23. package/src/dev-utils/view.js +1 -1
  24. package/src/index.js +8 -1
  25. package/src/model/batch.js +77 -10
  26. package/src/model/differ.js +115 -69
  27. package/src/model/document.js +13 -4
  28. package/src/model/documentfragment.js +1 -1
  29. package/src/model/documentselection.js +1 -1
  30. package/src/model/element.js +1 -1
  31. package/src/model/history.js +1 -1
  32. package/src/model/item.jsdoc +1 -1
  33. package/src/model/liveposition.js +1 -1
  34. package/src/model/liverange.js +1 -1
  35. package/src/model/markercollection.js +29 -5
  36. package/src/model/model.js +138 -12
  37. package/src/model/node.js +1 -1
  38. package/src/model/nodelist.js +1 -1
  39. package/src/model/operation/attributeoperation.js +1 -1
  40. package/src/model/operation/detachoperation.js +1 -1
  41. package/src/model/operation/insertoperation.js +1 -1
  42. package/src/model/operation/markeroperation.js +1 -1
  43. package/src/model/operation/mergeoperation.js +1 -1
  44. package/src/model/operation/moveoperation.js +1 -1
  45. package/src/model/operation/nooperation.js +1 -1
  46. package/src/model/operation/operation.js +1 -1
  47. package/src/model/operation/operationfactory.js +1 -1
  48. package/src/model/operation/renameoperation.js +1 -1
  49. package/src/model/operation/rootattributeoperation.js +1 -1
  50. package/src/model/operation/splitoperation.js +1 -1
  51. package/src/model/operation/transform.js +1 -1
  52. package/src/model/operation/utils.js +1 -1
  53. package/src/model/position.js +1 -1
  54. package/src/model/range.js +1 -1
  55. package/src/model/rootelement.js +1 -1
  56. package/src/model/schema.js +80 -11
  57. package/src/model/selection.js +1 -1
  58. package/src/model/text.js +1 -1
  59. package/src/model/textproxy.js +1 -1
  60. package/src/model/treewalker.js +3 -4
  61. package/src/model/utils/autoparagraphing.js +1 -1
  62. package/src/model/utils/deletecontent.js +16 -3
  63. package/src/model/utils/findoptimalinsertionrange.js +68 -0
  64. package/src/model/utils/getselectedcontent.js +1 -1
  65. package/src/model/utils/insertcontent.js +1 -1
  66. package/src/model/utils/insertobject.js +173 -0
  67. package/src/model/utils/modifyselection.js +15 -8
  68. package/src/model/utils/selection-post-fixer.js +1 -1
  69. package/src/model/writer.js +17 -27
  70. package/src/view/attributeelement.js +1 -11
  71. package/src/view/containerelement.js +1 -1
  72. package/src/view/document.js +3 -2
  73. package/src/view/documentfragment.js +1 -1
  74. package/src/view/documentselection.js +1 -1
  75. package/src/view/domconverter.js +55 -28
  76. package/src/view/downcastwriter.js +91 -50
  77. package/src/view/editableelement.js +1 -1
  78. package/src/view/element.js +1 -28
  79. package/src/view/elementdefinition.jsdoc +1 -1
  80. package/src/view/emptyelement.js +1 -4
  81. package/src/view/filler.js +1 -1
  82. package/src/view/item.jsdoc +1 -1
  83. package/src/view/matcher.js +3 -3
  84. package/src/view/node.js +1 -1
  85. package/src/view/observer/arrowkeysobserver.js +1 -1
  86. package/src/view/observer/bubblingemittermixin.js +1 -1
  87. package/src/view/observer/bubblingeventinfo.js +1 -1
  88. package/src/view/observer/clickobserver.js +1 -2
  89. package/src/view/observer/compositionobserver.js +1 -1
  90. package/src/view/observer/domeventdata.js +1 -1
  91. package/src/view/observer/domeventobserver.js +1 -1
  92. package/src/view/observer/fakeselectionobserver.js +1 -1
  93. package/src/view/observer/focusobserver.js +1 -1
  94. package/src/view/observer/inputobserver.js +2 -2
  95. package/src/view/observer/keyobserver.js +1 -1
  96. package/src/view/observer/mouseobserver.js +1 -1
  97. package/src/view/observer/mutationobserver.js +1 -1
  98. package/src/view/observer/observer.js +1 -1
  99. package/src/view/observer/selectionobserver.js +1 -1
  100. package/src/view/observer/tabobserver.js +68 -0
  101. package/src/view/placeholder.js +2 -2
  102. package/src/view/position.js +1 -1
  103. package/src/view/range.js +1 -1
  104. package/src/view/rawelement.js +1 -4
  105. package/src/view/renderer.js +3 -2
  106. package/src/view/rooteditableelement.js +1 -1
  107. package/src/view/selection.js +1 -1
  108. package/src/view/styles/background.js +1 -1
  109. package/src/view/styles/border.js +1 -1
  110. package/src/view/styles/margin.js +1 -1
  111. package/src/view/styles/padding.js +1 -1
  112. package/src/view/styles/utils.js +1 -1
  113. package/src/view/stylesmap.js +1 -1
  114. package/src/view/text.js +1 -1
  115. package/src/view/textproxy.js +1 -1
  116. package/src/view/treewalker.js +1 -1
  117. package/src/view/uielement.js +1 -4
  118. package/src/view/upcastwriter.js +1 -1
  119. package/src/view/view.js +5 -1
  120. package/theme/placeholder.css +10 -1
  121. package/theme/renderer.css +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -21,6 +21,7 @@ import ModelSelection from './selection';
21
21
  import OperationFactory from './operation/operationfactory';
22
22
 
23
23
  import insertContent from './utils/insertcontent';
24
+ import insertObject from './utils/insertobject';
24
25
  import deleteContent from './utils/deletecontent';
25
26
  import modifySelection from './utils/modifyselection';
26
27
  import getSelectedContent from './utils/getselectedcontent';
@@ -80,7 +81,7 @@ export default class Model {
80
81
  */
81
82
  this._currentWriter = null;
82
83
 
83
- [ 'insertContent', 'deleteContent', 'modifySelection', 'getSelectedContent', 'applyOperation' ]
84
+ [ 'insertContent', 'insertObject', 'deleteContent', 'modifySelection', 'getSelectedContent', 'applyOperation' ]
84
85
  .forEach( methodName => this.decorate( methodName ) );
85
86
 
86
87
  // Adding operation validation with `highest` priority, so it is called before any other feature would like
@@ -96,11 +97,28 @@ export default class Model {
96
97
  isLimit: true
97
98
  } );
98
99
 
100
+ this.schema.register( '$container', {
101
+ allowIn: [ '$root', '$container' ]
102
+ } );
103
+
99
104
  this.schema.register( '$block', {
100
- allowIn: '$root',
105
+ allowIn: [ '$root', '$container' ],
101
106
  isBlock: true
102
107
  } );
103
108
 
109
+ this.schema.register( '$blockObject', {
110
+ allowWhere: '$block',
111
+ isBlock: true,
112
+ isObject: true
113
+ } );
114
+
115
+ this.schema.register( '$inlineObject', {
116
+ allowWhere: '$text',
117
+ allowAttributesOf: '$text',
118
+ isInline: true,
119
+ isObject: true
120
+ } );
121
+
104
122
  this.schema.register( '$text', {
105
123
  allowIn: '$block',
106
124
  isInline: true,
@@ -214,8 +232,13 @@ export default class Model {
214
232
  * done in the outer `change()` block.
215
233
  *
216
234
  * Second, it lets you define the {@link module:engine/model/batch~Batch} into which you want to add your changes.
217
- * By default, a new batch is created. In the sample above, `change` and `enqueueChange` blocks use a different
218
- * batch (and different {@link module:engine/model/writer~Writer} since each of them operates on the separate batch).
235
+ * By default, a new batch with the default {@link module:engine/model/batch~Batch#constructor batch type} is created.
236
+ * In the sample above, the `change` and `enqueueChange` blocks will use a different batch (and a different
237
+ * {@link module:engine/model/writer~Writer} instance since each of them operates on a separate batch).
238
+ *
239
+ * model.enqueueChange( { isUndoable: false }, writer => {
240
+ * writer.insertText( 'foo', paragraph, 'end' );
241
+ * } );
219
242
  *
220
243
  * When using the `enqueueChange()` block you can also add some changes to the batch you used before.
221
244
  *
@@ -226,17 +249,20 @@ export default class Model {
226
249
  * In order to make a nested `enqueueChange()` create a single undo step together with the changes done in the outer `change()`
227
250
  * block, you can obtain the batch instance from the {@link module:engine/model/writer~Writer#batch writer} of the outer block.
228
251
  *
229
- * @param {module:engine/model/batch~Batch|'transparent'|'default'} batchOrType Batch or batch type should be used in the callback.
230
- * If not defined, a new batch will be created.
252
+ * @param {module:engine/model/batch~Batch|Object} [batchOrType] A batch or a
253
+ * {@link module:engine/model/batch~Batch#constructor batch type} that should be used in the callback. If not defined, a new batch with
254
+ * the default type will be created.
231
255
  * @param {Function} callback Callback function which may modify the model.
232
256
  */
233
257
  enqueueChange( batchOrType, callback ) {
234
258
  try {
235
- if ( typeof batchOrType === 'string' ) {
236
- batchOrType = new Batch( batchOrType );
237
- } else if ( typeof batchOrType == 'function' ) {
259
+ if ( !batchOrType ) {
260
+ batchOrType = new Batch();
261
+ } else if ( typeof batchOrType === 'function' ) {
238
262
  callback = batchOrType;
239
263
  batchOrType = new Batch();
264
+ } else if ( !( batchOrType instanceof Batch ) ) {
265
+ batchOrType = new Batch( batchOrType );
240
266
  }
241
267
 
242
268
  this._pendingChanges.push( { batch: batchOrType, callback } );
@@ -296,6 +322,9 @@ export default class Model {
296
322
  * Inserts content at the position in the editor specified by the selection, as one would expect the paste
297
323
  * functionality to work.
298
324
  *
325
+ * **Note**: If you want to insert an {@glink framework/guides/deep-dive/schema#object-elements object element}
326
+ * (e.g. a {@link module:widget/utils~toWidget widget}), see {@link #insertObject} instead.
327
+ *
299
328
  * This is a high-level method. It takes the {@link #schema schema} into consideration when inserting
300
329
  * the content, clears the given selection's content before inserting nodes and moves the selection
301
330
  * to its target position at the end of the process.
@@ -427,6 +456,89 @@ export default class Model {
427
456
  return insertContent( this, content, selectable, placeOrOffset );
428
457
  }
429
458
 
459
+ /**
460
+ * Inserts an {@glink framework/guides/deep-dive/schema#object-elements object element} at a specific position in the editor content.
461
+ *
462
+ * This is a high-level API:
463
+ * * It takes the {@link #schema schema} into consideration,
464
+ * * It clears the content of passed `selectable` before inserting,
465
+ * * It can move the selection at the end of the process,
466
+ * * It will copy the selected block's attributes to preserve them upon insertion,
467
+ * * It can split elements or wrap inline objects with paragraphs if they are not allowed in target position,
468
+ * * etc.
469
+ *
470
+ * # Notes
471
+ *
472
+ * * If you want to insert a non-object content, see {@link #insertContent} instead.
473
+ * * For lower-level API, see {@link module:engine/model/writer~Writer `Writer`}.
474
+ * * Unlike {@link module:engine/model/writer~Writer `Writer`}, this method does not have to be used inside
475
+ * a {@link #change `change()` block}.
476
+ * * Inserting object into the model is not enough to make CKEditor 5 render that content to the user.
477
+ * CKEditor 5 implements a model-view-controller architecture and what `model.insertObject()` does
478
+ * is only adding nodes to the model. Additionally, you need to define
479
+ * {@glink framework/guides/architecture/editing-engine#conversion converters} between the model and view
480
+ * and define those nodes in the {@glink framework/guides/architecture/editing-engine#schema schema}.
481
+ *
482
+ * # Examples
483
+ *
484
+ * Use the following code to insert an object at the current selection and keep the selection on the inserted element:
485
+ *
486
+ * const rawHtmlEmbedElement = writer.createElement( 'rawHtml' );
487
+ *
488
+ * model.insertObject( rawHtmlEmbedElement, null, null, {
489
+ * setSelection: 'on'
490
+ * } );
491
+ *
492
+ * Use the following code to insert an object at the current selection and nudge the selection after the inserted object:
493
+ *
494
+ * const pageBreakElement = writer.createElement( 'pageBreak' );
495
+ *
496
+ * model.insertObject( pageBreakElement, null, null, {
497
+ * setSelection: 'after'
498
+ * } );
499
+ *
500
+ * Use the following code to insert an object at the current selection and avoid splitting the content (non-destructive insertion):
501
+ *
502
+ * const tableElement = writer.createElement( 'table' );
503
+ *
504
+ * model.insertObject( tableElement, null, null, {
505
+ * findOptimalPosition: 'auto'
506
+ * } );
507
+ *
508
+ * Use the following code to insert an object at the specific range (also: replace the content of the range):
509
+ *
510
+ * const tableElement = writer.createElement( 'table' );
511
+ * const range = model.createRangeOn( model.document.getRoot().getChild( 1 ) );
512
+ *
513
+ * model.insertObject( tableElement, range );
514
+ *
515
+ * @param {module:engine/model/element~Element} object An object to be inserted into the model document.
516
+ * @param {module:engine/model/selection~Selectable} [selectable=model.document.selection]
517
+ * A selectable where the content should be inserted. If not specified, the current
518
+ * {@link module:engine/model/document~Document#selection document selection} will be used instead.
519
+ * @param {Number|'before'|'end'|'after'|'on'|'in'} placeOrOffset Specifies the exact place or offset for the insertion to take place,
520
+ * relative to `selectable`.
521
+ * @param {Object} [options] Additional options.
522
+ * @param {'auto'|'before'|'after'} [options.findOptimalPosition] An option that, when set, adjusts the insertion position (relative to
523
+ * `selectable` and `placeOrOffset`) so that the content of `selectable` is not split upon insertion (a.k.a. non-destructive insertion).
524
+ * * When `'auto'`, the algorithm will decide whether to insert the object before or after `selectable` to avoid content splitting.
525
+ * * When `'before'`, the closest position before `selectable` will be used that will not result in content splitting.
526
+ * * When `'after'`, the closest position after `selectable` will be used that will not result in content splitting.
527
+ *
528
+ * Note that this option works only for block objects. Inline objects are inserted into text and do not split blocks.
529
+ * @param {'on'|'after'} [options.setSelection] An option that, when set, moves the
530
+ * {@link module:engine/model/document~Document#selection document selection} after inserting the object.
531
+ * * When `'on'`, the document selection will be set on the inserted object.
532
+ * * When `'after'`, the document selection will move to the closest text node after the inserted object. If there is no
533
+ * such text node, a paragraph will be created and the document selection will be moved inside it.
534
+ * @returns {module:engine/model/range~Range} A range which contains all the performed changes. This is a range that, if removed,
535
+ * would return the model to the state before the insertion. If no changes were preformed by `insertObject()`, returns a range collapsed
536
+ * at the insertion position.
537
+ */
538
+ insertObject( object, selectable, placeOrOffset, options ) {
539
+ return insertObject( this, object, selectable, placeOrOffset, options );
540
+ }
541
+
430
542
  /**
431
543
  * Deletes content of the selection and merge siblings. The resulting selection is always collapsed.
432
544
  *
@@ -508,6 +620,7 @@ export default class Model {
508
620
  * @param {Object} [options]
509
621
  * @param {'forward'|'backward'} [options.direction='forward'] The direction in which the selection should be modified.
510
622
  * @param {'character'|'codePoint'|'word'} [options.unit='character'] The unit by which selection should be modified.
623
+ * @param {Boolean} [options.treatEmojiAsSingleUnit=false] Whether multi-characer emoji sequences should be handled as single unit.
511
624
  */
512
625
  modifySelection( selection, options ) {
513
626
  modifySelection( this, selection, options );
@@ -791,7 +904,7 @@ export default class Model {
791
904
  * * {@link #change `change()`},
792
905
  * * {@link #enqueueChange `enqueueChange()`}.
793
906
  *
794
- * @param {'transparent'|'default'} [type='default'] The type of the batch.
907
+ * @param {Object} [type] {@link module:engine/model/batch~Batch#constructor The type} of the batch.
795
908
  * @returns {module:engine/model/batch~Batch}
796
909
  */
797
910
  createBatch( type ) {
@@ -894,12 +1007,25 @@ export default class Model {
894
1007
  * listener to this event so it can be fully customized by the features.
895
1008
  *
896
1009
  * **Note** The `selectable` parameter for the {@link #insertContent} is optional. When `undefined` value is passed the method uses
897
- * `model.document.selection`.
1010
+ * {@link module:engine/model/document~Document#selection document selection}.
898
1011
  *
899
1012
  * @event insertContent
900
1013
  * @param {Array} args The arguments passed to the original method.
901
1014
  */
902
1015
 
1016
+ /**
1017
+ * Event fired when {@link #insertObject} method is called.
1018
+ *
1019
+ * The {@link #insertObject default action of that method} is implemented as a
1020
+ * listener to this event so it can be fully customized by the features.
1021
+ *
1022
+ * **Note** The `selectable` parameter for the {@link #insertObject} is optional. When `undefined` value is passed the method uses
1023
+ * {@link module:engine/model/document~Document#selection document selection}.
1024
+ *
1025
+ * @event insertObject
1026
+ * @param {Array} args The arguments passed to the original method.
1027
+ */
1028
+
903
1029
  /**
904
1030
  * Event fired when {@link #deleteContent} method is called.
905
1031
  *
package/src/model/node.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -834,6 +834,23 @@ export default class Schema {
834
834
  return null;
835
835
  }
836
836
 
837
+ /**
838
+ * Sets attributes allowed by the schema on given node.
839
+ *
840
+ * @param {module:engine/model/node~Node} node A node to set attributes on.
841
+ * @param {Object} attributes Attributes keys and values.
842
+ * @param {module:engine/model/writer~Writer} writer An instance of the model writer.
843
+ */
844
+ setAllowedAttributes( node, attributes, writer ) {
845
+ const model = writer.model;
846
+
847
+ for ( const [ attributeName, attributeValue ] of Object.entries( attributes ) ) {
848
+ if ( model.schema.checkAttribute( node, attributeName ) ) {
849
+ writer.setAttribute( attributeName, attributeValue, node );
850
+ }
851
+ }
852
+ }
853
+
837
854
  /**
838
855
  * Removes attributes disallowed by the schema.
839
856
  *
@@ -863,6 +880,34 @@ export default class Schema {
863
880
  }
864
881
  }
865
882
 
883
+ /**
884
+ * Gets attributes of a node that have given property.
885
+ *
886
+ * @param {module:engine/model/node~Node} node Node to get attributes from.
887
+ * @param {String} propertyName Name of the property that attribute must have to return it.
888
+ * @param {Boolean|Symbol|String|Number|Object|null|undefined} propertyValue Desired value of the property that we want to check.
889
+ * When `undefined` attributes will be returned if they have set a given property no matter what the value is. If specified it will
890
+ * return attributes which given property's value is equal to this parameter.
891
+ * @returns {Object} Object with attributes' names as key and attributes' values as value.
892
+ */
893
+ getAttributesWithProperty( node, propertyName, propertyValue ) {
894
+ const attributes = {};
895
+
896
+ for ( const [ attributeName, attributeValue ] of node.getAttributes() ) {
897
+ const attributeProperties = this.getAttributeProperties( attributeName );
898
+
899
+ if ( attributeProperties[ propertyName ] === undefined ) {
900
+ continue;
901
+ }
902
+
903
+ if ( propertyValue === undefined || propertyValue === attributeProperties[ propertyName ] ) {
904
+ attributes[ attributeName ] = attributeValue;
905
+ }
906
+ }
907
+
908
+ return attributes;
909
+ }
910
+
866
911
  /**
867
912
  * Creates an instance of the schema context.
868
913
  *
@@ -1135,19 +1180,39 @@ mix( Schema, ObservableMixin );
1135
1180
  *
1136
1181
  * # Generic items
1137
1182
  *
1138
- * There are three basic generic items: `$root`, `$block` and `$text`.
1139
- * They are defined as follows:
1183
+ * There are several generic items (classes of elements) available: `$root`, `$container`, `$block`, `$blockObject`,
1184
+ * `$inlineObject`, and `$text`. They are defined as follows:
1140
1185
  *
1141
- * this.schema.register( '$root', {
1186
+ * schema.register( '$root', {
1142
1187
  * isLimit: true
1143
1188
  * } );
1144
- * this.schema.register( '$block', {
1145
- * allowIn: '$root',
1189
+ *
1190
+ * schema.register( '$container', {
1191
+ * allowIn: [ '$root', '$container' ]
1192
+ * } );
1193
+ *
1194
+ * schema.register( '$block', {
1195
+ * allowIn: [ '$root', '$container' ],
1146
1196
  * isBlock: true
1147
1197
  * } );
1148
- * this.schema.register( '$text', {
1198
+ *
1199
+ * schema.register( '$blockObject', {
1200
+ * allowWhere: '$block',
1201
+ * isBlock: true,
1202
+ * isObject: true
1203
+ * } );
1204
+ *
1205
+ * schema.register( '$inlineObject', {
1206
+ * allowWhere: '$text',
1207
+ * allowAttributesOf: '$text',
1208
+ * isInline: true,
1209
+ * isObject: true
1210
+ * } );
1211
+ *
1212
+ * schema.register( '$text', {
1149
1213
  * allowIn: '$block',
1150
- * isInline: true
1214
+ * isInline: true,
1215
+ * isContent: true
1151
1216
  * } );
1152
1217
  *
1153
1218
  * They reflect typical editor content that is contained within one root, consists of several blocks
@@ -1180,14 +1245,18 @@ mix( Schema, ObservableMixin );
1180
1245
  * isBlock: true
1181
1246
  * } );
1182
1247
  *
1248
+ * The previous rule can be written in a shorter form using inheritance:
1249
+ *
1250
+ * schema.register( 'paragraph', {
1251
+ * inheritAllFrom: '$block'
1252
+ * } );
1253
+ *
1183
1254
  * Make `imageBlock` a block object, which is allowed everywhere where `$block` is.
1184
1255
  * Also, allow `src` and `alt` attributes in it:
1185
1256
  *
1186
1257
  * schema.register( 'imageBlock', {
1187
- * allowWhere: '$block',
1258
+ * inheritAllFrom: '$blockObject',
1188
1259
  * allowAttributes: [ 'src', 'alt' ],
1189
- * isBlock: true,
1190
- * isObject: true
1191
1260
  * } );
1192
1261
  *
1193
1262
  * Make `caption` allowed in `imageBlock` and make it allow all the content of `$block`s (usually, `$text`).
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
package/src/model/text.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -233,9 +233,8 @@ export default class TreeWalker {
233
233
 
234
234
  // Get node just after the current position.
235
235
  // Use a highly optimized version instead of checking the text node first and then getting the node after. See #6582.
236
- const positionParent = position.parent;
237
- const textNodeAtPosition = getTextNodeAtPosition( position, positionParent );
238
- const node = textNodeAtPosition ? textNodeAtPosition : getNodeAfterPosition( position, positionParent, textNodeAtPosition );
236
+ const textNodeAtPosition = getTextNodeAtPosition( position, parent );
237
+ const node = textNodeAtPosition ? textNodeAtPosition : getNodeAfterPosition( position, parent, textNodeAtPosition );
239
238
 
240
239
  if ( node instanceof Element ) {
241
240
  if ( !this.shallow ) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -80,6 +80,17 @@ export default function deleteContent( model, selection, options = {} ) {
80
80
  return;
81
81
  }
82
82
 
83
+ // Collect attributes to copy in case of autoparagraphing.
84
+ const attributesForAutoparagraph = {};
85
+
86
+ if ( !options.doNotAutoparagraph ) {
87
+ const selectedElement = selection.getSelectedElement();
88
+
89
+ if ( selectedElement ) {
90
+ Object.assign( attributesForAutoparagraph, schema.getAttributesWithProperty( selectedElement, 'copyOnReplace', true ) );
91
+ }
92
+ }
93
+
83
94
  // Get the live positions for the range adjusted to span only blocks selected from the user perspective.
84
95
  const [ startPosition, endPosition ] = getLivePositionsForSelectedBlocks( selRange );
85
96
 
@@ -114,7 +125,7 @@ export default function deleteContent( model, selection, options = {} ) {
114
125
  // Check if a text is allowed in the new container. If not, try to create a new paragraph (if it's allowed here).
115
126
  // If autoparagraphing is off, we assume that you know what you do so we leave the selection wherever it was.
116
127
  if ( !options.doNotAutoparagraph && shouldAutoparagraph( schema, startPosition ) ) {
117
- insertParagraph( writer, startPosition, selection );
128
+ insertParagraph( writer, startPosition, selection, attributesForAutoparagraph );
118
129
  }
119
130
 
120
131
  startPosition.detach();
@@ -482,9 +493,11 @@ function isCrossingLimitElement( leftPos, rightPos, schema ) {
482
493
  return true;
483
494
  }
484
495
 
485
- function insertParagraph( writer, position, selection ) {
496
+ function insertParagraph( writer, position, selection, attributes = {} ) {
486
497
  const paragraph = writer.createElement( 'paragraph' );
487
498
 
499
+ writer.model.schema.setAllowedAttributes( paragraph, attributes, writer );
500
+
488
501
  writer.insert( paragraph, position );
489
502
 
490
503
  collapseSelectionAt( writer, selection, writer.createPositionAt( paragraph, 0 ) );