@ckeditor/ckeditor5-engine 44.3.0-alpha.7 → 45.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/index.js +304 -128
  3. package/dist/index.js.map +1 -1
  4. package/package.json +3 -3
  5. package/src/controller/datacontroller.js +40 -0
  6. package/src/controller/editingcontroller.js +16 -0
  7. package/src/conversion/conversion.js +6 -4
  8. package/src/conversion/conversionhelpers.js +1 -0
  9. package/src/conversion/downcastdispatcher.js +10 -0
  10. package/src/conversion/downcasthelpers.js +1 -1
  11. package/src/conversion/mapper.js +92 -95
  12. package/src/conversion/modelconsumable.js +13 -15
  13. package/src/conversion/upcastdispatcher.js +28 -24
  14. package/src/conversion/upcasthelpers.js +1 -1
  15. package/src/conversion/viewconsumable.js +19 -20
  16. package/src/dataprocessor/htmldataprocessor.js +13 -1
  17. package/src/dataprocessor/xmldataprocessor.js +21 -1
  18. package/src/dev-utils/model.js +1 -1
  19. package/src/dev-utils/operationreplayer.js +3 -0
  20. package/src/dev-utils/utils.js +35 -1
  21. package/src/dev-utils/view.js +13 -0
  22. package/src/model/batch.js +20 -0
  23. package/src/model/differ.js +92 -88
  24. package/src/model/document.d.ts +1 -3
  25. package/src/model/document.js +38 -1
  26. package/src/model/documentfragment.js +10 -10
  27. package/src/model/documentselection.js +44 -32
  28. package/src/model/element.js +8 -4
  29. package/src/model/history.js +31 -33
  30. package/src/model/markercollection.js +25 -7
  31. package/src/model/model.js +21 -0
  32. package/src/model/node.js +22 -18
  33. package/src/model/nodelist.js +12 -12
  34. package/src/model/operation/attributeoperation.js +25 -1
  35. package/src/model/operation/detachoperation.js +8 -0
  36. package/src/model/operation/insertoperation.js +18 -0
  37. package/src/model/operation/markeroperation.js +29 -0
  38. package/src/model/operation/mergeoperation.js +16 -0
  39. package/src/model/operation/moveoperation.js +12 -0
  40. package/src/model/operation/operation.js +19 -0
  41. package/src/model/operation/renameoperation.js +12 -0
  42. package/src/model/operation/rootattributeoperation.js +20 -0
  43. package/src/model/operation/rootoperation.js +16 -0
  44. package/src/model/operation/splitoperation.js +19 -0
  45. package/src/model/operation/transform.js +5 -0
  46. package/src/model/position.js +40 -0
  47. package/src/model/range.js +8 -0
  48. package/src/model/rootelement.js +18 -10
  49. package/src/model/schema.js +25 -23
  50. package/src/model/selection.js +10 -10
  51. package/src/model/text.js +6 -0
  52. package/src/model/textproxy.js +12 -0
  53. package/src/model/treewalker.js +49 -0
  54. package/src/model/utils/insertcontent.js +60 -25
  55. package/src/model/writer.js +8 -0
  56. package/src/view/attributeelement.js +23 -23
  57. package/src/view/datatransfer.js +8 -0
  58. package/src/view/document.js +21 -4
  59. package/src/view/documentfragment.js +13 -9
  60. package/src/view/documentselection.js +4 -0
  61. package/src/view/domconverter.d.ts +6 -1
  62. package/src/view/domconverter.js +109 -48
  63. package/src/view/downcastwriter.js +14 -10
  64. package/src/view/element.js +29 -17
  65. package/src/view/matcher.js +1 -1
  66. package/src/view/node.js +9 -1
  67. package/src/view/observer/bubblingeventinfo.js +12 -0
  68. package/src/view/observer/clickobserver.js +4 -7
  69. package/src/view/observer/compositionobserver.js +14 -12
  70. package/src/view/observer/domeventdata.js +17 -1
  71. package/src/view/observer/domeventobserver.js +10 -13
  72. package/src/view/observer/fakeselectionobserver.d.ts +1 -1
  73. package/src/view/observer/fakeselectionobserver.js +5 -1
  74. package/src/view/observer/focusobserver.js +65 -14
  75. package/src/view/observer/inputobserver.js +33 -26
  76. package/src/view/observer/keyobserver.js +4 -7
  77. package/src/view/observer/mouseobserver.js +4 -7
  78. package/src/view/observer/mutationobserver.js +23 -6
  79. package/src/view/observer/observer.js +12 -4
  80. package/src/view/observer/selectionobserver.d.ts +6 -1
  81. package/src/view/observer/selectionobserver.js +94 -17
  82. package/src/view/observer/touchobserver.js +4 -7
  83. package/src/view/position.js +8 -0
  84. package/src/view/range.js +8 -0
  85. package/src/view/renderer.js +142 -70
  86. package/src/view/selection.js +16 -0
  87. package/src/view/stylesmap.js +26 -11
  88. package/src/view/text.js +6 -0
  89. package/src/view/textproxy.js +12 -0
  90. package/src/view/tokenlist.js +4 -6
  91. package/src/view/treewalker.js +42 -0
  92. package/src/view/upcastwriter.js +5 -1
  93. package/src/view/view.js +51 -33
