@ckeditor/ckeditor5-engine 38.2.0-alpha.1 → 39.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 (212) hide show
  1. package/README.md +0 -1
  2. package/package.json +3 -4
  3. package/src/controller/datacontroller.d.ts +15 -15
  4. package/src/controller/datacontroller.js +11 -11
  5. package/src/controller/editingcontroller.d.ts +7 -7
  6. package/src/controller/editingcontroller.js +8 -8
  7. package/src/conversion/conversion.d.ts +6 -6
  8. package/src/conversion/conversion.js +2 -2
  9. package/src/conversion/downcastdispatcher.d.ts +28 -13
  10. package/src/conversion/downcastdispatcher.js +30 -21
  11. package/src/conversion/downcasthelpers.d.ts +21 -21
  12. package/src/conversion/downcasthelpers.js +11 -11
  13. package/src/conversion/mapper.d.ts +9 -9
  14. package/src/conversion/mapper.js +5 -5
  15. package/src/conversion/modelconsumable.d.ts +5 -5
  16. package/src/conversion/modelconsumable.js +1 -1
  17. package/src/conversion/upcastdispatcher.d.ts +12 -12
  18. package/src/conversion/upcastdispatcher.js +5 -5
  19. package/src/conversion/upcasthelpers.d.ts +9 -9
  20. package/src/conversion/upcasthelpers.js +3 -3
  21. package/src/conversion/viewconsumable.d.ts +5 -5
  22. package/src/dataprocessor/basichtmlwriter.d.ts +1 -1
  23. package/src/dataprocessor/dataprocessor.d.ts +2 -2
  24. package/src/dataprocessor/htmldataprocessor.d.ts +6 -6
  25. package/src/dataprocessor/htmldataprocessor.js +2 -2
  26. package/src/dataprocessor/xmldataprocessor.d.ts +6 -6
  27. package/src/dataprocessor/xmldataprocessor.js +2 -2
  28. package/src/dev-utils/model.d.ts +10 -10
  29. package/src/dev-utils/model.js +16 -16
  30. package/src/dev-utils/operationreplayer.d.ts +2 -2
  31. package/src/dev-utils/operationreplayer.js +1 -1
  32. package/src/dev-utils/view.d.ts +8 -8
  33. package/src/dev-utils/view.js +15 -15
  34. package/src/index.d.ts +107 -106
  35. package/src/index.js +65 -64
  36. package/src/model/batch.d.ts +1 -1
  37. package/src/model/differ.d.ts +19 -5
  38. package/src/model/differ.js +72 -13
  39. package/src/model/document.d.ts +18 -12
  40. package/src/model/document.js +18 -13
  41. package/src/model/documentfragment.d.ts +4 -4
  42. package/src/model/documentfragment.js +5 -5
  43. package/src/model/documentselection.d.ts +8 -8
  44. package/src/model/documentselection.js +8 -5
  45. package/src/model/element.d.ts +2 -2
  46. package/src/model/element.js +4 -4
  47. package/src/model/history.d.ts +1 -1
  48. package/src/model/item.d.ts +2 -2
  49. package/src/model/liveposition.d.ts +4 -4
  50. package/src/model/liveposition.js +1 -1
  51. package/src/model/liverange.d.ts +5 -5
  52. package/src/model/liverange.js +1 -1
  53. package/src/model/markercollection.d.ts +4 -4
  54. package/src/model/markercollection.js +2 -2
  55. package/src/model/model.d.ts +14 -15
  56. package/src/model/model.js +18 -19
  57. package/src/model/node.d.ts +5 -5
  58. package/src/model/node.js +2 -2
  59. package/src/model/nodelist.d.ts +1 -1
  60. package/src/model/nodelist.js +1 -1
  61. package/src/model/operation/attributeoperation.d.ts +4 -4
  62. package/src/model/operation/attributeoperation.js +3 -3
  63. package/src/model/operation/detachoperation.d.ts +3 -3
  64. package/src/model/operation/detachoperation.js +3 -3
  65. package/src/model/operation/insertoperation.d.ts +6 -6
  66. package/src/model/operation/insertoperation.js +7 -7
  67. package/src/model/operation/markeroperation.d.ts +5 -5
  68. package/src/model/operation/markeroperation.js +2 -2
  69. package/src/model/operation/mergeoperation.d.ts +5 -5
  70. package/src/model/operation/mergeoperation.js +5 -5
  71. package/src/model/operation/moveoperation.d.ts +4 -4
  72. package/src/model/operation/moveoperation.js +4 -4
  73. package/src/model/operation/nooperation.d.ts +2 -2
  74. package/src/model/operation/nooperation.js +1 -1
  75. package/src/model/operation/operation.d.ts +3 -3
  76. package/src/model/operation/operationfactory.d.ts +2 -2
  77. package/src/model/operation/operationfactory.js +11 -11
  78. package/src/model/operation/renameoperation.d.ts +4 -4
  79. package/src/model/operation/renameoperation.js +3 -3
  80. package/src/model/operation/rootattributeoperation.d.ts +4 -4
  81. package/src/model/operation/rootattributeoperation.js +1 -1
  82. package/src/model/operation/rootoperation.d.ts +3 -7
  83. package/src/model/operation/rootoperation.js +1 -25
  84. package/src/model/operation/splitoperation.d.ts +5 -5
  85. package/src/model/operation/splitoperation.js +5 -5
  86. package/src/model/operation/transform.d.ts +2 -2
  87. package/src/model/operation/transform.js +14 -14
  88. package/src/model/operation/utils.d.ts +6 -6
  89. package/src/model/operation/utils.js +4 -4
  90. package/src/model/position.d.ts +14 -14
  91. package/src/model/position.js +3 -3
  92. package/src/model/range.d.ts +12 -12
  93. package/src/model/range.js +3 -3
  94. package/src/model/rootelement.d.ts +8 -2
  95. package/src/model/rootelement.js +7 -1
  96. package/src/model/schema.d.ts +9 -9
  97. package/src/model/schema.js +10 -5
  98. package/src/model/selection.d.ts +7 -7
  99. package/src/model/selection.js +4 -4
  100. package/src/model/text.d.ts +1 -1
  101. package/src/model/text.js +1 -1
  102. package/src/model/textproxy.d.ts +5 -5
  103. package/src/model/textproxy.js +1 -1
  104. package/src/model/treewalker.d.ts +3 -3
  105. package/src/model/treewalker.js +4 -4
  106. package/src/model/typecheckable.d.ts +13 -13
  107. package/src/model/utils/autoparagraphing.d.ts +4 -4
  108. package/src/model/utils/autoparagraphing.js +1 -2
  109. package/src/model/utils/deletecontent.d.ts +3 -3
  110. package/src/model/utils/deletecontent.js +3 -3
  111. package/src/model/utils/findoptimalinsertionrange.d.ts +4 -4
  112. package/src/model/utils/getselectedcontent.d.ts +4 -4
  113. package/src/model/utils/insertcontent.d.ts +6 -6
  114. package/src/model/utils/insertcontent.js +6 -6
  115. package/src/model/utils/insertobject.d.ts +5 -5
  116. package/src/model/utils/insertobject.js +1 -1
  117. package/src/model/utils/modifyselection.d.ts +3 -3
  118. package/src/model/utils/modifyselection.js +4 -4
  119. package/src/model/utils/selection-post-fixer.d.ts +3 -3
  120. package/src/model/utils/selection-post-fixer.js +2 -2
  121. package/src/model/writer.d.ts +12 -12
  122. package/src/model/writer.js +17 -17
  123. package/src/view/attributeelement.d.ts +3 -3
  124. package/src/view/attributeelement.js +1 -1
  125. package/src/view/containerelement.d.ts +3 -3
  126. package/src/view/containerelement.js +1 -1
  127. package/src/view/document.d.ts +4 -4
  128. package/src/view/document.js +2 -2
  129. package/src/view/documentfragment.d.ts +4 -4
  130. package/src/view/documentfragment.js +3 -3
  131. package/src/view/documentselection.d.ts +8 -8
  132. package/src/view/documentselection.js +2 -2
  133. package/src/view/domconverter.d.ts +19 -13
  134. package/src/view/domconverter.js +28 -10
  135. package/src/view/downcastwriter.d.ts +17 -17
  136. package/src/view/downcastwriter.js +11 -11
  137. package/src/view/editableelement.d.ts +14 -4
  138. package/src/view/editableelement.js +2 -1
  139. package/src/view/element.d.ts +5 -5
  140. package/src/view/element.js +5 -5
  141. package/src/view/emptyelement.d.ts +4 -4
  142. package/src/view/emptyelement.js +2 -2
  143. package/src/view/filler.d.ts +1 -1
  144. package/src/view/item.d.ts +2 -2
  145. package/src/view/matcher.d.ts +1 -1
  146. package/src/view/node.d.ts +5 -5
  147. package/src/view/node.js +2 -2
  148. package/src/view/observer/arrowkeysobserver.d.ts +4 -4
  149. package/src/view/observer/arrowkeysobserver.js +2 -2
  150. package/src/view/observer/bubblingemittermixin.d.ts +2 -2
  151. package/src/view/observer/bubblingemittermixin.js +1 -1
  152. package/src/view/observer/bubblingeventinfo.d.ts +3 -3
  153. package/src/view/observer/clickobserver.d.ts +3 -3
  154. package/src/view/observer/clickobserver.js +1 -1
  155. package/src/view/observer/compositionobserver.d.ts +3 -3
  156. package/src/view/observer/compositionobserver.js +1 -1
  157. package/src/view/observer/domeventdata.d.ts +3 -3
  158. package/src/view/observer/domeventobserver.d.ts +1 -1
  159. package/src/view/observer/domeventobserver.js +2 -2
  160. package/src/view/observer/fakeselectionobserver.d.ts +2 -2
  161. package/src/view/observer/fakeselectionobserver.js +2 -2
  162. package/src/view/observer/focusobserver.d.ts +3 -3
  163. package/src/view/observer/focusobserver.js +1 -1
  164. package/src/view/observer/inputobserver.d.ts +4 -4
  165. package/src/view/observer/inputobserver.js +2 -2
  166. package/src/view/observer/keyobserver.d.ts +2 -2
  167. package/src/view/observer/keyobserver.js +1 -1
  168. package/src/view/observer/mouseobserver.d.ts +2 -2
  169. package/src/view/observer/mouseobserver.js +1 -1
  170. package/src/view/observer/mutationobserver.d.ts +4 -4
  171. package/src/view/observer/mutationobserver.js +2 -2
  172. package/src/view/observer/observer.d.ts +2 -2
  173. package/src/view/observer/selectionobserver.d.ts +7 -7
  174. package/src/view/observer/selectionobserver.js +5 -5
  175. package/src/view/observer/tabobserver.d.ts +4 -4
  176. package/src/view/observer/tabobserver.js +2 -2
  177. package/src/view/placeholder.d.ts +16 -8
  178. package/src/view/placeholder.js +21 -12
  179. package/src/view/position.d.ts +7 -7
  180. package/src/view/position.js +4 -4
  181. package/src/view/range.d.ts +7 -7
  182. package/src/view/range.js +3 -3
  183. package/src/view/rawelement.d.ts +5 -5
  184. package/src/view/rawelement.js +2 -2
  185. package/src/view/renderer.d.ts +5 -5
  186. package/src/view/renderer.js +4 -5
  187. package/src/view/rooteditableelement.d.ts +2 -2
  188. package/src/view/rooteditableelement.js +1 -1
  189. package/src/view/selection.d.ts +8 -8
  190. package/src/view/selection.js +5 -5
  191. package/src/view/styles/background.d.ts +1 -1
  192. package/src/view/styles/background.js +1 -1
  193. package/src/view/styles/border.d.ts +1 -1
  194. package/src/view/styles/border.js +1 -1
  195. package/src/view/styles/margin.d.ts +1 -1
  196. package/src/view/styles/margin.js +1 -1
  197. package/src/view/styles/padding.d.ts +1 -1
  198. package/src/view/styles/padding.js +1 -1
  199. package/src/view/styles/utils.d.ts +1 -1
  200. package/src/view/text.d.ts +2 -2
  201. package/src/view/text.js +1 -1
  202. package/src/view/textproxy.d.ts +6 -6
  203. package/src/view/textproxy.js +1 -1
  204. package/src/view/treewalker.d.ts +3 -3
  205. package/src/view/treewalker.js +4 -4
  206. package/src/view/typecheckable.d.ts +16 -16
  207. package/src/view/uielement.d.ts +6 -6
  208. package/src/view/uielement.js +2 -2
  209. package/src/view/upcastwriter.d.ts +9 -9
  210. package/src/view/upcastwriter.js +6 -6
  211. package/src/view/view.d.ts +26 -19
  212. package/src/view/view.js +31 -19
