@ckeditor/ckeditor5-engine 30.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.
- package/LICENSE.md +17 -0
- package/README.md +30 -0
- package/package.json +70 -0
- package/src/controller/datacontroller.js +563 -0
- package/src/controller/editingcontroller.js +149 -0
- package/src/conversion/conversion.js +644 -0
- package/src/conversion/conversionhelpers.js +40 -0
- package/src/conversion/downcastdispatcher.js +914 -0
- package/src/conversion/downcasthelpers.js +1706 -0
- package/src/conversion/mapper.js +696 -0
- package/src/conversion/modelconsumable.js +329 -0
- package/src/conversion/upcastdispatcher.js +807 -0
- package/src/conversion/upcasthelpers.js +997 -0
- package/src/conversion/viewconsumable.js +623 -0
- package/src/dataprocessor/basichtmlwriter.js +32 -0
- package/src/dataprocessor/dataprocessor.jsdoc +64 -0
- package/src/dataprocessor/htmldataprocessor.js +159 -0
- package/src/dataprocessor/htmlwriter.js +22 -0
- package/src/dataprocessor/xmldataprocessor.js +161 -0
- package/src/dev-utils/model.js +482 -0
- package/src/dev-utils/operationreplayer.js +140 -0
- package/src/dev-utils/utils.js +103 -0
- package/src/dev-utils/view.js +1091 -0
- package/src/index.js +52 -0
- package/src/model/batch.js +82 -0
- package/src/model/differ.js +1282 -0
- package/src/model/document.js +483 -0
- package/src/model/documentfragment.js +390 -0
- package/src/model/documentselection.js +1261 -0
- package/src/model/element.js +438 -0
- package/src/model/history.js +138 -0
- package/src/model/item.jsdoc +14 -0
- package/src/model/liveposition.js +182 -0
- package/src/model/liverange.js +221 -0
- package/src/model/markercollection.js +553 -0
- package/src/model/model.js +934 -0
- package/src/model/node.js +507 -0
- package/src/model/nodelist.js +217 -0
- package/src/model/operation/attributeoperation.js +202 -0
- package/src/model/operation/detachoperation.js +103 -0
- package/src/model/operation/insertoperation.js +188 -0
- package/src/model/operation/markeroperation.js +154 -0
- package/src/model/operation/mergeoperation.js +216 -0
- package/src/model/operation/moveoperation.js +209 -0
- package/src/model/operation/nooperation.js +58 -0
- package/src/model/operation/operation.js +139 -0
- package/src/model/operation/operationfactory.js +49 -0
- package/src/model/operation/renameoperation.js +155 -0
- package/src/model/operation/rootattributeoperation.js +211 -0
- package/src/model/operation/splitoperation.js +254 -0
- package/src/model/operation/transform.js +2389 -0
- package/src/model/operation/utils.js +292 -0
- package/src/model/position.js +1164 -0
- package/src/model/range.js +1049 -0
- package/src/model/rootelement.js +111 -0
- package/src/model/schema.js +1851 -0
- package/src/model/selection.js +902 -0
- package/src/model/text.js +138 -0
- package/src/model/textproxy.js +279 -0
- package/src/model/treewalker.js +414 -0
- package/src/model/utils/autoparagraphing.js +77 -0
- package/src/model/utils/deletecontent.js +528 -0
- package/src/model/utils/getselectedcontent.js +150 -0
- package/src/model/utils/insertcontent.js +824 -0
- package/src/model/utils/modifyselection.js +229 -0
- package/src/model/utils/selection-post-fixer.js +297 -0
- package/src/model/writer.js +1574 -0
- package/src/view/attributeelement.js +274 -0
- package/src/view/containerelement.js +123 -0
- package/src/view/document.js +221 -0
- package/src/view/documentfragment.js +273 -0
- package/src/view/documentselection.js +387 -0
- package/src/view/domconverter.js +1437 -0
- package/src/view/downcastwriter.js +2121 -0
- package/src/view/editableelement.js +118 -0
- package/src/view/element.js +945 -0
- package/src/view/elementdefinition.jsdoc +59 -0
- package/src/view/emptyelement.js +119 -0
- package/src/view/filler.js +161 -0
- package/src/view/item.jsdoc +14 -0
- package/src/view/matcher.js +776 -0
- package/src/view/node.js +391 -0
- package/src/view/observer/arrowkeysobserver.js +58 -0
- package/src/view/observer/bubblingemittermixin.js +307 -0
- package/src/view/observer/bubblingeventinfo.js +71 -0
- package/src/view/observer/clickobserver.js +46 -0
- package/src/view/observer/compositionobserver.js +79 -0
- package/src/view/observer/domeventdata.js +82 -0
- package/src/view/observer/domeventobserver.js +99 -0
- package/src/view/observer/fakeselectionobserver.js +118 -0
- package/src/view/observer/focusobserver.js +106 -0
- package/src/view/observer/inputobserver.js +44 -0
- package/src/view/observer/keyobserver.js +83 -0
- package/src/view/observer/mouseobserver.js +56 -0
- package/src/view/observer/mutationobserver.js +345 -0
- package/src/view/observer/observer.js +118 -0
- package/src/view/observer/selectionobserver.js +242 -0
- package/src/view/placeholder.js +285 -0
- package/src/view/position.js +426 -0
- package/src/view/range.js +533 -0
- package/src/view/rawelement.js +148 -0
- package/src/view/renderer.js +1037 -0
- package/src/view/rooteditableelement.js +107 -0
- package/src/view/selection.js +718 -0
- package/src/view/styles/background.js +73 -0
- package/src/view/styles/border.js +362 -0
- package/src/view/styles/margin.js +41 -0
- package/src/view/styles/padding.js +40 -0
- package/src/view/styles/utils.js +277 -0
- package/src/view/stylesmap.js +938 -0
- package/src/view/text.js +147 -0
- package/src/view/textproxy.js +199 -0
- package/src/view/treewalker.js +496 -0
- package/src/view/uielement.js +238 -0
- package/src/view/upcastwriter.js +484 -0
- package/src/view/view.js +721 -0
- package/theme/placeholder.css +27 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module engine/controller/editingcontroller
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import RootEditableElement from '../view/rooteditableelement';
|
|
11
|
+
import View from '../view/view';
|
|
12
|
+
import Mapper from '../conversion/mapper';
|
|
13
|
+
import DowncastDispatcher from '../conversion/downcastdispatcher';
|
|
14
|
+
import { clearAttributes, convertCollapsedSelection, convertRangeSelection, insertText, remove } from '../conversion/downcasthelpers';
|
|
15
|
+
|
|
16
|
+
import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
|
|
17
|
+
import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
18
|
+
import { convertSelectionChange } from '../conversion/upcasthelpers';
|
|
19
|
+
|
|
20
|
+
// @if CK_DEBUG_ENGINE // const { dumpTrees, initDocumentDumping } = require( '../dev-utils/utils' );
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Controller for the editing pipeline. The editing pipeline controls {@link ~EditingController#model model} rendering,
|
|
24
|
+
* including selection handling. It also creates the {@link ~EditingController#view view} which builds a
|
|
25
|
+
* browser-independent virtualization over the DOM elements. The editing controller also attaches default converters.
|
|
26
|
+
*
|
|
27
|
+
* @mixes module:utils/observablemixin~ObservableMixin
|
|
28
|
+
*/
|
|
29
|
+
export default class EditingController {
|
|
30
|
+
/**
|
|
31
|
+
* Creates an editing controller instance.
|
|
32
|
+
*
|
|
33
|
+
* @param {module:engine/model/model~Model} model Editing model.
|
|
34
|
+
* @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor The styles processor instance.
|
|
35
|
+
*/
|
|
36
|
+
constructor( model, stylesProcessor ) {
|
|
37
|
+
/**
|
|
38
|
+
* Editor model.
|
|
39
|
+
*
|
|
40
|
+
* @readonly
|
|
41
|
+
* @member {module:engine/model/model~Model}
|
|
42
|
+
*/
|
|
43
|
+
this.model = model;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Editing view controller.
|
|
47
|
+
*
|
|
48
|
+
* @readonly
|
|
49
|
+
* @member {module:engine/view/view~View}
|
|
50
|
+
*/
|
|
51
|
+
this.view = new View( stylesProcessor );
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Mapper which describes the model-view binding.
|
|
55
|
+
*
|
|
56
|
+
* @readonly
|
|
57
|
+
* @member {module:engine/conversion/mapper~Mapper}
|
|
58
|
+
*/
|
|
59
|
+
this.mapper = new Mapper();
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Downcast dispatcher that converts changes from the model to {@link #view the editing view}.
|
|
63
|
+
*
|
|
64
|
+
* @readonly
|
|
65
|
+
* @member {module:engine/conversion/downcastdispatcher~DowncastDispatcher} #downcastDispatcher
|
|
66
|
+
*/
|
|
67
|
+
this.downcastDispatcher = new DowncastDispatcher( {
|
|
68
|
+
mapper: this.mapper,
|
|
69
|
+
schema: model.schema
|
|
70
|
+
} );
|
|
71
|
+
|
|
72
|
+
const doc = this.model.document;
|
|
73
|
+
const selection = doc.selection;
|
|
74
|
+
const markers = this.model.markers;
|
|
75
|
+
|
|
76
|
+
// When plugins listen on model changes (on selection change, post fixers, etc.) and change the view as a result of
|
|
77
|
+
// model's change, they might trigger view rendering before the conversion is completed (e.g. before the selection
|
|
78
|
+
// is converted). We disable rendering for the length of the outermost model change() block to prevent that.
|
|
79
|
+
//
|
|
80
|
+
// See https://github.com/ckeditor/ckeditor5-engine/issues/1528
|
|
81
|
+
this.listenTo( this.model, '_beforeChanges', () => {
|
|
82
|
+
this.view._disableRendering( true );
|
|
83
|
+
}, { priority: 'highest' } );
|
|
84
|
+
|
|
85
|
+
this.listenTo( this.model, '_afterChanges', () => {
|
|
86
|
+
this.view._disableRendering( false );
|
|
87
|
+
}, { priority: 'lowest' } );
|
|
88
|
+
|
|
89
|
+
// Whenever model document is changed, convert those changes to the view (using model.Document#differ).
|
|
90
|
+
// Do it on 'low' priority, so changes are converted after other listeners did their job.
|
|
91
|
+
// Also convert model selection.
|
|
92
|
+
this.listenTo( doc, 'change', () => {
|
|
93
|
+
this.view.change( writer => {
|
|
94
|
+
this.downcastDispatcher.convertChanges( doc.differ, markers, writer );
|
|
95
|
+
this.downcastDispatcher.convertSelection( selection, markers, writer );
|
|
96
|
+
} );
|
|
97
|
+
}, { priority: 'low' } );
|
|
98
|
+
|
|
99
|
+
// Convert selection from the view to the model when it changes in the view.
|
|
100
|
+
this.listenTo( this.view.document, 'selectionChange', convertSelectionChange( this.model, this.mapper ) );
|
|
101
|
+
|
|
102
|
+
// Attach default model converters.
|
|
103
|
+
this.downcastDispatcher.on( 'insert:$text', insertText(), { priority: 'lowest' } );
|
|
104
|
+
this.downcastDispatcher.on( 'remove', remove(), { priority: 'low' } );
|
|
105
|
+
|
|
106
|
+
// Attach default model selection converters.
|
|
107
|
+
this.downcastDispatcher.on( 'selection', clearAttributes(), { priority: 'high' } );
|
|
108
|
+
this.downcastDispatcher.on( 'selection', convertRangeSelection(), { priority: 'low' } );
|
|
109
|
+
this.downcastDispatcher.on( 'selection', convertCollapsedSelection(), { priority: 'low' } );
|
|
110
|
+
|
|
111
|
+
// Binds {@link module:engine/view/document~Document#roots view roots collection} to
|
|
112
|
+
// {@link module:engine/model/document~Document#roots model roots collection} so creating
|
|
113
|
+
// model root automatically creates corresponding view root.
|
|
114
|
+
this.view.document.roots.bindTo( this.model.document.roots ).using( root => {
|
|
115
|
+
// $graveyard is a special root that has no reflection in the view.
|
|
116
|
+
if ( root.rootName == '$graveyard' ) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const viewRoot = new RootEditableElement( this.view.document, root.name );
|
|
121
|
+
|
|
122
|
+
viewRoot.rootName = root.rootName;
|
|
123
|
+
this.mapper.bindElements( root, viewRoot );
|
|
124
|
+
|
|
125
|
+
return viewRoot;
|
|
126
|
+
} );
|
|
127
|
+
|
|
128
|
+
// @if CK_DEBUG_ENGINE // initDocumentDumping( this.model.document );
|
|
129
|
+
// @if CK_DEBUG_ENGINE // initDocumentDumping( this.view.document );
|
|
130
|
+
|
|
131
|
+
// @if CK_DEBUG_ENGINE // dumpTrees( this.model.document, this.model.document.version );
|
|
132
|
+
// @if CK_DEBUG_ENGINE // dumpTrees( this.view.document, this.model.document.version );
|
|
133
|
+
|
|
134
|
+
// @if CK_DEBUG_ENGINE // this.model.document.on( 'change', () => {
|
|
135
|
+
// @if CK_DEBUG_ENGINE // dumpTrees( this.view.document, this.model.document.version );
|
|
136
|
+
// @if CK_DEBUG_ENGINE // }, { priority: 'lowest' } );
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Removes all event listeners attached to the `EditingController`. Destroys all objects created
|
|
141
|
+
* by `EditingController` that need to be destroyed.
|
|
142
|
+
*/
|
|
143
|
+
destroy() {
|
|
144
|
+
this.view.destroy();
|
|
145
|
+
this.stopListening();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
mix( EditingController, ObservableMixin );
|