@ckeditor/ckeditor5-engine 35.0.1 → 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 (124) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/package.json +30 -24
  3. package/src/controller/datacontroller.js +467 -561
  4. package/src/controller/editingcontroller.js +168 -204
  5. package/src/conversion/conversion.js +541 -565
  6. package/src/conversion/conversionhelpers.js +24 -28
  7. package/src/conversion/downcastdispatcher.js +457 -686
  8. package/src/conversion/downcasthelpers.js +1583 -1965
  9. package/src/conversion/mapper.js +518 -707
  10. package/src/conversion/modelconsumable.js +240 -283
  11. package/src/conversion/upcastdispatcher.js +372 -718
  12. package/src/conversion/upcasthelpers.js +707 -818
  13. package/src/conversion/viewconsumable.js +524 -581
  14. package/src/dataprocessor/basichtmlwriter.js +12 -16
  15. package/src/dataprocessor/dataprocessor.js +5 -0
  16. package/src/dataprocessor/htmldataprocessor.js +100 -116
  17. package/src/dataprocessor/htmlwriter.js +1 -18
  18. package/src/dataprocessor/xmldataprocessor.js +116 -137
  19. package/src/dev-utils/model.js +260 -352
  20. package/src/dev-utils/operationreplayer.js +106 -126
  21. package/src/dev-utils/utils.js +34 -51
  22. package/src/dev-utils/view.js +632 -753
  23. package/src/index.js +0 -11
  24. package/src/model/batch.js +111 -127
  25. package/src/model/differ.js +988 -1233
  26. package/src/model/document.js +340 -449
  27. package/src/model/documentfragment.js +327 -364
  28. package/src/model/documentselection.js +996 -1189
  29. package/src/model/element.js +306 -410
  30. package/src/model/history.js +224 -262
  31. package/src/model/item.js +5 -0
  32. package/src/model/liveposition.js +84 -145
  33. package/src/model/liverange.js +108 -185
  34. package/src/model/markercollection.js +379 -480
  35. package/src/model/model.js +883 -1034
  36. package/src/model/node.js +419 -463
  37. package/src/model/nodelist.js +175 -201
  38. package/src/model/operation/attributeoperation.js +153 -182
  39. package/src/model/operation/detachoperation.js +64 -83
  40. package/src/model/operation/insertoperation.js +135 -166
  41. package/src/model/operation/markeroperation.js +114 -140
  42. package/src/model/operation/mergeoperation.js +163 -191
  43. package/src/model/operation/moveoperation.js +157 -187
  44. package/src/model/operation/nooperation.js +28 -38
  45. package/src/model/operation/operation.js +106 -125
  46. package/src/model/operation/operationfactory.js +30 -34
  47. package/src/model/operation/renameoperation.js +109 -135
  48. package/src/model/operation/rootattributeoperation.js +155 -188
  49. package/src/model/operation/splitoperation.js +196 -232
  50. package/src/model/operation/transform.js +1833 -2204
  51. package/src/model/operation/utils.js +140 -204
  52. package/src/model/position.js +899 -1053
  53. package/src/model/range.js +910 -1028
  54. package/src/model/rootelement.js +77 -97
  55. package/src/model/schema.js +1189 -1835
  56. package/src/model/selection.js +745 -862
  57. package/src/model/text.js +90 -114
  58. package/src/model/textproxy.js +204 -240
  59. package/src/model/treewalker.js +316 -397
  60. package/src/model/typecheckable.js +16 -0
  61. package/src/model/utils/autoparagraphing.js +32 -44
  62. package/src/model/utils/deletecontent.js +334 -418
  63. package/src/model/utils/findoptimalinsertionrange.js +25 -36
  64. package/src/model/utils/getselectedcontent.js +96 -118
  65. package/src/model/utils/insertcontent.js +654 -773
  66. package/src/model/utils/insertobject.js +96 -119
  67. package/src/model/utils/modifyselection.js +120 -158
  68. package/src/model/utils/selection-post-fixer.js +153 -201
  69. package/src/model/writer.js +1305 -1474
  70. package/src/view/attributeelement.js +189 -225
  71. package/src/view/containerelement.js +75 -85
  72. package/src/view/document.js +172 -215
  73. package/src/view/documentfragment.js +200 -249
  74. package/src/view/documentselection.js +338 -367
  75. package/src/view/domconverter.js +1370 -1617
  76. package/src/view/downcastwriter.js +1747 -2076
  77. package/src/view/editableelement.js +81 -97
  78. package/src/view/element.js +739 -890
  79. package/src/view/elementdefinition.js +5 -0
  80. package/src/view/emptyelement.js +82 -92
  81. package/src/view/filler.js +35 -50
  82. package/src/view/item.js +5 -0
  83. package/src/view/matcher.js +260 -559
  84. package/src/view/node.js +274 -360
  85. package/src/view/observer/arrowkeysobserver.js +19 -28
  86. package/src/view/observer/bubblingemittermixin.js +120 -263
  87. package/src/view/observer/bubblingeventinfo.js +47 -55
  88. package/src/view/observer/clickobserver.js +7 -13
  89. package/src/view/observer/compositionobserver.js +14 -24
  90. package/src/view/observer/domeventdata.js +57 -67
  91. package/src/view/observer/domeventobserver.js +40 -64
  92. package/src/view/observer/fakeselectionobserver.js +81 -96
  93. package/src/view/observer/focusobserver.js +45 -61
  94. package/src/view/observer/inputobserver.js +7 -13
  95. package/src/view/observer/keyobserver.js +17 -27
  96. package/src/view/observer/mouseobserver.js +7 -14
  97. package/src/view/observer/mutationobserver.js +220 -315
  98. package/src/view/observer/observer.js +81 -102
  99. package/src/view/observer/selectionobserver.js +191 -246
  100. package/src/view/observer/tabobserver.js +23 -36
  101. package/src/view/placeholder.js +128 -173
  102. package/src/view/position.js +350 -401
  103. package/src/view/range.js +453 -513
  104. package/src/view/rawelement.js +85 -112
  105. package/src/view/renderer.js +874 -1018
  106. package/src/view/rooteditableelement.js +80 -90
  107. package/src/view/selection.js +608 -689
  108. package/src/view/styles/background.js +43 -44
  109. package/src/view/styles/border.js +220 -276
  110. package/src/view/styles/margin.js +8 -17
  111. package/src/view/styles/padding.js +8 -16
  112. package/src/view/styles/utils.js +127 -160
  113. package/src/view/stylesmap.js +728 -905
  114. package/src/view/text.js +102 -126
  115. package/src/view/textproxy.js +144 -170
  116. package/src/view/treewalker.js +383 -479
  117. package/src/view/typecheckable.js +19 -0
  118. package/src/view/uielement.js +166 -187
  119. package/src/view/upcastwriter.js +395 -449
  120. package/src/view/view.js +569 -664
  121. package/src/dataprocessor/dataprocessor.jsdoc +0 -64
  122. package/src/model/item.jsdoc +0 -14
  123. package/src/view/elementdefinition.jsdoc +0 -59
  124. 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
  }