package/src/index.js CHANGED
@@ -5,73 +5,74 @@
5
5
  /**
6
6
  * @module engine
7
7
  */
8
- export * from './view/placeholder.js';
8
+ export * from './view/placeholder';
9
9
  // Controller.
10
- export { default as EditingController } from './controller/editingcontroller.js';
11
- export { default as DataController } from './controller/datacontroller.js';
10
+ export { default as EditingController } from './controller/editingcontroller';
11
+ export { default as DataController } from './controller/datacontroller';
12
12
  // Conversion.
13
- export { default as Conversion } from './conversion/conversion.js';
14
- export { default as HtmlDataProcessor } from './dataprocessor/htmldataprocessor.js';
15
- export { default as InsertOperation } from './model/operation/insertoperation.js';
16
- export { default as MoveOperation } from './model/operation/moveoperation.js';
17
- export { default as MergeOperation } from './model/operation/mergeoperation.js';
18
- export { default as SplitOperation } from './model/operation/splitoperation.js';
19
- export { default as MarkerOperation } from './model/operation/markeroperation.js';
20
- export { default as OperationFactory } from './model/operation/operationfactory.js';
21
- export { default as AttributeOperation } from './model/operation/attributeoperation.js';
22
- export { default as RenameOperation } from './model/operation/renameoperation.js';
23
- export { default as RootAttributeOperation } from './model/operation/rootattributeoperation.js';
24
- export { default as RootOperation } from './model/operation/rootoperation.js';
25
- export { default as NoOperation } from './model/operation/nooperation.js';
26
- export { transformSets } from './model/operation/transform.js';
13
+ export { default as Conversion } from './conversion/conversion';
14
+ export { default as HtmlDataProcessor } from './dataprocessor/htmldataprocessor';
15
+ export { default as InsertOperation } from './model/operation/insertoperation';
16
+ export { default as MoveOperation } from './model/operation/moveoperation';
17
+ export { default as MergeOperation } from './model/operation/mergeoperation';
18
+ export { default as SplitOperation } from './model/operation/splitoperation';
19
+ export { default as MarkerOperation } from './model/operation/markeroperation';
20
+ export { default as OperationFactory } from './model/operation/operationfactory';
21
+ export { default as AttributeOperation } from './model/operation/attributeoperation';
22
+ export { default as RenameOperation } from './model/operation/renameoperation';
23
+ export { default as RootAttributeOperation } from './model/operation/rootattributeoperation';
24
+ export { default as RootOperation } from './model/operation/rootoperation';
25
+ export { default as NoOperation } from './model/operation/nooperation';
26
+ export { transformSets } from './model/operation/transform';
27
27
  // Model.