@@ -5,25 +5,36 @@
5
5
  /**
6
6
  * @module engine/view/stylesmap
7
7
  */
8
- import { get, isObject, merge, set, unset } from 'lodash-es';
8
+ import { get, isObject, merge, set, unset } from 'es-toolkit/compat';
9
9
  import { toArray } from '@ckeditor/ckeditor5-utils';
10
10
  import { isPatternMatched } from './matcher.js';
11
11
  /**
12
12
  * Styles map. Allows handling (adding, removing, retrieving) a set of style rules (usually, of an element).
13
13
  */
14
14
  export default class StylesMap {
15
+ /**
16
+ * Keeps an internal representation of styles map. Normalized styles are kept as object tree to allow unified modification and
17
+ * value access model using lodash's get, set, unset, etc methods.
18
+ *
19
+ * When no style processor rules are defined it acts as simple key-value storage.
20
+ */
21
+ _styles;
22
+ /**
23
+ * Cached list of style names for faster access.
24
+ */
25
+ _cachedStyleNames = null;
26
+ /**
27
+ * Cached list of expanded style names for faster access.
28
+ */
29
+ _cachedExpandedStyleNames = null;
30
+ /**
31
+ * An instance of the {@link module:engine/view/stylesmap~StylesProcessor}.
32
+ */
33
+ _styleProcessor;
15
34
  /**
16
35
  * Creates Styles instance.
17
36
  */
18
37
  constructor(styleProcessor) {
19
- /**
20
- * Cached list of style names for faster access.
21
- */
22
- this._cachedStyleNames = null;
23
- /**
24
- * Cached list of expanded style names for faster access.
25
- */
26
- this._cachedExpandedStyleNames = null;
27
38
  this._styles = {};
28
39
  this._styleProcessor = styleProcessor;
29
40
  }
@@ -303,10 +314,10 @@ export default class StylesMap {
303
314
  return [];
304
315
  }
305
316
  if (expand) {
306
- this._cachedExpandedStyleNames = this._cachedExpandedStyleNames || this._styleProcessor.getStyleNames(this._styles);
317
+ this._cachedExpandedStyleNames ||= this._styleProcessor.getStyleNames(this._styles);
307
318
  return this._cachedExpandedStyleNames;
308
319
  }
309
- this._cachedStyleNames = this._cachedStyleNames || this.getStylesEntries().map(([key]) => key);
320
+ this._cachedStyleNames ||= this.getStylesEntries().map(([key]) => key);
310
321
  return this._cachedStyleNames;
311
322
  }
312
323
  /**
@@ -483,6 +494,10 @@ export default class StylesMap {
483
494
  * Style processor is responsible for writing and reading a normalized styles object.
484
495
  */
