Răsfoiți Sursa

Code refactoring and new documentation in the BalloonEditorUI class.

Aleksander Nowodzinski 7 ani în urmă
părinte
comite
4f53b12848
1 a modificat fișierele cu 32 adăugiri și 14 ștergeri
  1. 32 14
      packages/ckeditor5-editor-balloon/src/ballooneditorui.js

+ 32 - 14
packages/ckeditor5-editor-balloon/src/ballooneditorui.js

@@ -60,32 +60,50 @@ export default class BalloonEditorUI extends EditorUI {
 		const view = this.view;
 		const balloonToolbar = editor.plugins.get( 'BalloonToolbar' );
 		const editingView = editor.editing.view;
+		const editable = view.editable;
+		const editingRoot = editingView.document.getRoot();
 
 		view.render();
 
-		editingView.attachDomRoot( view.editable.editableElement );
+		// The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
+		// But it can be available earlier if a DOM element has been passed to BalloonEditor.create().
+		const editableElement = editable.editableElement;
 
-		// Setup the editable.
-		const editingRoot = editingView.document.getRoot();
+		// Register the editable UI view in the editor. A single editor instance can aggregate multiple
+		// editable areas (roots) but the balloon editor has only one.
+		this._editableElements.push( view.editable );
 
+		// Let the global focus tracker know that the editable UI element is focusable and
+		// belongs to the editor. From now on, the focus tracker will sustain the editor focus
+		// as long as the editable is focused (e.g. the user is typing).
+		this.focusTracker.add( editableElement );
+
+		// Let the editable UI element respond to the changes in the global editor focus
+		// tracker. It has been added to the same tracker a few lines above but, in reality, there are
+		// many focusable areas in the editor, like balloons, toolbars or dropdowns and as long
+		// as they have focus, the editable should act like it is focused too (although technically
+		// it isn't), e.g. by setting the proper CSS class, visually announcing focus to the user.
+		// Doing otherwise will result in editable focus styles disappearing, once e.g. the
+		// toolbar gets focused.
+		view.editable.bind( 'isFocused' ).to( this.focusTracker );
+
+		// The editable UI and editing root should share the same name. Then name is used
+		// to recognize the particular editable, for instance in ARIA attributes.
 		view.editable.name = editingRoot.rootName;
 
+		// Bind the editable UI element to the editing view, making it an end– and entry–point
+		// of the editor's engine. This is where the engine meets the UI.
+		editingView.attachDomRoot( editableElement );
+
+		// The UI must wait until the data is ready to attach certain actions that operate
+		// on the editing view–level. They use the view writer to set attributes on the editable
+		// element and doing so before data is loaded into the model (ready) would destroy the
+		// original content.
 		editor.on( 'dataReady', () => {
 			view.editable.enableDomRootActions();
-
 			attachPlaceholder( editingView, getPlaceholderElement( editingRoot ), 'Type some text...' );
 		} );
 
-		view.editable.bind( 'isReadOnly' ).to( editingRoot );
-
-		// Bind to focusTracker instead of editingView because otherwise
-		// focused editable styles disappear when view#toolbar is focused.
-		view.editable.bind( 'isFocused' ).to( this.focusTracker );
-
-		this._editableElements.push( view.editable );
-
-		this.focusTracker.add( view.editable.editableElement );
-
 		enableToolbarKeyboardFocus( {
 			origin: editingView,
 			originFocusTracker: this.focusTracker,