28
- export { default as DocumentSelection } from './model/documentselection.js';
29
- export { default as Range } from './model/range.js';
30
- export { default as LiveRange } from './model/liverange.js';
31
- export { default as LivePosition } from './model/liveposition.js';
32
- export { default as Model } from './model/model.js';
33
- export { default as TreeWalker } from './model/treewalker.js';
34
- export { default as Element } from './model/element.js';
35
- export { default as Position } from './model/position.js';
36
- export { default as DocumentFragment } from './model/documentfragment.js';
37
- export { default as History } from './model/history.js';
38
- export { default as Text } from './model/text.js';
39
- export { default as TextProxy } from './model/textproxy.js';
40
- export { findOptimalInsertionRange } from './model/utils/findoptimalinsertionrange.js';
28
+ export { default as DocumentSelection } from './model/documentselection';
29
+ export { default as Range } from './model/range';
30
+ export { default as LiveRange } from './model/liverange';
31
+ export { default as LivePosition } from './model/liveposition';
32
+ export { default as Model } from './model/model';
33
+ export { default as TreeWalker } from './model/treewalker';
34
+ export { default as Element } from './model/element';
35
+ export { default as Position } from './model/position';
36
+ export { default as DocumentFragment } from './model/documentfragment';
37
+ export { default as History } from './model/history';
38
+ export { default as Text } from './model/text';
39
+ export { default as TextProxy } from './model/textproxy';
40
+ export { findOptimalInsertionRange } from './model/utils/findoptimalinsertionrange';
41
41
  // View.
