@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.
- package/CHANGELOG.md +823 -0
- package/LICENSE.md +4 -0
- package/package.json +32 -25
- package/src/controller/datacontroller.js +467 -561
- package/src/controller/editingcontroller.js +168 -204
- package/src/conversion/conversion.js +541 -565
- package/src/conversion/conversionhelpers.js +24 -28
- package/src/conversion/downcastdispatcher.js +457 -686
- package/src/conversion/downcasthelpers.js +1583 -1965
- package/src/conversion/mapper.js +518 -707
- package/src/conversion/modelconsumable.js +240 -283
- package/src/conversion/upcastdispatcher.js +372 -718
- package/src/conversion/upcasthelpers.js +707 -818
- package/src/conversion/viewconsumable.js +524 -581
- package/src/dataprocessor/basichtmlwriter.js +12 -16
- package/src/dataprocessor/dataprocessor.js +5 -0
- package/src/dataprocessor/htmldataprocessor.js +101 -117
- package/src/dataprocessor/htmlwriter.js +1 -18
- package/src/dataprocessor/xmldataprocessor.js +117 -138
- package/src/dev-utils/model.js +260 -352
- package/src/dev-utils/operationreplayer.js +106 -126
- package/src/dev-utils/utils.js +34 -51
- package/src/dev-utils/view.js +632 -753
- package/src/index.js +0 -11
- package/src/model/batch.js +111 -127
- package/src/model/differ.js +988 -1233
- package/src/model/document.js +340 -449
- package/src/model/documentfragment.js +327 -364
- package/src/model/documentselection.js +996 -1189
- package/src/model/element.js +306 -410
- package/src/model/history.js +224 -262
- package/src/model/item.js +5 -0
- package/src/model/liveposition.js +84 -145
- package/src/model/liverange.js +108 -185
- package/src/model/markercollection.js +379 -480
- package/src/model/model.js +883 -1034
- package/src/model/node.js +419 -463
- package/src/model/nodelist.js +175 -201
- package/src/model/operation/attributeoperation.js +153 -182
- package/src/model/operation/detachoperation.js +64 -83
- package/src/model/operation/insertoperation.js +135 -166
- package/src/model/operation/markeroperation.js +114 -140
- package/src/model/operation/mergeoperation.js +163 -191
- package/src/model/operation/moveoperation.js +157 -187
- package/src/model/operation/nooperation.js +28 -38
- package/src/model/operation/operation.js +106 -125
- package/src/model/operation/operationfactory.js +30 -34
- package/src/model/operation/renameoperation.js +109 -135
- package/src/model/operation/rootattributeoperation.js +155 -188
- package/src/model/operation/splitoperation.js +196 -232
- package/src/model/operation/transform.js +1833 -2204
- package/src/model/operation/utils.js +140 -204
- package/src/model/position.js +899 -1053
- package/src/model/range.js +910 -1028
- package/src/model/rootelement.js +77 -97
- package/src/model/schema.js +1189 -1835
- package/src/model/selection.js +745 -862
- package/src/model/text.js +90 -114
- package/src/model/textproxy.js +204 -240
- package/src/model/treewalker.js +316 -397
- package/src/model/typecheckable.js +16 -0
- package/src/model/utils/autoparagraphing.js +32 -44
- package/src/model/utils/deletecontent.js +334 -418
- package/src/model/utils/findoptimalinsertionrange.js +25 -36
- package/src/model/utils/getselectedcontent.js +96 -118
- package/src/model/utils/insertcontent.js +654 -773
- package/src/model/utils/insertobject.js +96 -119
- package/src/model/utils/modifyselection.js +120 -158
- package/src/model/utils/selection-post-fixer.js +153 -201
- package/src/model/writer.js +1305 -1474
- package/src/view/attributeelement.js +189 -225
- package/src/view/containerelement.js +75 -85
- package/src/view/document.js +172 -215
- package/src/view/documentfragment.js +200 -249
- package/src/view/documentselection.js +338 -367
- package/src/view/domconverter.js +1371 -1613
- package/src/view/downcastwriter.js +1747 -2076
- package/src/view/editableelement.js +81 -97
- package/src/view/element.js +739 -890
- package/src/view/elementdefinition.js +5 -0
- package/src/view/emptyelement.js +82 -92
- package/src/view/filler.js +35 -50
- package/src/view/item.js +5 -0
- package/src/view/matcher.js +260 -559
- package/src/view/node.js +274 -360
- package/src/view/observer/arrowkeysobserver.js +19 -28
- package/src/view/observer/bubblingemittermixin.js +120 -263
- package/src/view/observer/bubblingeventinfo.js +47 -55
- package/src/view/observer/clickobserver.js +7 -13
- package/src/view/observer/compositionobserver.js +14 -24
- package/src/view/observer/domeventdata.js +57 -67
- package/src/view/observer/domeventobserver.js +40 -64
- package/src/view/observer/fakeselectionobserver.js +81 -96
- package/src/view/observer/focusobserver.js +45 -61
- package/src/view/observer/inputobserver.js +7 -13
- package/src/view/observer/keyobserver.js +17 -27
- package/src/view/observer/mouseobserver.js +7 -14
- package/src/view/observer/mutationobserver.js +220 -315
- package/src/view/observer/observer.js +81 -102
- package/src/view/observer/selectionobserver.js +191 -246
- package/src/view/observer/tabobserver.js +23 -36
- package/src/view/placeholder.js +128 -173
- package/src/view/position.js +350 -401
- package/src/view/range.js +453 -513
- package/src/view/rawelement.js +85 -112
- package/src/view/renderer.js +874 -1014
- package/src/view/rooteditableelement.js +80 -90
- package/src/view/selection.js +608 -689
- package/src/view/styles/background.js +43 -44
- package/src/view/styles/border.js +220 -276
- package/src/view/styles/margin.js +8 -17
- package/src/view/styles/padding.js +8 -16
- package/src/view/styles/utils.js +127 -160
- package/src/view/stylesmap.js +728 -905
- package/src/view/text.js +102 -126
- package/src/view/textproxy.js +144 -170
- package/src/view/treewalker.js +383 -479
- package/src/view/typecheckable.js +19 -0
- package/src/view/uielement.js +166 -187
- package/src/view/upcastwriter.js +395 -449
- package/src/view/view.js +569 -664
- package/src/dataprocessor/dataprocessor.jsdoc +0 -64
- package/src/model/item.jsdoc +0 -14
- package/src/view/elementdefinition.jsdoc +0 -59
- package/src/view/item.jsdoc +0 -14
package/src/view/placeholder.js
CHANGED
|
@@ -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(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
}
|