@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,16 +2,12 @@
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
-
6
5
  /**
7
6
  * @module engine/view/placeholder
8
7
  */
9
-
10
8
  import '../../theme/placeholder.css';
11
-
12
9
  // Each document stores information about its placeholder elements and check functions.
13
10
  const documentPlaceholders = new WeakMap();
14
-
15
11
  /**
16
12
  * A helper that enables a placeholder on the provided view element (also updates its visibility).
17
13
  * The placeholder is a CSS pseudo–element (with a text content) attached to the element.
@@ -31,31 +27,26 @@ const documentPlaceholders = new WeakMap();
31
27
  * editable root elements.
32
28
  * @param {Boolean} [options.keepOnFocus=false] If set `true`, the placeholder stay visible when the host element is focused.
33
29
  */
34
- export function enablePlaceholder( options ) {
35
- const { view, element, text, isDirectHost = true, keepOnFocus = false } = options;
36
- const doc = view.document;
37
-
38
- // Use a single a single post fixer per—document to update all placeholders.
39
- if ( !documentPlaceholders.has( doc ) ) {
40
- documentPlaceholders.set( doc, new Map() );
41
-
42
- // If a post-fixer callback makes a change, it should return `true` so other post–fixers
43
- // can re–evaluate the document again.
44
- doc.registerPostFixer( writer => updateDocumentPlaceholders( doc, writer ) );
45
- }
46
-
47
- // Store information about the element placeholder under its document.
48
- documentPlaceholders.get( doc ).set( element, {
49
- text,
50
- isDirectHost,
51
- keepOnFocus,
52
- hostElement: isDirectHost ? element : null
53
- } );
54
-
55
- // Update the placeholders right away.
56
- view.change( writer => updateDocumentPlaceholders( doc, writer ) );
30
+ export function enablePlaceholder(options) {
31
+ const { view, element, text, isDirectHost = true, keepOnFocus = false } = options;
32
+ const doc = view.document;
33
+ // Use a single a single post fixer per—document to update all placeholders.
34
+ if (!documentPlaceholders.has(doc)) {
35
+ documentPlaceholders.set(doc, new Map());
36
+ // If a post-fixer callback makes a change, it should return `true` so other post–fixers
37
+ // can re–evaluate the document again.
38
+ doc.registerPostFixer(writer => updateDocumentPlaceholders(doc, writer));
39
+ }
40
+ // Store information about the element placeholder under its document.
41
+ documentPlaceholders.get(doc).set(element, {
42
+ text,
43
+ isDirectHost,
44
+ keepOnFocus,
45
+ hostElement: isDirectHost ? element : null
46
+ });
47
+ // Update the placeholders right away.
48
+ view.change(writer => updateDocumentPlaceholders(doc, writer));
57
49
  }
58
-
59
50
  /**
60
51
  * Disables the placeholder functionality from a given element.
61
52
  *
@@ -64,24 +55,19 @@ export function enablePlaceholder( options ) {
64
55
  * @param {module:engine/view/view~View} view
65
56
  * @param {module:engine/view/element~Element} element
66
57
  */
67
- export function disablePlaceholder( view, element ) {
68
- const doc = element.document;
69
-
70
- view.change( writer => {
71
- if ( !documentPlaceholders.has( doc ) ) {
72
- return;
73
- }
74
-
75
- const placeholders = documentPlaceholders.get( doc );
76
- const config = placeholders.get( element );
77
-
78
- writer.removeAttribute( 'data-placeholder', config.hostElement );
79
- hidePlaceholder( writer, config.hostElement );
80
-
81
- placeholders.delete( element );
82
- } );
58
+ export function disablePlaceholder(view, element) {
59
+ const doc = element.document;
60
+ view.change(writer => {
61
+ if (!documentPlaceholders.has(doc)) {
62
+ return;
63
+ }
64
+ const placeholders = documentPlaceholders.get(doc);
65
+ const config = placeholders.get(element);
66
+ writer.removeAttribute('data-placeholder', config.hostElement);
67
+ hidePlaceholder(writer, config.hostElement);
68
+ placeholders.delete(element);
69
+ });
83
70
  }
84
-
85
71
  /**
86
72
  * Shows a placeholder in the provided element by changing related attributes and CSS classes.
87
73
  *
@@ -100,16 +86,13 @@ export function disablePlaceholder( view, element ) {
100
86
  * @param {module:engine/view/element~Element} element
101
87
  * @returns {Boolean} `true`, if any changes were made to the `element`.
102
88
  */
103
- export function showPlaceholder( writer, element ) {
104
- if ( !element.hasClass( 'ck-placeholder' ) ) {
105
- writer.addClass( 'ck-placeholder', element );
106
-
107
- return true;
108
- }
109
-
110
- return false;
89
+ export function showPlaceholder(writer, element) {
90
+ if (!element.hasClass('ck-placeholder')) {
91
+ writer.addClass('ck-placeholder', element);
92
+ return true;
93
+ }
94
+ return false;
111
95
  }
112
-
113
96
  /**
114
97
  * Hides a placeholder in the element by changing related attributes and CSS classes.
115
98
  *
@@ -123,16 +106,13 @@ export function showPlaceholder( writer, element ) {
123
106
  * @param {module:engine/view/element~Element} element
124
107
  * @returns {Boolean} `true`, if any changes were made to the `element`.
125
108
  */
126
- export function hidePlaceholder( writer, element ) {
127
- if ( element.hasClass( 'ck-placeholder' ) ) {
128
- writer.removeClass( 'ck-placeholder', element );
129
-
130
- return true;
131
- }
132
-
133
- return false;
109
+ export function hidePlaceholder(writer, element) {
110
+ if (element.hasClass('ck-placeholder')) {
111
+ writer.removeClass('ck-placeholder', element);
112
+ return true;
113
+ }
114
+ return false;
134
115
  }
135
-
136
116
  /**
137
117
  * Checks if a placeholder should be displayed in the element.
138
118
  *
@@ -147,90 +127,72 @@ export function hidePlaceholder( writer, element ) {
147
127
  * @param {Boolean} keepOnFocus Focusing the element will keep the placeholder visible.
148
128
  * @returns {Boolean}
149
129
  */
150
- export function needsPlaceholder( element, keepOnFocus ) {
151
- if ( !element.isAttached() ) {
152
- return false;
153
- }
154
-
155
- // Anything but uiElement(s) counts as content.
156
- const hasContent = Array.from( element.getChildren() )
157
- .some( element => !element.is( 'uiElement' ) );
158
-
159
- if ( hasContent ) {
160
- return false;
161
- }
162
-
163
- // Skip the focus check and make the placeholder visible already regardless of document focus state.
164
- if ( keepOnFocus ) {
165
- return true;
166
- }
167
-
168
- const doc = element.document;
169
-
170
- // If the document is blurred.
171
- if ( !doc.isFocused ) {
172
- return true;
173
- }
174
-
175
- const viewSelection = doc.selection;
176
- const selectionAnchor = viewSelection.anchor;
177
-
178
- // If document is focused and the element is empty but the selection is not anchored inside it.
179
- return selectionAnchor && selectionAnchor.parent !== element;
130
+ export function needsPlaceholder(element, keepOnFocus) {
131
+ if (!element.isAttached()) {
132
+ return false;
133
+ }
134
+ // Anything but uiElement(s) counts as content.
135
+ const hasContent = Array.from(element.getChildren())
136
+ .some(element => !element.is('uiElement'));
137
+ if (hasContent) {
138
+ return false;
139
+ }
140
+ // Skip the focus check and make the placeholder visible already regardless of document focus state.
141
+ if (keepOnFocus) {
142
+ return true;
143
+ }
144
+ const doc = element.document;
145
+ // If the document is blurred.
146
+ if (!doc.isFocused) {
147
+ return true;
148
+ }
149
+ const viewSelection = doc.selection;
150
+ const selectionAnchor = viewSelection.anchor;
151
+ // If document is focused and the element is empty but the selection is not anchored inside it.
152
+ return !!selectionAnchor && selectionAnchor.parent !== element;
180
153
  }
181
-
182
154
  // Updates all placeholders associated with a document in a post–fixer callback.
183
155
  //
184
156
  // @private
185
157
  // @param { module:engine/view/document~Document} doc
186
158
  // @param {module:engine/view/downcastwriter~DowncastWriter} writer
187
159
  // @returns {Boolean} True if any changes were made to the view document.
188
- function updateDocumentPlaceholders( doc, writer ) {
189
- const placeholders = documentPlaceholders.get( doc );
190
- const directHostElements = [];
191
- let wasViewModified = false;
192
-
193
- // First set placeholders on the direct hosts.
194
- for ( const [ element, config ] of placeholders ) {
195
- if ( config.isDirectHost ) {
196
- directHostElements.push( element );
197
-
198
- if ( updatePlaceholder( writer, element, config ) ) {
199
- wasViewModified = true;
200
- }
201
- }
202
- }
203
-
204
- // Then set placeholders on the indirect hosts but only on those that does not already have an direct host placeholder.
205
- for ( const [ element, config ] of placeholders ) {
206
- if ( config.isDirectHost ) {
207
- continue;
208
- }
209
-
210
- const hostElement = getChildPlaceholderHostSubstitute( element );
211
-
212
- // When not a direct host, it could happen that there is no child element
213
- // capable of displaying a placeholder.
214
- if ( !hostElement ) {
215
- continue;
216
- }
217
-
218
- // Don't override placeholder if the host element already has some direct placeholder.
219
- if ( directHostElements.includes( hostElement ) ) {
220
- continue;
221
- }
222
-
223
- // Update the host element (used for setting and removing the placeholder).
224
- config.hostElement = hostElement;
225
-
226
- if ( updatePlaceholder( writer, element, config ) ) {
227
- wasViewModified = true;
228
- }
229
- }
230
-
231
- return wasViewModified;
160
+ function updateDocumentPlaceholders(doc, writer) {
161
+ const placeholders = documentPlaceholders.get(doc);
162
+ const directHostElements = [];
163
+ let wasViewModified = false;
164
+ // First set placeholders on the direct hosts.
165
+ for (const [element, config] of placeholders) {
166
+ if (config.isDirectHost) {
167
+ directHostElements.push(element);
168
+ if (updatePlaceholder(writer, element, config)) {
169
+ wasViewModified = true;
170
+ }
171
+ }
172
+ }
173
+ // Then set placeholders on the indirect hosts but only on those that does not already have an direct host placeholder.
174
+ for (const [element, config] of placeholders) {
175
+ if (config.isDirectHost) {
176
+ continue;
177
+ }
178
+ const hostElement = getChildPlaceholderHostSubstitute(element);
179
+ // When not a direct host, it could happen that there is no child element
180
+ // capable of displaying a placeholder.
181
+ if (!hostElement) {
182
+ continue;
183
+ }
184
+ // Don't override placeholder if the host element already has some direct placeholder.
185
+ if (directHostElements.includes(hostElement)) {
186
+ continue;
187
+ }
188
+ // Update the host element (used for setting and removing the placeholder).
189
+ config.hostElement = hostElement;
190
+ if (updatePlaceholder(writer, element, config)) {
191
+ wasViewModified = true;
192
+ }
193
+ }
194
+ return wasViewModified;
232
195
  }
233
-
234
196
  // Updates a single placeholder in a post–fixer callback.
235
197
  //
236
198
  // @private
@@ -240,31 +202,26 @@ function updateDocumentPlaceholders( doc, writer ) {
240
202
  // @param {String} config.text
241
203
  // @param {Boolean} config.isDirectHost
242
204
  // @returns {Boolean} True if any changes were made to the view document.
243
- function updatePlaceholder( writer, element, config ) {
244
- const { text, isDirectHost, hostElement } = config;
245
-
246
- let wasViewModified = false;
247
-
248
- // This may be necessary when updating the placeholder text to something else.
249
- if ( hostElement.getAttribute( 'data-placeholder' ) !== text ) {
250
- writer.setAttribute( 'data-placeholder', text, hostElement );
251
- wasViewModified = true;
252
- }
253
-
254
- // If the host element is not a direct host then placeholder is needed only when there is only one element.
255
- const isOnlyChild = isDirectHost || element.childCount == 1;
256
-
257
- if ( isOnlyChild && needsPlaceholder( hostElement, config.keepOnFocus ) ) {
258
- if ( showPlaceholder( writer, hostElement ) ) {
259
- wasViewModified = true;
260
- }
261
- } else if ( hidePlaceholder( writer, hostElement ) ) {
262
- wasViewModified = true;
263
- }
264
-
265
- return wasViewModified;
205
+ function updatePlaceholder(writer, element, config) {
206
+ const { text, isDirectHost, hostElement } = config;
207
+ let wasViewModified = false;
208
+ // This may be necessary when updating the placeholder text to something else.
209
+ if (hostElement.getAttribute('data-placeholder') !== text) {
210
+ writer.setAttribute('data-placeholder', text, hostElement);
211
+ wasViewModified = true;
212
+ }
213
+ // If the host element is not a direct host then placeholder is needed only when there is only one element.
214
+ const isOnlyChild = isDirectHost || element.childCount == 1;
215
+ if (isOnlyChild && needsPlaceholder(hostElement, config.keepOnFocus)) {
216
+ if (showPlaceholder(writer, hostElement)) {
217
+ wasViewModified = true;
218
+ }
219
+ }
220
+ else if (hidePlaceholder(writer, hostElement)) {
221
+ wasViewModified = true;
222
+ }
223
+ return wasViewModified;
266
224
  }
267
-
268
225
  // Gets a child element capable of displaying a placeholder if a parent element can host more
269
226
  // than just text (for instance, when it is a root editable element). The child element
270
227
  // can then be used in other placeholder helpers as a substitute of its parent.
@@ -272,14 +229,12 @@ function updatePlaceholder( writer, element, config ) {
272
229
  // @private
273
230
  // @param {module:engine/view/element~Element} parent
274
231
  // @returns {module:engine/view/element~Element|null}
275
- function getChildPlaceholderHostSubstitute( parent ) {
276
- if ( parent.childCount ) {
277
- const firstChild = parent.getChild( 0 );
278
-
279
- if ( firstChild.is( 'element' ) && !firstChild.is( 'uiElement' ) && !firstChild.is( 'attributeElement' ) ) {
280
- return firstChild;
281
- }
282
- }
283
-
284
- return null;
232
+ function getChildPlaceholderHostSubstitute(parent) {
233
+ if (parent.childCount) {
234
+ const firstChild = parent.getChild(0);
235
+ if (firstChild.is('element') && !firstChild.is('uiElement') && !firstChild.is('attributeElement')) {
236
+ return firstChild;
237
+ }
238
+ }
239
+ return null;
285
240
  }