42
- export { default as DataTransfer } from './view/datatransfer.js';
43
- export { default as DomConverter } from './view/domconverter.js';
44
- export { default as Renderer } from './view/renderer.js';
45
- export { default as View } from './view/view.js';
46
- export { default as ViewDocument } from './view/document.js';
47
- export { default as ViewText } from './view/text.js';
48
- export { default as ViewElement } from './view/element.js';
49
- export { default as ViewContainerElement } from './view/containerelement.js';
50
- export { default as ViewEditableElement } from './view/editableelement.js';
51
- export { default as ViewRootEditableElement } from './view/rooteditableelement.js';
52
- export { default as ViewAttributeElement } from './view/attributeelement.js';
53
- export { default as ViewEmptyElement } from './view/emptyelement.js';
54
- export { default as ViewRawElement } from './view/rawelement.js';
55
- export { default as ViewUIElement } from './view/uielement.js';
56
- export { default as ViewDocumentFragment } from './view/documentfragment.js';
57
- export { default as ViewTreeWalker } from './view/treewalker.js';
58
- export { default as AttributeElement } from './view/attributeelement.js';
59
- export { getFillerOffset } from './view/containerelement.js';
42
+ export { default as DataTransfer } from './view/datatransfer';
43
+ export { default as DomConverter } from './view/domconverter';
44
+ export { default as Renderer } from './view/renderer';
45
+ export { default as View } from './view/view';
46
+ export { default as ViewDocument } from './view/document';
47
+ export { default as ViewText } from './view/text';
48
+ export { default as ViewElement } from './view/element';
49
+ export { default as ViewContainerElement } from './view/containerelement';
50
+ export { default as ViewEditableElement } from './view/editableelement';
51
+ export { default as ViewRootEditableElement } from './view/rooteditableelement';
52
+ export { default as ViewAttributeElement } from './view/attributeelement';
53
+ export { default as ViewEmptyElement } from './view/emptyelement';
54
+ export { default as ViewRawElement } from './view/rawelement';
55
+ export { default as ViewUIElement } from './view/uielement';
56
+ export { default as ViewDocumentFragment } from './view/documentfragment';
57
+ export { default as ViewTreeWalker } from './view/treewalker';
58
+ export { default as AttributeElement } from './view/attributeelement';
59
+ export { getFillerOffset } from './view/containerelement';
60
60
  // View / Observer.
61
- export { default as Observer } from './view/observer/observer.js';
62
- export { default as ClickObserver } from './view/observer/clickobserver.js';
63
- export { default as DomEventObserver } from './view/observer/domeventobserver.js';
64
- export { default as MouseObserver } from './view/observer/mouseobserver.js';
65
- export { default as TabObserver } from './view/observer/tabobserver.js';
66
- export { default as DowncastWriter } from './view/downcastwriter.js';
67
- export { default as UpcastWriter } from './view/upcastwriter.js';
68
- export { default as Matcher } from './view/matcher.js';
69
- export { default as BubblingEventInfo } from './view/observer/bubblingeventinfo.js';
70
- export { default as DomEventData } from './view/observer/domeventdata.js';
61
+ export { default as Observer } from './view/observer/observer';
62
+ export { default as ClickObserver } from './view/observer/clickobserver';
63
+ export { default as DomEventObserver } from './view/observer/domeventobserver';
64
+ export { default as MouseObserver } from './view/observer/mouseobserver';
65
+ export { default as TabObserver } from './view/observer/tabobserver';
66
+ export { default as FocusObserver } from './view/observer/focusobserver';
67
+ export { default as DowncastWriter } from './view/downcastwriter';
68
+ export { default as UpcastWriter } from './view/upcastwriter';
69
+ export { default as Matcher } from './view/matcher';
70
+ export { default as BubblingEventInfo } from './view/observer/bubblingeventinfo';
71
+ export { default as DomEventData } from './view/observer/domeventdata';
71
72
  // View / Styles.
72
- export { StylesProcessor } from './view/stylesmap.js';
73
- export * from './view/styles/background.js';
74
- export * from './view/styles/border.js';
75
- export * from './view/styles/margin.js';
76
- export * from './view/styles/padding.js';
77
- export * from './view/styles/utils.js';
73
+ export { StylesProcessor } from './view/stylesmap';
74
+ export * from './view/styles/background';
75
+ export * from './view/styles/border';
76
+ export * from './view/styles/margin';
77
+ export * from './view/styles/padding';
78
+ export * from './view/styles/utils';
@@ -2,7 +2,7 @@
2
2
  * @license Copyright (c) 2003-2023, 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
