Преглед на файлове

Applied changes to the body collection API.

Piotr Jasiun преди 6 години
родител
ревизия
a4b55ac081
променени са 2 файла, в които са добавени 22 реда и са изтрити 5 реда
  1. 20 3
      packages/ckeditor5-ui/src/editorui/bodycollection.js
  2. 2 2
      packages/ckeditor5-ui/src/editorui/editoruiview.js

+ 20 - 3
packages/ckeditor5-ui/src/editorui/bodycollection.js

@@ -12,8 +12,10 @@
 import Template from '../template';
 import ViewCollection from '../viewcollection';
 
+import createElement from '@ckeditor/ckeditor5-utils/src/dom/createElement';
+
 export default class BodyCollection extends ViewCollection {
-	render() {
+	attachToDOM() {
 		this._bodyCollectionContainer = new Template( {
 			tag: 'div',
 			attributes: {
@@ -28,14 +30,29 @@ export default class BodyCollection extends ViewCollection {
 			children: this
 		} ).render();
 
-		document.body.appendChild( this._bodyCollectionContainer );
+		let wrapper = document.querySelector( '.ck-body-wrapper' );
+
+		if ( !wrapper ) {
+			wrapper = createElement( document, 'div', { class: 'ck-body-wrapper' } );
+			document.body.appendChild( wrapper );
+		}
+
+		console.log( wrapper );
+
+		wrapper.appendChild( this._bodyCollectionContainer );
 	}
 
-	destroy() {
+	detachFromDOM() {
 		super.destroy();
 
 		if ( this._bodyCollectionContainer ) {
 			this._bodyCollectionContainer.remove();
 		}
+
+		const wrapper = document.querySelector( '.ck-body-wrapper' );
+
+		if ( wrapper.childElementCount == 0 ) {
+			wrapper.remove();
+		}
 	}
 }

+ 2 - 2
packages/ckeditor5-ui/src/editorui/editoruiview.js

@@ -49,14 +49,14 @@ export default class EditorUIView extends View {
 	render() {
 		super.render();
 
-		this.body.render();
+		this.body.attachToDOM();
 	}
 
 	/**
 	 * @inheritDoc
 	 */
 	destroy() {
-		this.body.destroy();
+		this.body.detachFromDOM();
 
 		return super.destroy();
 	}