@ckeditor/ckeditor5-engine 34.2.0 → 35.1.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 (125) hide show
  1. package/CHANGELOG.md +823 -0
  2. package/LICENSE.md +4 -0
  3. package/package.json +32 -25
  4. package/src/controller/datacontroller.js +467 -561
  5. package/src/controller/editingcontroller.js +168 -204
  6. package/src/conversion/conversion.js +541 -565
  7. package/src/conversion/conversionhelpers.js +24 -28
  8. package/src/conversion/downcastdispatcher.js +457 -686
  9. package/src/conversion/downcasthelpers.js +1583 -1965
  10. package/src/conversion/mapper.js +518 -707
  11. package/src/conversion/modelconsumable.js +240 -283
  12. package/src/conversion/upcastdispatcher.js +372 -718
  13. package/src/conversion/upcasthelpers.js +707 -818
  14. package/src/conversion/viewconsumable.js +524 -581
  15. package/src/dataprocessor/basichtmlwriter.js +12 -16
  16. package/src/dataprocessor/dataprocessor.js +5 -0
  17. package/src/dataprocessor/htmldataprocessor.js +101 -117
  18. package/src/dataprocessor/htmlwriter.js +1 -18
  19. package/src/dataprocessor/xmldataprocessor.js +117 -138
  20. package/src/dev-utils/model.js +260 -352
  21. package/src/dev-utils/operationreplayer.js +106 -126
  22. package/src/dev-utils/utils.js +34 -51
  23. package/src/dev-utils/view.js +632 -753
  24. package/src/index.js +0 -11
  25. package/src/model/batch.js +111 -127
  26. package/src/model/differ.js +988 -1233
  27. package/src/model/document.js +340 -449
  28. package/src/model/documentfragment.js +327 -364
  29. package/src/model/documentselection.js +996 -1189
  30. package/src/model/element.js +306 -410
  31. package/src/model/history.js +224 -262
  32. package/src/model/item.js +5 -0
  33. package/src/model/liveposition.js +84 -145
  34. package/src/model/liverange.js +108 -185
  35. package/src/model/markercollection.js +379 -480
  36. package/src/model/model.js +883 -1034
  37. package/src/model/node.js +419 -463
  38. package/src/model/nodelist.js +175 -201
  39. package/src/model/operation/attributeoperation.js +153 -182
  40. package/src/model/operation/detachoperation.js +64 -83
  41. package/src/model/operation/insertoperation.js +135 -166
  42. package/src/model/operation/markeroperation.js +114 -140
  43. package/src/model/operation/mergeoperation.js +163 -191
  44. package/src/model/operation/moveoperation.js +157 -187
  45. package/src/model/operation/nooperation.js +28 -38
  46. package/src/model/operation/operation.js +106 -125
  47. package/src/model/operation/operationfactory.js +30 -34
  48. package/src/model/operation/renameoperation.js +109 -135
  49. package/src/model/operation/rootattributeoperation.js +155 -188
  50. package/src/model/operation/splitoperation.js +196 -232
  51. package/src/model/operation/transform.js +1833 -2204
  52. package/src/model/operation/utils.js +140 -204
  53. package/src/model/position.js +899 -1053
  54. package/src/model/range.js +910 -1028
  55. package/src/model/rootelement.js +77 -97
  56. package/src/model/schema.js +1189 -1835
  57. package/src/model/selection.js +745 -862
  58. package/src/model/text.js +90 -114
  59. package/src/model/textproxy.js +204 -240
  60. package/src/model/treewalker.js +316 -397
  61. package/src/model/typecheckable.js +16 -0
  62. package/src/model/utils/autoparagraphing.js +32 -44
  63. package/src/model/utils/deletecontent.js +334 -418
  64. package/src/model/utils/findoptimalinsertionrange.js +25 -36
  65. package/src/model/utils/getselectedcontent.js +96 -118
  66. package/src/model/utils/insertcontent.js +654 -773
  67. package/src/model/utils/insertobject.js +96 -119
  68. package/src/model/utils/modifyselection.js +120 -158
  69. package/src/model/utils/selection-post-fixer.js +153 -201
  70. package/src/model/writer.js +1305 -1474
  71. package/src/view/attributeelement.js +189 -225
  72. package/src/view/containerelement.js +75 -85
  73. package/src/view/document.js +172 -215
  74. package/src/view/documentfragment.js +200 -249
  75. package/src/view/documentselection.js +338 -367
  76. package/src/view/domconverter.js +1371 -1613
  77. package/src/view/downcastwriter.js +1747 -2076
  78. package/src/view/editableelement.js +81 -97
  79. package/src/view/element.js +739 -890
  80. package/src/view/elementdefinition.js +5 -0
  81. package/src/view/emptyelement.js +82 -92
  82. package/src/view/filler.js +35 -50
  83. package/src/view/item.js +5 -0
  84. package/src/view/matcher.js +260 -559
  85. package/src/view/node.js +274 -360
  86. package/src/view/observer/arrowkeysobserver.js +19 -28
  87. package/src/view/observer/bubblingemittermixin.js +120 -263
  88. package/src/view/observer/bubblingeventinfo.js +47 -55
  89. package/src/view/observer/clickobserver.js +7 -13
  90. package/src/view/observer/compositionobserver.js +14 -24
  91. package/src/view/observer/domeventdata.js +57 -67
  92. package/src/view/observer/domeventobserver.js +40 -64
  93. package/src/view/observer/fakeselectionobserver.js +81 -96
  94. package/src/view/observer/focusobserver.js +45 -61
  95. package/src/view/observer/inputobserver.js +7 -13
  96. package/src/view/observer/keyobserver.js +17 -27
  97. package/src/view/observer/mouseobserver.js +7 -14
  98. package/src/view/observer/mutationobserver.js +220 -315
  99. package/src/view/observer/observer.js +81 -102
  100. package/src/view/observer/selectionobserver.js +191 -246
  101. package/src/view/observer/tabobserver.js +23 -36
  102. package/src/view/placeholder.js +128 -173
  103. package/src/view/position.js +350 -401
  104. package/src/view/range.js +453 -513
  105. package/src/view/rawelement.js +85 -112
  106. package/src/view/renderer.js +874 -1014
  107. package/src/view/rooteditableelement.js +80 -90
  108. package/src/view/selection.js +608 -689
  109. package/src/view/styles/background.js +43 -44
  110. package/src/view/styles/border.js +220 -276
  111. package/src/view/styles/margin.js +8 -17
  112. package/src/view/styles/padding.js +8 -16
  113. package/src/view/styles/utils.js +127 -160
  114. package/src/view/stylesmap.js +728 -905
  115. package/src/view/text.js +102 -126
  116. package/src/view/textproxy.js +144 -170
  117. package/src/view/treewalker.js +383 -479
  118. package/src/view/typecheckable.js +19 -0
  119. package/src/view/uielement.js +166 -187
  120. package/src/view/upcastwriter.js +395 -449
  121. package/src/view/view.js +569 -664
  122. package/src/dataprocessor/dataprocessor.jsdoc +0 -64
  123. package/src/model/item.jsdoc +0 -14
  124. package/src/view/elementdefinition.jsdoc +0 -59
  125. package/src/view/item.jsdoc +0 -14