- import type Operation from './operation/operation.js';
5
+ import type Operation from './operation/operation';
6
6
  /**
7
7
  * A batch instance groups model changes ({@link module:engine/model/operation/operation~Operation operations}). All operations
8
8
  * grouped in a single batch can be reverted together, so you can also think about a batch as of a single undo step. If you want
@@ -5,11 +5,12 @@
5
5
  /**
6
6
  * @module engine/model/differ
7
7
  */
8
- import Position from './position.js';
9
- import Range from './range.js';
10
- import type { default as MarkerCollection, MarkerData } from './markercollection.js';
11
- import type Item from './item.js';
12
- import type Operation from './operation/operation.js';
8
+ import Position from './position';
9
+ import Range from './range';
10
+ import type { default as MarkerCollection, MarkerData } from './markercollection';
11
+ import type Item from './item';
12
+ import type RootElement from './rootelement';
13
+ import type Operation from './operation/operation';
13
14
  /**
14
15
  * Calculates the difference between two model states.
15
16
  *
@@ -191,6 +192,19 @@ export default class Differ {
191
192
  * @param item Item to refresh.
192
193
  */
193
194
  _refreshItem(item: Item): void;
195
+ /**
196
+ * Buffers all the data related to given root like it was all just added to the editor.
197
+ *
198
+ * Following changes are buffered:
199
+ *
200
+ * * root is attached,
201
+ * * all root content is inserted,
202
+ * * all root attributes are added,
203
+ * * all markers inside the root are added.
204
+ *
205
+ * @internal
206
+ */
207
+ _bufferRootLoad(root: RootElement): void;
194
208
  /**
195
209
  * Saves and handles an insert change.
196
210
  */
@@ -5,8 +5,8 @@
5
5
  /**
6
6
  * @module engine/model/differ
7
7
  */
8
- import Position from './position.js';
9
- import Range from './range.js';
8
+ import Position from './position';
9
+ import Range from './range';
10
10
  /**
11
11
  * Calculates the difference between two model states.
12
12
  *
@@ -94,6 +94,9 @@ export default class Differ {
94
94
  // Marking changes in them would cause a "double" changing then.
95
95
  //
96
96
  const operation = operationToBuffer;
97
+ // Note: an operation that happens inside a non-loaded root will be ignored. If the operation happens partially inside
98
+ // a non-loaded root, that part will be ignored (this may happen for move or marker operations).
99
+ //
97
100
  switch (operation.type) {
98
101
  case 'insert': {
99
102
  if (this._isInInsertedElement(operation.position.parent)) {
@@ -179,12 +182,23 @@ export default class Differ {
179
182
  }
180
183
  case 'detachRoot':
181
184
  case 'addRoot': {
185
+ const root = operation.affectedSelectable;
186
+ if (!root._isLoaded) {
187
+ return;
188
+ }
189
+ // Don't buffer if the root state does not change.
190
+ if (root.isAttached() == operation.isAdd) {
191
+ return;
192
+ }
182
193
  this._bufferRootStateChange(operation.rootName, operation.isAdd);
183
194
  break;
184
195
  }
185
196
  case 'addRootAttribute':
186
197
  case 'removeRootAttribute':
187
198
  case 'changeRootAttribute': {
199
+ if (!operation.root._isLoaded) {
200
+ return;
201
+ }
188
202
  const rootName = operation.root.rootName;
189
203
  this._bufferRootAttributeChange(rootName, operation.key, operation.oldValue, operation.newValue);
190
204
  break;
@@ -201,20 +215,24 @@ export default class Differ {
201
215
  * @param newMarkerData Marker data after the change.
202
216
  */
203
217
  bufferMarkerChange(markerName, oldMarkerData, newMarkerData) {
204
- const buffered = this._changedMarkers.get(markerName);
218
+ if (oldMarkerData.range && oldMarkerData.range.root.is('rootElement') && !oldMarkerData.range.root._isLoaded) {
219
+ oldMarkerData.range = null;
220
+ }
221
+ if (newMarkerData.range && newMarkerData.range.root.is('rootElement') && !newMarkerData.range.root._isLoaded) {
222
+ newMarkerData.range = null;
223
+ }
224
+ let buffered = this._changedMarkers.get(markerName);
205
225
  if (!buffered) {
206
- this._changedMarkers.set(markerName, {
207
- newMarkerData,
208
- oldMarkerData
209
- });
226
+ buffered = { newMarkerData, oldMarkerData };
227
+ this._changedMarkers.set(markerName, buffered);
210
228
  }
211
229
  else {
212
230
  buffered.newMarkerData = newMarkerData;
213
- if (buffered.oldMarkerData.range == null && newMarkerData.range == null) {
214
- // The marker is going to be removed (`newMarkerData.range == null`) but it did not exist before the first buffered change
215
- // (`buffered.oldMarkerData.range == null`). In this case, do not keep the marker in buffer at all.
216
- this._changedMarkers.delete(markerName);
217
- }
231
+ }
232
+ if (buffered.oldMarkerData.range == null && newMarkerData.range == null) {
233
+ // The marker is going to be removed (`newMarkerData.range == null`) but it did not exist before the first buffered change
234
+ // (`buffered.oldMarkerData.range == null`). In this case, do not keep the marker in buffer at all.
235
+ this._changedMarkers.delete(markerName);
218
236
  }
219
237
  }