485
496
  export class StylesProcessor {
497
+ _normalizers;
498
+ _extractors;
499
+ _reducers;
500
+ _consumables;
486
501
  /**
487
502
  * Creates StylesProcessor instance.
488
503
  *
package/src/view/text.js CHANGED
@@ -16,6 +16,12 @@ import Node from './node.js';
16
16
  * method when working on non-semantic views.
17
17
  */
18
18
  export default class Text extends Node {
19
+ /**
20
+ * The text content.
21
+ *
22
+ * Setting the data fires the {@link module:engine/view/node~Node#event:change:text change event}.
23
+ */
24
+ _textData;
19
25
  /**
20
26
  * Creates a tree view text node.
21
27
  *
@@ -28,6 +28,18 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
28
28
  * an instance of this class by your own.
29
29
  */
30
30
  export default class TextProxy extends TypeCheckable {
31
+ /**
32
+ * Reference to the {@link module:engine/view/text~Text} element which TextProxy is a substring.
33
+ */
34
+ textNode;
35
+ /**
36
+ * Text data represented by this text proxy.
37
+ */
38
+ data;
39
+ /**
40
+ * Offset in the `textNode` where this `TextProxy` instance starts.
41
+ */
42
+ offsetInText;
31
43
  /**
32
44
  * Creates a text proxy.
33
45
  *
@@ -10,12 +10,10 @@ import { toArray } from '@ckeditor/ckeditor5-utils';
10
10
  * Token list. Allows handling (adding, removing, retrieving) a set of tokens (for example class names).
11
11
  */
12
12
  export default class TokenList {
13
- constructor() {
14
- /**
15
- * The set of tokens.
16
- */
17
- this._set = new Set();
18
- }
13
+ /**
14
+ * The set of tokens.
15
+ */
16
+ _set = new Set();
19
17
  /**
20
18
  * Returns true if token list has no tokens set.
21
19
  */
@@ -9,6 +9,48 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
9
9
  * Position iterator class. It allows to iterate forward and backward over the document.
10
10
  */
11
11
  export default class TreeWalker {
12
+ /**
13
+ * Walking direction. Defaults `'forward'`.
14
+ */
15
+ direction;
16
+ /**
17
+ * Iterator boundaries.
18
+ *
19
+ * When the iterator is walking `'forward'` on the end of boundary or is walking `'backward'`
20
+ * on the start of boundary, then `{ done: true }` is returned.
21
+ *
22
+ * If boundaries are not defined they are set before first and after last child of the root node.
23
+ */
24
+ boundaries;
25
+ /**
26
+ * Flag indicating whether all characters from {@link module:engine/view/text~Text} should be returned as one
27
+ * {@link module:engine/view/text~Text} or one by one as {@link module:engine/view/textproxy~TextProxy}.
28
+ */
29
+ singleCharacters;
30
+ /**
31
+ * Flag indicating whether iterator should enter elements or not. If the iterator is shallow child nodes of any
32
+ * iterated node will not be returned along with `elementEnd` tag.
33
+ */
34
+ shallow;
35
+ /**
36
+ * Flag indicating whether iterator should ignore `elementEnd` tags. If set to `true`, walker will not
37
+ * return a parent node of the start position. Each {@link module:engine/view/element~Element} will be returned once.
38
+ * When set to `false` each element might be returned twice: for `'elementStart'` and `'elementEnd'`.
39
+ */
40
+ ignoreElementEnd;
41
+ /**
42
+ * Iterator position. If start position is not defined then position depends on {@link #direction}. If direction is
43
+ * `'forward'` position starts form the beginning, when direction is `'backward'` position starts from the end.
44
+ */
45
+ _position;
46
+ /**
47
+ * Start boundary parent.
48
+ */
49
+ _boundaryStartParent;
50
+ /**
51
+ * End boundary parent.
52
+ */
53
+ _boundaryEndParent;
12
54
  /**
13
55
  * Creates a range iterator. All parameters are optional, but you have to specify either `boundaries` or `startPosition`.
14
56
  *
@@ -8,7 +8,7 @@
8
8
  import DocumentFragment from './documentfragment.js';
9
9
  import Element from './element.js';
10
10
  import Text from './text.js';
11
- import { isPlainObject } from 'lodash-es';
11
+ import { isPlainObject } from 'es-toolkit/compat';
12
12
  import Position from './position.js';
13
13
  import Range from './range.js';
14
14
  import Selection from './selection.js';
@@ -34,6 +34,10 @@ import Selection from './selection.js';
34
34
  * ```
35
35
  */
36
36
  export default class UpcastWriter {
37
+ /**
38
+ * The view document instance in which this upcast writer operates.
39
+ */
40
+ document;
37
41
  /**
38
42
  * @param document The view document instance in which this upcast writer operates.
39
43
  */
package/src/view/view.js CHANGED
@@ -24,7 +24,7 @@ import TabObserver from './observer/tabobserver.js';
24
24
  import { CKEditorError, env, ObservableMixin, scrollViewportToShowTarget } from '@ckeditor/ckeditor5-utils';
25
25
  import { injectUiElementHandling } from './uielement.js';
26
26
  import { injectQuirksHandling } from './filler.js';
27
- import { cloneDeep } from 'lodash-es';
27
+ import { cloneDeep } from 'es-toolkit/compat';
28
28
  /**
29
29
  * Editor's view controller class. Its main responsibility is DOM - View management for editing purposes, to provide
30
30
  * abstraction over the DOM structure and events and hide all browsers quirks.
@@ -58,43 +58,61 @@ import { cloneDeep } from 'lodash-es';
58
58
  * elements you do not need this controller. You can use the {@link module:engine/view/domconverter~DomConverter DomConverter} instead.
59
59
  */
60
60
  export default class View extends /* #__PURE__ */ ObservableMixin() {
61
+ /**
62
+ * Instance of the {@link module:engine/view/document~Document} associated with this view controller.
63
+ */
64
+ document;
65
+ /**
66
+ * Instance of the {@link module:engine/view/domconverter~DomConverter domConverter} used by
67
+ * {@link module:engine/view/view~View#_renderer renderer}
68
+ * and {@link module:engine/view/observer/observer~Observer observers}.
69
+ */
70
+ domConverter;
71
+ /**
72
+ * Roots of the DOM tree. Map on the `HTMLElement`s with roots names as keys.
73
+ */
74
+ domRoots = new Map();
75
+ /**
76
+ * Instance of the {@link module:engine/view/renderer~Renderer renderer}.
77
+ */
78
+ _renderer;
79
+ /**
80
+ * A DOM root attributes cache. It saves the initial values of DOM root attributes before the DOM element
81
+ * is {@link module:engine/view/view~View#attachDomRoot attached} to the view so later on, when
82
+ * the view is destroyed ({@link module:engine/view/view~View#detachDomRoot}), they can be easily restored.
83
+ * This way, the DOM element can go back to the (clean) state as if the editing view never used it.
84
+ */
85
+ _initialDomRootAttributes = new WeakMap();
86
+ /**
87
+ * Map of registered {@link module:engine/view/observer/observer~Observer observers}.
88
+ */
89
+ _observers = new Map();
90
+ /**
91
+ * DowncastWriter instance used in {@link #change change method} callbacks.
92
+ */
93
+ _writer;
94
+ /**
95
+ * Is set to `true` when {@link #change view changes} are currently in progress.
96
+ */
97
+ _ongoingChange = false;
98
+ /**
99
+ * Used to prevent calling {@link #forceRender} and {@link #change} during rendering view to the DOM.
100
+ */
101
+ _postFixersInProgress = false;
102
+ /**
103
+ * Internal flag to temporary disable rendering. See the usage in the {@link #_disableRendering}.
104
+ */
105
+ _renderingDisabled = false;
106
+ /**
107
+ * Internal flag that disables rendering when there are no changes since the last rendering.
108
+ * It stores information about changed selection and changed elements from attached document roots.
109
+ */
110
+ _hasChangedSinceTheLastRendering = false;
61
111
  /**
62
112
  * @param stylesProcessor The styles processor instance.
63
113
  */
64
114
  constructor(stylesProcessor) {
65
115
  super();
66
- /**
67
- * Roots of the DOM tree. Map on the `HTMLElement`s with roots names as keys.
68
- */
69
- this.domRoots = new Map();
70
- /**
71
- * A DOM root attributes cache. It saves the initial values of DOM root attributes before the DOM element
72
- * is {@link module:engine/view/view~View#attachDomRoot attached} to the view so later on, when
73
- * the view is destroyed ({@link module:engine/view/view~View#detachDomRoot}), they can be easily restored.
74
- * This way, the DOM element can go back to the (clean) state as if the editing view never used it.
75
- */
76
- this._initialDomRootAttributes = new WeakMap();
77
- /**
78
- * Map of registered {@link module:engine/view/observer/observer~Observer observers}.
79
- */
80
- this._observers = new Map();
81
- /**
82
- * Is set to `true` when {@link #change view changes} are currently in progress.
83
- */
84
- this._ongoingChange = false;
85
- /**
86
- * Used to prevent calling {@link #forceRender} and {@link #change} during rendering view to the DOM.
87
- */
88
- this._postFixersInProgress = false;
89
- /**
90
- * Internal flag to temporary disable rendering. See the usage in the {@link #_disableRendering}.
91
- */
92
- this._renderingDisabled = false;
93
- /**
94
- * Internal flag that disables rendering when there are no changes since the last rendering.
95
- * It stores information about changed selection and changed elements from attached document roots.
96
- */
97
- this._hasChangedSinceTheLastRendering = false;
98
116
  this.document = new Document(stylesProcessor);
99
117
  this.domConverter = new DomConverter(this.document);
100
118
  this.set('isRenderingInProgress', false);