@@ -2,19 +2,15 @@
2
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
+ /* eslint-disable new-cap */
6
6
  /**
7
7
  * @module engine/view/document
8
8
  */
9
-
10
9
  import DocumentSelection from './documentselection';
11
10
  import Collection from '@ckeditor/ckeditor5-utils/src/collection';
12
- import mix from '@ckeditor/ckeditor5-utils/src/mix';
13
11
  import BubblingEmitterMixin from './observer/bubblingemittermixin';
14
- import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
15
-
12
+ import { Observable } from '@ckeditor/ckeditor5-utils/src/observablemixin';
16
13
  // @if CK_DEBUG_ENGINE // const { logDocument } = require( '../dev-utils/utils' );
17
-
18
14
  /**
19
15
  * Document class creates an abstract layer over the content editable area, contains a tree of view elements and
20
16
  * {@link module:engine/view/documentselection~DocumentSelection view selection} associated with this document.
@@ -22,213 +18,174 @@ import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
22
18
  * @mixes module:engine/view/observer/bubblingemittermixin~BubblingEmitterMixin
23
19
  * @mixes module:utils/observablemixin~ObservableMixin
24
20
  */
25
- export default class Document {
26
- /**
27
- * Creates a Document instance.
28
- *
29
- * @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor The styles processor instance.
30
- */
31
- constructor( stylesProcessor ) {
32
- /**
33
- * Selection done on this document.
34
- *
35
- * @readonly
36
- * @member {module:engine/view/documentselection~DocumentSelection} module:engine/view/document~Document#selection
37
- */
38
- this.selection = new DocumentSelection();
39
-
40
- /**
41
- * Roots of the view tree. Collection of the {@link module:engine/view/element~Element view elements}.
42
- *
43
- * View roots are created as a result of binding between {@link module:engine/view/document~Document#roots} and
44
- * {@link module:engine/model/document~Document#roots} and this is handled by
45
- * {@link module:engine/controller/editingcontroller~EditingController}, so to create view root we need to create
46
- * model root using {@link module:engine/model/document~Document#createRoot}.
47
- *
48
- * @readonly
49
- * @member {module:utils/collection~Collection} module:engine/view/document~Document#roots
50
- */
51
- this.roots = new Collection( { idProperty: 'rootName' } );
52
-
53
- /**
54
- * The styles processor instance used by this document when normalizing styles.
55
- *
56
- * @readonly
57
- * @member {module:engine/view/stylesmap~StylesProcessor}
58
- */
59
- this.stylesProcessor = stylesProcessor;
60
-
61
- /**
62
- * Defines whether document is in read-only mode.
63
- *
64
- * When document is read-ony then all roots are read-only as well and caret placed inside this root is hidden.
65
- *
66
- * @observable
67
- * @member {Boolean} #isReadOnly
68
- */
69
- this.set( 'isReadOnly', false );
70
-
71
- /**
72
- * True if document is focused.
73
- *
74
- * This property is updated by the {@link module:engine/view/observer/focusobserver~FocusObserver}.
75
- * If the {@link module:engine/view/observer/focusobserver~FocusObserver} is disabled this property will not change.
76
- *
77
- * @readonly
78
- * @observable
79
- * @member {Boolean} module:engine/view/document~Document#isFocused
80
- */
81
- this.set( 'isFocused', false );
82
-
83
- /**
84
- * `true` while the user is making a selection in the document (e.g. holding the mouse button and moving the cursor).
85
- * When they stop selecting, the property goes back to `false`.
86
- *
87
- * This property is updated by the {@link module:engine/view/observer/selectionobserver~SelectionObserver}.
88
- *
89
- * @readonly
90
- * @observable
91
- * @member {Boolean} module:engine/view/document~Document#isSelecting
92
- */
93
- this.set( 'isSelecting', false );
94
-
95
- /**
96
- * True if composition is in progress inside the document.
97
- *
98
- * This property is updated by the {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
99
- * If the {@link module:engine/view/observer/compositionobserver~CompositionObserver} is disabled this property will not change.
100
- *
101
- * @readonly
102
- * @observable
103
- * @member {Boolean} module:engine/view/document~Document#isComposing
104
- */
105
- this.set( 'isComposing', false );
106
-
107
- /**
108
- * Post-fixer callbacks registered to the view document.
109
- *
110
- * @private
111
- * @member {Set}
112
- */
113
- this._postFixers = new Set();
114
- }
115
-
116
- /**
117
- * Gets a {@link module:engine/view/document~Document#roots view root element} with the specified name. If the name is not
118
- * specific "main" root is returned.
119
- *
120
- * @param {String} [name='main'] Name of the root.
121
- * @returns {module:engine/view/rooteditableelement~RootEditableElement|null} The view root element with the specified name
122
- * or null when there is no root of given name.
123
- */
124
- getRoot( name = 'main' ) {
125
- return this.roots.get( name );
126
- }
127
-
128
- /**
129
- * Allows registering post-fixer callbacks. A post-fixers mechanism allows to update the view tree just before it is rendered
130
- * to the DOM.
131
- *
132
- * Post-fixers are executed right after all changes from the outermost change block were applied but
133
- * before the {@link module:engine/view/view~View#event:render render event} is fired. If a post-fixer callback made
134
- * a change, it should return `true`. When this happens, all post-fixers are fired again to check if something else should
135
- * not be fixed in the new document tree state.
136
- *
137
- * View post-fixers are useful when you want to apply some fixes whenever the view structure changes. Keep in mind that
138
- * changes executed in a view post-fixer should not break model-view mapping.
139
- *
140
- * The types of changes which should be safe:
141
- *
142
- * * adding or removing attribute from elements,
143
- * * changes inside of {@link module:engine/view/uielement~UIElement UI elements},
144
- * * {@link module:engine/controller/editingcontroller~EditingController#reconvertItem marking some of the model elements to be
145
- * re-converted}.
146
- *
147
- * Try to avoid changes which touch view structure:
148
- *
149
- * * you should not add or remove nor wrap or unwrap any view elements,
150
- * * you should not change the editor data model in a view post-fixer.
151
- *
152
- * As a parameter, a post-fixer callback receives a {@link module:engine/view/downcastwriter~DowncastWriter downcast writer}.
153
- *
154
- * Typically, a post-fixer will look like this:
155
- *
156
- * editor.editing.view.document.registerPostFixer( writer => {
157
- * if ( checkSomeCondition() ) {
158
- * writer.doSomething();
159
- *
160
- * // Let other post-fixers know that something changed.
161
- * return true;
162
- * }
163
- * } );
164
- *
165
- * Note that nothing happens right after you register a post-fixer (e.g. execute such a code in the console).
166
- * That is because adding a post-fixer does not execute it.
167
- * The post-fixer will be executed as soon as any change in the document needs to cause its rendering.
168
- * If you want to re-render the editor's view after registering the post-fixer then you should do it manually by calling
169
- * {@link module:engine/view/view~View#forceRender `view.forceRender()`}.
170
- *
171
- * If you need to register a callback which is executed when DOM elements are already updated,
172
- * use {@link module:engine/view/view~View#event:render render event}.
173
- *
174
- * @param {Function} postFixer
175
- */
176
- registerPostFixer( postFixer ) {
177
- this._postFixers.add( postFixer );
178
- }
179
-
180
- /**
181
- * Destroys this instance. Makes sure that all observers are destroyed and listeners removed.
182
- */
183
- destroy() {
184
- this.roots.map( root => root.destroy() );
185
- this.stopListening();
186
- }
187
-
188
- /**
189
- * Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model.
190
- *
191
- * @protected
192
- * @param {module:engine/view/downcastwriter~DowncastWriter} writer
193
- */
194
- _callPostFixers( writer ) {
195
- let wasFixed = false;
196
-
197
- do {
198
- for ( const callback of this._postFixers ) {
199
- wasFixed = callback( writer );
200
-
201
- if ( wasFixed ) {
202
- break;
203
- }
204
- }
205
- } while ( wasFixed );
206
- }
207
-
208
- /**
209
- * Event fired whenever document content layout changes. It is fired whenever content is
210
- * {@link module:engine/view/view~View#event:render rendered}, but should be also fired by observers in case of
211
- * other actions which may change layout, for instance when image loads.
212
- *
213
- * @event layoutChanged
214
- */
215
-
216
- // @if CK_DEBUG_ENGINE // log( version ) {
217
- // @if CK_DEBUG_ENGINE // logDocument( this, version );
218
- // @if CK_DEBUG_ENGINE // }
21
+ export default class Document extends BubblingEmitterMixin(Observable) {
22
+ /**
23
+ * Creates a Document instance.
24
+ *
25
+ * @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor The styles processor instance.
26
+ */
27
+ constructor(stylesProcessor) {
28
+ super();
29
+ /**
30
+ * Selection done on this document.
31
+ *
32
+ * @readonly
33
+ * @member {module:engine/view/documentselection~DocumentSelection} module:engine/view/document~Document#selection
34
+ */
35
+ this.selection = new DocumentSelection();
36
+ /**
37
+ * Roots of the view tree. Collection of the {@link module:engine/view/element~Element view elements}.
38
+ *
39
+ * View roots are created as a result of binding between {@link module:engine/view/document~Document#roots} and
40
+ * {@link module:engine/model/document~Document#roots} and this is handled by
41
+ * {@link module:engine/controller/editingcontroller~EditingController}, so to create view root we need to create
42
+ * model root using {@link module:engine/model/document~Document#createRoot}.
43
+ *
44
+ * @readonly
45
+ * @member {module:utils/collection~Collection} module:engine/view/document~Document#roots
46
+ */
47
+ this.roots = new Collection({ idProperty: 'rootName' });
48
+ /**
49
+ * The styles processor instance used by this document when normalizing styles.
50
+ *
51
+ * @readonly
52
+ * @member {module:engine/view/stylesmap~StylesProcessor}
53
+ */
54
+ this.stylesProcessor = stylesProcessor;
55
+ /**
56
+ * Defines whether document is in read-only mode.
57
+ *
58
+ * When document is read-ony then all roots are read-only as well and caret placed inside this root is hidden.
59
+ *
60
+ * @observable
61
+ * @member {Boolean} #isReadOnly
62
+ */
63
+ this.set('isReadOnly', false);
64
+ /**
65
+ * True if document is focused.
66
+ *
67
+ * This property is updated by the {@link module:engine/view/observer/focusobserver~FocusObserver}.
68
+ * If the {@link module:engine/view/observer/focusobserver~FocusObserver} is disabled this property will not change.
69
+ *
70
+ * @readonly
71
+ * @observable
72
+ * @member {Boolean} module:engine/view/document~Document#isFocused
73
+ */
74
+ this.set('isFocused', false);
75
+ /**
76
+ * `true` while the user is making a selection in the document (e.g. holding the mouse button and moving the cursor).
77
+ * When they stop selecting, the property goes back to `false`.
78
+ *
79
+ * This property is updated by the {@link module:engine/view/observer/selectionobserver~SelectionObserver}.
80
+ *
81
+ * @readonly
82
+ * @observable
83
+ * @member {Boolean} module:engine/view/document~Document#isSelecting
84
+ */
85
+ this.set('isSelecting', false);
86
+ /**
87
+ * True if composition is in progress inside the document.
88
+ *
89
+ * This property is updated by the {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
90
+ * If the {@link module:engine/view/observer/compositionobserver~CompositionObserver} is disabled this property will not change.
91
+ *
92
+ * @readonly
93
+ * @observable
94
+ * @member {Boolean} module:engine/view/document~Document#isComposing
95
+ */
96
+ this.set('isComposing', false);
97
+ /**
98
+ * Post-fixer callbacks registered to the view document.
99
+ *
100
+ * @private
101
+ * @member {Set}
102
+ */
103
+ this._postFixers = new Set();
104
+ }
105
+ /**
106
+ * Gets a {@link module:engine/view/document~Document#roots view root element} with the specified name. If the name is not
107
+ * specific "main" root is returned.
108
+ *
109
+ * @param {String} [name='main'] Name of the root.
110
+ * @returns {module:engine/view/rooteditableelement~RootEditableElement|null} The view root element with the specified name
111
+ * or null when there is no root of given name.
112
+ */
113
+ getRoot(name = 'main') {
114
+ return this.roots.get(name);
115
+ }
116
+ /**
117
+ * Allows registering post-fixer callbacks. A post-fixers mechanism allows to update the view tree just before it is rendered
118
+ * to the DOM.
119
+ *
120
+ * Post-fixers are executed right after all changes from the outermost change block were applied but
121
+ * before the {@link module:engine/view/view~View#event:render render event} is fired. If a post-fixer callback made
122
+ * a change, it should return `true`. When this happens, all post-fixers are fired again to check if something else should
123
+ * not be fixed in the new document tree state.
124
+ *
125
+ * View post-fixers are useful when you want to apply some fixes whenever the view structure changes. Keep in mind that
126
+ * changes executed in a view post-fixer should not break model-view mapping.
127
+ *
128
+ * The types of changes which should be safe:
129
+ *
130
+ * * adding or removing attribute from elements,
131
+ * * changes inside of {@link module:engine/view/uielement~UIElement UI elements},
132
+ * * {@link module:engine/controller/editingcontroller~EditingController#reconvertItem marking some of the model elements to be
133
+ * re-converted}.
134
+ *
135
+ * Try to avoid changes which touch view structure:
136
+ *
137
+ * * you should not add or remove nor wrap or unwrap any view elements,
138
+ * * you should not change the editor data model in a view post-fixer.
139
+ *
140
+ * As a parameter, a post-fixer callback receives a {@link module:engine/view/downcastwriter~DowncastWriter downcast writer}.
141
+ *
142
+ * Typically, a post-fixer will look like this:
143
+ *
144
+ * editor.editing.view.document.registerPostFixer( writer => {
145
+ * if ( checkSomeCondition() ) {
146
+ * writer.doSomething();
147
+ *
148
+ * // Let other post-fixers know that something changed.
149
+ * return true;
150
+ * }
151
+ * } );
152
+ *
153
+ * Note that nothing happens right after you register a post-fixer (e.g. execute such a code in the console).
154
+ * That is because adding a post-fixer does not execute it.
155
+ * The post-fixer will be executed as soon as any change in the document needs to cause its rendering.
156
+ * If you want to re-render the editor's view after registering the post-fixer then you should do it manually by calling
157
+ * {@link module:engine/view/view~View#forceRender `view.forceRender()`}.
158
+ *
159
+ * If you need to register a callback which is executed when DOM elements are already updated,
160
+ * use {@link module:engine/view/view~View#event:render render event}.
161
+ *
162
+ * @param {Function} postFixer
163
+ */
164
+ registerPostFixer(postFixer) {
165
+ this._postFixers.add(postFixer);
166
+ }
167
+ /**
168
+ * Destroys this instance. Makes sure that all observers are destroyed and listeners removed.
169
+ */
170
+ destroy() {
171
+ this.roots.map(root => root.destroy());
172
+ this.stopListening();
173
+ }
174
+ /**
175
+ * Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model.
176
+ *
177
+ * @protected
178
+ * @param {module:engine/view/downcastwriter~DowncastWriter} writer
179
+ */
180
+ _callPostFixers(writer) {
181
+ let wasFixed = false;
182
+ do {
183
+ for (const callback of this._postFixers) {
184
+ wasFixed = callback(writer);
185
+ if (wasFixed) {
186
+ break;
187
+ }
188
+ }
189
+ } while (wasFixed);
190
+ }
219
191
  }
220
-
221
- mix( Document, BubblingEmitterMixin );
222
- mix( Document, ObservableMixin );
223
-
224
- /**
225
- * Enum representing type of the change.
226
- *
227
- * Possible values:
228
- *
229
- * * `children` - for child list changes,
230
- * * `attributes` - for element attributes changes,
231
- * * `text` - for text nodes changes.
232
- *
233
- * @typedef {String} module:engine/view/document~ChangeType
234
- */