220
238
  /**
@@ -496,7 +514,7 @@ export default class Differ {
496
514
  }
497
515
  const diffItem = this._changedRoots.get(rootName);
498
516
  if (diffItem.state !== undefined) {
499
- // Root `state` can only toggle between of the values ('attached' or 'detached') and no value. It cannot be any other way,
517
+ // Root `state` can only toggle between one of the values and no value. It cannot be any other way,
500
518
  // because if the root was originally attached it can only become detached. Then, if it is re-attached in the same batch of
501
519
  // changes, it gets back to "no change" (which means no value). Same if the root was originally detached.
502
520
  delete diffItem.state;
@@ -567,10 +585,45 @@ export default class Differ {
567
585
  // Clear cache after each buffered operation as it is no longer valid.
568
586
  this._cachedChanges = null;
569
587
  }
588
+ /**
589
+ * Buffers all the data related to given root like it was all just added to the editor.
590
+ *
591
+ * Following changes are buffered:
592
+ *
593
+ * * root is attached,
594
+ * * all root content is inserted,
595
+ * * all root attributes are added,
596
+ * * all markers inside the root are added.
597
+ *
598
+ * @internal
599
+ */
600
+ _bufferRootLoad(root) {
601
+ if (!root.isAttached()) {
602
+ return;
603
+ }
604
+ this._bufferRootStateChange(root.rootName, true);
605
+ this._markInsert(root, 0, root.maxOffset);
606
+ // Buffering root attribute changes makes sense and is actually needed, even though we buffer root state change above.
607
+ // Because the root state change is buffered, the root attributes changes are not returned by the differ.
608
+ // But, if the root attribute is removed in the same change block, or the root is detached, then the differ results would be wrong.
609
+ //
610
+ for (const key of root.getAttributeKeys()) {
611
+ this._bufferRootAttributeChange(root.rootName, key, null, root.getAttribute(key));
612
+ }
613
+ for (const marker of this._markerCollection) {
614
+ if (marker.getRange().root == root) {
615
+ const markerData = marker.getData();
616
+ this.bufferMarkerChange(marker.name, { ...markerData, range: null }, markerData);
617
+ }
618
+ }
619
+ }
570
620
  /**
571
621
  * Saves and handles an insert change.
572
622
  */
573
623
  _markInsert(parent, offset, howMany) {
624
+ if (parent.root.is('rootElement') && !parent.root._isLoaded) {
625
+ return;
626
+ }
574
627
  const changeItem = { type: 'insert', offset, howMany, count: this._changeCount++ };
575
628
  this._markChange(parent, changeItem);
576
629
  }
