浏览代码

Draft of the placeholder feature.

Aleksander Nowodzinski 6 年之前
父节点
当前提交
f57109a7bf

+ 2 - 1
packages/ckeditor5-editor-decoupled/src/decouplededitor.js

@@ -73,7 +73,8 @@ export default class DecoupledEditor extends Editor {
 
 		this.model.document.createRoot();
 
-		this.ui = new DecoupledEditorUI( this, new DecoupledEditorUIView( this.locale, this.sourceElement ) );
+		const view = new DecoupledEditorUIView( this.locale, this.sourceElement, this.editing.view );
+		this.ui = new DecoupledEditorUI( this, view );
 	}
 
 	/**

+ 14 - 4
packages/ckeditor5-editor-decoupled/src/decouplededitorui.js

@@ -10,6 +10,7 @@
 import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui';
 import enableToolbarKeyboardFocus from '@ckeditor/ckeditor5-ui/src/toolbar/enabletoolbarkeyboardfocus';
 import normalizeToolbarConfig from '@ckeditor/ckeditor5-ui/src/toolbar/normalizetoolbarconfig';
+import { attachPlaceholder, getPlaceholderElement } from '@ckeditor/ckeditor5-engine/src/view/placeholder';
 
 /**
  * The decoupled editor UI class.
@@ -38,16 +39,25 @@ export default class DecoupledEditorUI extends EditorUI {
 	init() {
 		const editor = this.editor;
 		const view = this.view;
+		const editingView = editor.editing.view;
 
 		view.render();
 
-		// Set up the editable.
-		const editingRoot = editor.editing.view.document.getRoot();
-		view.editable.bind( 'isReadOnly' ).to( editingRoot );
-		view.editable.bind( 'isFocused' ).to( editor.editing.view.document );
 		editor.editing.view.attachDomRoot( view.editableElement );
+
+		const editingRoot = editor.editing.view.document.getRoot();
+
 		view.editable.name = editingRoot.rootName;
 
+		editor.on( 'dataReady', () => {
+			view.editable.enableDomRootActions();
+
+			attachPlaceholder( editingView, getPlaceholderElement( editingRoot ), 'Type some text...' );
+		} );
+
+		// Set up the editable.
+		view.editable.bind( 'isFocused' ).to( editor.editing.view.document );
+
 		this.focusTracker.add( this.view.editableElement );
 		this.view.toolbar.fillFromConfig( this._toolbarConfig.items, this.componentFactory );
 

+ 2 - 2
packages/ckeditor5-editor-decoupled/src/decouplededitoruiview.js

@@ -31,7 +31,7 @@ export default class DecoupledEditorUIView 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 );
 
 		/**
@@ -48,7 +48,7 @@ export default class DecoupledEditorUIView extends EditorUIView {
 		 * @readonly
 		 * @member {module:ui/editableui/inline/inlineeditableuiview~InlineEditableUIView}
 		 */
-		this.editable = new InlineEditableUIView( locale, editableElement );
+		this.editable = new InlineEditableUIView( locale, editingView, editableElement );
 
 		// This toolbar may be placed anywhere in the page so things like font size need to be reset in it.
 		// Also because of the above, make sure the toolbar supports rounded corners.