Browse Source

Draft of the placeholder feature.

Aleksander Nowodzinski 7 years ago
parent
commit
5bb8e30879

+ 2 - 1
packages/ckeditor5-editor-balloon/src/ballooneditor.js

@@ -77,7 +77,8 @@ export default class BalloonEditor extends Editor {
 
 		this.model.document.createRoot();
 
-		this.ui = new BalloonEditorUI( this, new BalloonEditorUIView( this.locale, this.sourceElement ) );
+		const view = new BalloonEditorUIView( this.locale, this.sourceElement, this.editing.view );
+		this.ui = new BalloonEditorUI( this, view );
 
 		attachToForm( this );
 	}

+ 16 - 5
packages/ckeditor5-editor-balloon/src/ballooneditorui.js

@@ -9,6 +9,7 @@
 
 import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui';
 import enableToolbarKeyboardFocus from '@ckeditor/ckeditor5-ui/src/toolbar/enabletoolbarkeyboardfocus';
+import { attachPlaceholder, getPlaceholderElement } from '@ckeditor/ckeditor5-engine/src/view/placeholder';
 
 /**
  * The balloon editor UI class.
@@ -23,23 +24,33 @@ export default class BalloonEditorUI extends EditorUI {
 		const editor = this.editor;
 		const view = this.view;
 		const balloonToolbar = editor.plugins.get( 'BalloonToolbar' );
+		const editingView = editor.editing.view;
 
 		view.render();
 
+		editingView.attachDomRoot( view.editableElement );
+
 		// Setup the editable.
-		const editingRoot = editor.editing.view.document.getRoot();
+		const editingRoot = editingView.document.getRoot();
+
+		view.editable.name = editingRoot.rootName;
+
+		editor.on( 'dataReady', () => {
+			view.editable.enableDomRootActions();
+
+			attachPlaceholder( editingView, getPlaceholderElement( editingRoot ), 'Type some text...' );
+		} );
+
 		view.editable.bind( 'isReadOnly' ).to( editingRoot );
 
-		// Bind to focusTracker instead of editor.editing.view because otherwise
+		// Bind to focusTracker instead of editingView because otherwise
 		// focused editable styles disappear when view#toolbar is focused.
 		view.editable.bind( 'isFocused' ).to( this.focusTracker );
-		editor.editing.view.attachDomRoot( view.editableElement );
-		view.editable.name = editingRoot.rootName;
 
 		this.focusTracker.add( view.editableElement );
 
 		enableToolbarKeyboardFocus( {
-			origin: editor.editing.view,
+			origin: editingView,
 			originFocusTracker: this.focusTracker,
 			originKeystrokeHandler: editor.keystrokes,
 			toolbar: balloonToolbar.toolbarView,

+ 2 - 2
packages/ckeditor5-editor-balloon/src/ballooneditoruiview.js

@@ -23,7 +23,7 @@ export default class BalloonEditorUIView extends EditorUIView {
 	 * @param {HTMLElement} [editableElement] The editable element. If not specified, it will be automatically created by
 	 * {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
 	 */
-	constructor( locale, editableElement ) {
+	constructor( locale, editableElement, editingView ) {
 		super( locale );
 
 		/**
@@ -32,7 +32,7 @@ export default class BalloonEditorUIView extends EditorUIView {
 		 * @readonly
 		 * @member {module:ui/editableui/inline/inlineeditableuiview~InlineEditableUIView}
 		 */
-		this.editable = new InlineEditableUIView( locale, editableElement );
+		this.editable = new InlineEditableUIView( locale, editingView, editableElement );
 	}
 
 	/**