@@ -578,6 +631,9 @@ export default class Differ {
578
631
  * Saves and handles a remove change.
579
632
  */
580
633
  _markRemove(parent, offset, howMany) {
634
+ if (parent.root.is('rootElement') && !parent.root._isLoaded) {
635
+ return;
636
+ }
581
637
  const changeItem = { type: 'remove', offset, howMany, count: this._changeCount++ };
582
638
  this._markChange(parent, changeItem);
583
639
  this._removeAllNestedChanges(parent, offset, howMany);
@@ -586,6 +642,9 @@ export default class Differ {
586
642
  * Saves and handles an attribute change.
587
643
  */
588
644
  _markAttribute(item) {
645
+ if (item.root.is('rootElement') && !item.root._isLoaded) {
646
+ return;
647
+ }
589
648
  const changeItem = { type: 'attribute', offset: item.startOffset, howMany: item.offsetSize, count: this._changeCount++ };
590
649
  this._markChange(item.parent, changeItem);
591
650
  }
@@ -5,20 +5,18 @@
5
5
  /**
6
6
  * @module engine/model/document
7
7
  */
8
- import Differ from './differ.js';
9
- import DocumentSelection from './documentselection.js';
10
- import History from './history.js';
11
- import RootElement from './rootelement.js';
12
- import type { default as Model } from './model.js';
13
- import type Batch from './batch.js';
14
- import type Range from './range.js';
15
- import type Writer from './writer.js';
8
+ import Differ from './differ';
9
+ import DocumentSelection from './documentselection';
10
+ import History from './history';
11
+ import RootElement from './rootelement';
12
+ import type { default as Model } from './model';
13
+ import type Batch from './batch';
14
+ import type Range from './range';
15
+ import type Writer from './writer';
16
16
  import { Collection } from '@ckeditor/ckeditor5-utils';
17
17
  declare const Document_base: {
18
18
  new (): import("@ckeditor/ckeditor5-utils").Emitter;
19
- prototype: import("@ckeditor/ckeditor5-utils").Emitter; /**
20
- * The model differ object. Its role is to buffer changes done on the model document and then calculate a diff of those changes.
21
- */
19
+ prototype: import("@ckeditor/ckeditor5-utils").Emitter;
22
20
  };
23
21
  /**
24
22
  * Data model's document. It contains the model's structure, its selection and the history of changes.
@@ -127,9 +125,17 @@ export default class Document extends Document_base {
127
125
  * on the document data know which roots are still a part of the document and should be processed.
128
126
  *
129
127
  * @param includeDetached Specified whether detached roots should be returned as well.
130
- * @returns Roots names.
131
128
  */
132
129
  getRootNames(includeDetached?: boolean): Array<string>;
130
+ /**
131
+ * Returns an array with all roots added to the document (except the {@link #graveyard graveyard root}).
132
+ *
133
+ * Detached roots **are not** returned by this method by default. This is to make sure that all features or algorithms that operate
134
+ * on the document data know which roots are still a part of the document and should be processed.
135
+ *
136
+ * @param includeDetached Specified whether detached roots should be returned as well.
137
+ */
138
+ getRoots(includeDetached?: boolean): Array<RootElement>;
133
139
  /**
134
140
  * Used to register a post-fixer callback. A post-fixer mechanism guarantees that the features
135
141
  * will operate on a correct model state.
@@ -5,10 +5,10 @@
5
5
  /**
6
6
  * @module engine/model/document
7
7
  */
8
- import Differ from './differ.js';
9
- import DocumentSelection from './documentselection.js';
10
- import History from './history.js';
11
- import RootElement from './rootelement.js';
8
+ import Differ from './differ';
9
+ import DocumentSelection from './documentselection';
10
+ import History from './history';
11
+ import RootElement from './rootelement';
12
12
  import { CKEditorError, Collection, EmitterMixin, isInsideSurrogatePair, isInsideCombinedSymbol } from '@ckeditor/ckeditor5-utils';
13
13
  import { clone } from 'lodash-es';
14
14
  // @if CK_DEBUG_ENGINE // const { logDocument } = require( '../dev-utils/utils' );
@@ -179,12 +179,21 @@ export default class Document extends EmitterMixin() {
179
179
  * on the document data know which roots are still a part of the document and should be processed.
180
180
  *
181
181
  * @param includeDetached Specified whether detached roots should be returned as well.
182
- * @returns Roots names.
183
182
  */
184
183
  getRootNames(includeDetached = false) {
184
+ return this.getRoots(includeDetached).map(root => root.rootName);
185
+ }
186
+ /**
187
+ * Returns an array with all roots added to the document (except the {@link #graveyard graveyard root}).
188
+ *
189
+ * Detached roots **are not** returned by this method by default. This is to make sure that all features or algorithms that operate
190
+ * on the document data know which roots are still a part of the document and should be processed.
191
+ *
192
+ * @param includeDetached Specified whether detached roots should be returned as well.
193
+ */
194
+ getRoots(includeDetached = false) {
185
195
  return Array.from(this.roots)
186
- .filter(root => root.rootName != graveyardName && (includeDetached || root.isAttached()))
187
- .map(root => root.rootName);
196
+ .filter(root => root != this.graveyard && (includeDetached || root.isAttached()) && root._isLoaded);
188
197
  }
189
198
  /**
190
199
  * Used to register a post-fixer callback. A post-fixer mechanism guarantees that the features
@@ -283,12 +292,8 @@ export default class Document extends EmitterMixin() {
283
292
  * @returns The default root for this document.
284
293
  */
285
294
  _getDefaultRoot() {
286
- for (const root of this.roots) {
287
- if (root !== this.graveyard) {
288
- return root;
289
- }
290
- }
291
- return this.graveyard;
295
+ const roots = this.getRoots();
296
+ return roots.length ? roots[0] : this.graveyard;
292
297
  }
293
298
  /**
294
299
  * Returns the default range for this selection. The default range is a collapsed range that starts and ends
@@ -5,10 +5,10 @@
5
5
  /**
6
6
  * @module engine/model/documentfragment
7
7
  */
8
- import TypeCheckable from './typecheckable.js';
9
- import type Item from './item.js';
10
- import type Node from './node.js';
11
- import type Range from './range.js';
8
+ import TypeCheckable from './typecheckable';
9
+ import type Item from './item';
10
+ import type Node from './node';
11
+ import type Range from './range';
12
12
  /**
13
13
  * DocumentFragment represents a part of model which does not have a common root but its top-level nodes
14
14
  * can be seen as siblings. In other words, it is a detached part of model tree, without a root.
@@ -5,11 +5,11 @@
5
5
  /**
6
6
  * @module engine/model/documentfragment
7
7
  */
8
- import TypeCheckable from './typecheckable.js';
9
- import Element from './element.js';
10
- import NodeList from './nodelist.js';
11
- import Text from './text.js';
12
- import TextProxy from './textproxy.js';
8
+ import TypeCheckable from './typecheckable';
9
+ import Element from './element';
10
+ import NodeList from './nodelist';
11
+ import Text from './text';
12
+ import TextProxy from './textproxy';
13
13
  import { isIterable } from '@ckeditor/ckeditor5-utils';
14
14
  // @if CK_DEBUG_ENGINE // const { stringifyMap } = require( '../dev-utils/utils' );
15
15
  /**
@@ -5,14 +5,14 @@
5
5
  /**
6
6
  * @module engine/model/documentselection
7
7
  */
8
- import TypeCheckable from './typecheckable.js';
9
- import Selection, { type SelectionChangeAttributeEvent, type SelectionChangeRangeEvent } from './selection.js';
10
- import type { default as Document } from './document.js';
11
- import type { Marker } from './markercollection.js';
12
- import type Element from './element.js';
13
- import type Item from './item.js';
14
- import type { default as Position, PositionOffset } from './position.js';
15
- import type Range from './range.js';
8
+ import TypeCheckable from './typecheckable';
9
+ import Selection, { type SelectionChangeAttributeEvent, type SelectionChangeRangeEvent } from './selection';
10
+ import type { default as Document } from './document';
11
+ import type { Marker } from './markercollection';
12
+ import type Element from './element';
13
+ import type Item from './item';
14
+ import type { default as Position, PositionOffset } from './position';
15
+ import type Range from './range';
16
16
  import { Collection } from '@ckeditor/ckeditor5-utils';
17
17
  declare const DocumentSelection_base: import("@ckeditor/ckeditor5-utils").Mixed<typeof TypeCheckable, import("@ckeditor/ckeditor5-utils").Emitter>;
18
18
  /**
@@ -5,11 +5,11 @@
5
5
  /**
6
6
  * @module engine/model/documentselection
7
7
  */
8
- import TypeCheckable from './typecheckable.js';
9
- import LiveRange from './liverange.js';
10
- import Selection from './selection.js';
11
- import Text from './text.js';
12
- import TextProxy from './textproxy.js';
8
+ import TypeCheckable from './typecheckable';
9
+ import LiveRange from './liverange';
10
+ import Selection from './selection';
11
+ import Text from './text';
12
+ import TextProxy from './textproxy';
13
13
  import { CKEditorError, Collection, EmitterMixin, toMap, uid } from '@ckeditor/ckeditor5-utils';
14
14
  const storePrefix = 'selection:';
15
15
  /**
@@ -866,6 +866,9 @@ class LiveSelection extends Selection {
866
866
  _getSurroundingAttributes() {
867
867
  const position = this.getFirstPosition();
868
868
  const schema = this._model.schema;
869
+ if (position.root.rootName == '$graveyard') {
870
+ return null;
871
+ }
869
872
  let attrs = null;
870
873
  if (!this.isCollapsed) {
871
874
  // 1. If selection is a range...
@@ -5,8 +5,8 @@
5
5
  /**
6
6
  * @module engine/model/element
7
7
  */
8
- import Node, { type NodeAttributes } from './node.js';
9
- import type Item from './item.js';
8
+ import Node, { type NodeAttributes } from './node';
9
+ import type Item from './item';
10
10
  /**
11
11
  * Model element. Type of {@link module:engine/model/node~Node node} that has a {@link module:engine/model/element~Element#name name} and
12
12
  * {@link module:engine/model/element~Element#getChildren child nodes}.
@@ -5,10 +5,10 @@
5
5
  /**
6
6
  * @module engine/model/element
7
7
  */
8
- import Node from './node.js';
9
- import NodeList from './nodelist.js';
10
- import Text from './text.js';
11
- import TextProxy from './textproxy.js';
8
+ import Node from './node';
9
+ import NodeList from './nodelist';
10
+ import Text from './text';
11
+ import TextProxy from './textproxy';
12
12
  import { isIterable } from '@ckeditor/ckeditor5-utils';
13
13
  // @if CK_DEBUG_ENGINE // const { stringifyMap, convertMapToStringifiedObject, convertMapToTags } = require( '../dev-utils/utils' );
14
14
  /**
@@ -2,7 +2,7 @@
2
2
  * @license Copyright (c) 2003-2023, 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
- import type Operation from './operation/operation.js';
5
+ import type Operation from './operation/operation';
6
6
  /**
7
7
  * @module engine/model/history
8
8
  */
@@ -2,8 +2,8 @@
2
2
  * @license Copyright (c) 2003-2023, 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
- import type Node from './node.js';
6
- import type TextProxy from './textproxy.js';
5
+ import type Node from './node';
6
+ import type TextProxy from './textproxy';
7
7
  /**
8
8
  * @module engine/model/item
9
9
  */
@@ -5,10 +5,10 @@
5
5
  /**
6
6
  * @module engine/model/liveposition
7
7
  */
8
- import Position, { type PositionOffset, type PositionStickiness } from './position.js';
9
- import type DocumentFragment from './documentfragment.js';
10
- import type Item from './item.js';
11
- import type RootElement from './rootelement.js';
8
+ import Position, { type PositionOffset, type PositionStickiness } from './position';
9
+ import type DocumentFragment from './documentfragment';
10
+ import type Item from './item';
11
+ import type RootElement from './rootelement';
12
12
  declare const LivePosition_base: import("@ckeditor/ckeditor5-utils").Mixed<typeof Position, import("@ckeditor/ckeditor5-utils").Emitter>;
13
13
  /**
14
14
  * `LivePosition` is a type of {@link module:engine/model/position~Position Position}
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * @module engine/model/liveposition
7
7
  */
8
- import Position from './position.js';
8
+ import Position from './position';
9
9
  import { CKEditorError, EmitterMixin } from '@ckeditor/ckeditor5-utils';
10
10
  /**
11
11
  * `LivePosition` is a type of {@link module:engine/model/position~Position Position}
@@ -5,11 +5,11 @@
5
5
  /**
6
6
  * @module engine/model/liverange
7
7
  */
8
- import Range from './range.js';
9
- import type DocumentFragment from './documentfragment.js';
10
- import type Element from './element.js';
11
- import type Item from './item.js';
12
- import type Position from './position.js';
8
+ import Range from './range';
9
+ import type DocumentFragment from './documentfragment';
10
+ import type Element from './element';
11
+ import type Item from './item';
12
+ import type Position from './position';
13
13
  declare const LiveRange_base: import("@ckeditor/ckeditor5-utils").Mixed<typeof Range, import("@ckeditor/ckeditor5-utils").Emitter>;
14
14
  /**
15
15
  * `LiveRange` is a type of {@link module:engine/model/range~Range Range}
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * @module engine/model/liverange
7
7
  */
8
- import Range from './range.js';
8
+ import Range from './range';
9
9
  import { EmitterMixin } from '@ckeditor/ckeditor5-utils';
10
10
  /**
11
11
  * `LiveRange` is a type of {@link module:engine/model/range~Range Range}