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

Merge branch 'master' into t/ckeditor5/401

Krzysztof Krztoń преди 6 години
родител
ревизия
cc6d0488c5

+ 8 - 4
packages/ckeditor5-core/package.json

@@ -41,7 +41,7 @@
     "@ckeditor/ckeditor5-ui": "^11.2.0",
     "eslint": "^5.5.0",
     "eslint-config-ckeditor5": "^1.0.9",
-    "husky": "^0.14.3",
+    "husky": "^1.3.1",
     "lint-staged": "^7.0.0"
   },
   "engines": {
@@ -62,8 +62,7 @@
     "theme"
   ],
   "scripts": {
-    "lint": "eslint --quiet '**/*.js'",
-    "precommit": "lint-staged"
+    "lint": "eslint --quiet '**/*.js'"
   },
   "lint-staged": {
     "**/*.js": [
@@ -73,5 +72,10 @@
   "eslintIgnore": [
     "src/lib/**",
     "packages/**"
-  ]
+  ],
+  "husky": {
+    "hooks": {
+      "pre-commit": "lint-staged"
+    }
+  }
 }

+ 23 - 13
packages/ckeditor5-core/src/editor/editor.js

@@ -14,8 +14,6 @@ import CommandCollection from '../commandcollection';
 import Locale from '@ckeditor/ckeditor5-utils/src/locale';
 import DataController from '@ckeditor/ckeditor5-engine/src/controller/datacontroller';
 import Conversion from '@ckeditor/ckeditor5-engine/src/conversion/conversion';
-import DowncastHelpers from '@ckeditor/ckeditor5-engine/src/conversion/downcasthelpers';
-import UpcastHelpers from '@ckeditor/ckeditor5-engine/src/conversion/upcasthelpers';
 import Model from '@ckeditor/ckeditor5-engine/src/model/model';
 import EditingKeystrokeHandler from '../editingkeystrokehandler';
 
@@ -179,13 +177,9 @@ export default class Editor {
 		 * @readonly
 		 * @member {module:engine/conversion/conversion~Conversion}
 		 */
-		this.conversion = new Conversion();
-
-		this.conversion.register( 'downcast', new DowncastHelpers( [ this.editing.downcastDispatcher, this.data.downcastDispatcher ] ) );
-		this.conversion.register( 'editingDowncast', new DowncastHelpers( this.editing.downcastDispatcher ) );
-		this.conversion.register( 'dataDowncast', new DowncastHelpers( this.data.downcastDispatcher ) );
-
-		this.conversion.register( 'upcast', new UpcastHelpers( this.data.upcastDispatcher ) );
+		this.conversion = new Conversion( [ this.editing.downcastDispatcher, this.data.downcastDispatcher ], this.data.upcastDispatcher );
+		this.conversion.addAlias( 'dataDowncast', this.data.downcastDispatcher );
+		this.conversion.addAlias( 'editingDowncast', this.editing.downcastDispatcher );
 
 		/**
 		 * Instance of the {@link module:core/editingkeystrokehandler~EditingKeystrokeHandler}.
@@ -219,8 +213,8 @@ export default class Editor {
 	/**
 	 * Loads and initializes plugins specified in the config.
 	 *
-	 * @returns {Promise.<Array.<module:core/plugin~PluginInterface>>} returns.loadedPlugins A promise which resolves
-	 * once the initialization is completed providing array of loaded plugins.
+	 * @returns {Promise.<module:core/plugin~LoadedPlugins>} A promise which resolves
+	 * once the initialization is completed providing an array of loaded plugins.
 	 */
 	initPlugins() {
 		const config = this.config;
@@ -275,13 +269,29 @@ export default class Editor {
 	execute( ...args ) {
 		this.commands.execute( ...args );
 	}
+
+	/**
+	 * Creates and initializes a new editor instance.
+	 *
+	 * This is an abstract method. Every editor type needs to implement its own initialization logic.
+	 *
+	 * See the `create()` methods of the existing editor types to learn how to use them:
+	 *
+	 * * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}
+	 * * {@link module:editor-balloon/ballooneditor~BalloonEditor.create `BalloonEditor.create()`}
+	 * * {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}
+	 * * {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`}
+	 *
+	 * @abstract
+	 * @method module:core/editor/editor~Editor.create
+	 */
 }
 
 mix( Editor, ObservableMixin );
 
 /**
- * Fired when {@link module:core/plugincollection~PluginCollection#event:ready plugins},
- * and {@link module:engine/controller/datacontroller~DataController#event:ready data} and all additional editor components are ready.
+ * Fired when {@link module:engine/controller/datacontroller~DataController#event:ready data} and all additional
+ * editor components are ready.
  *
  * Note: This event is most useful for plugin developers. When integrating the editor with your website or
  * application you do not have to listen to `editor#ready` because when the promise returned by the static

+ 29 - 0
packages/ckeditor5-core/src/editor/editorconfig.jsdoc

@@ -168,3 +168,32 @@
  *
  * @member {String} module:core/editor/editorconfig~EditorConfig#language
  */
+
+/**
+ * Specifies the text displayed in the editor when there is no content (editor is empty). It is intended to
+ * help users locate the editor in the application (form) and prompt them to input the content. Work similarly
+ * as to the native DOM
+ * [`placeholder` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#The_placeholder_attribute)
+ * used by inputs.
+ *
+ *		const config = {
+ *			placeholder: 'Type some text...'
+ *		};
+ *
+ * The placeholder text is displayed as a pseudo–element of an empty paragraph in the editor content.
+ * The paragraph has the `.ck-placeholder` CSS class and the `data-placeholder` attribute.
+ *
+ *		<p data-placeholder="Type some text..." class="ck-placeholder">
+ *			::before
+ *		</p>
+ *
+ * **Note**: Placeholder text can also be set using the `placeholder` attribute if a `<textarea>` is passed to
+ * the `create()` method, e.g. {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}.
+ *
+ * **Note**: This configuration has precedence over the value of the `placeholder` attribute of a `<textarea>`
+ * element passed to the `create()` method.
+ *
+ * See the {@glink features/placeholder "Editor placeholder" guide} for more information and live examples.
+ *
+ * @member {String} module:core/editor/editorconfig~EditorConfig#placeholder
+ */

+ 1 - 2
packages/ckeditor5-core/src/editor/editorui.js

@@ -125,8 +125,7 @@ export default class EditorUI {
 	/**
 	 * Fired when the editor UI is ready.
 	 *
-	 * Fired after {@link module:core/plugincollection~PluginCollection#event:ready} and before
-	 * {@link module:engine/controller/datacontroller~DataController#event:ready}.
+	 * Fired before {@link module:engine/controller/datacontroller~DataController#event:ready}.
 	 *
 	 * @event ready
 	 */

+ 6 - 0
packages/ckeditor5-core/src/plugin.js

@@ -169,3 +169,9 @@ mix( Plugin, ObservableMixin );
  * @method #destroy
  * @returns {null|Promise}
  */
+
+/**
+ * Array of loaded plugins.
+ *
+ * @typedef {Array.<module:core/plugin~PluginInterface>} module:core/plugin~LoadedPlugins
+ */

+ 3 - 4
packages/ckeditor5-core/src/plugincollection.js

@@ -25,7 +25,7 @@ export default class PluginCollection {
 	 *
 	 * @param {module:core/editor/editor~Editor} editor
 	 * @param {Array.<Function>} [availablePlugins] Plugins (constructors) which the collection will be able to use
-	 * when {@link module:core/plugincollection~PluginCollection#load} is used with plugin names (strings, instead of constructors).
+	 * when {@link module:core/plugincollection~PluginCollection#init} is used with plugin names (strings, instead of constructors).
 	 * Usually, the editor will pass its built-in plugins to the collection so they can later be
 	 * used in `config.plugins` or `config.removePlugins` by names.
 	 */
@@ -151,9 +151,8 @@ export default class PluginCollection {
 	 * `availablePlugins` were passed to the {@link #constructor}.
 	 * @param {Array.<String|Function>} [removePlugins] Names of plugins or plugin constructors
 	 * that should not be loaded (despite being specified in the `plugins` array).
-	 * @returns {Promise} A promise which gets resolved once all plugins are loaded and available in the
-	 * collection.
-	 * @returns {Promise.<Array.<module:core/plugin~PluginInterface>>} returns.loadedPlugins The array of loaded plugins.
+	 * @returns {Promise.<module:core/plugin~LoadedPlugins>} A promise which gets resolved once all plugins are loaded
+	 * and available in the collection.
 	 */
 	init( plugins, removePlugins = [] ) {
 		const that = this;

+ 6 - 4
packages/ckeditor5-core/tests/_utils-tests/classictesteditor.js

@@ -57,7 +57,7 @@ describe( 'ClassicTestEditor', () => {
 			expect( editor.ui ).to.be.instanceOf( EditorUI );
 			expect( editor.ui.view ).to.be.instanceOf( BoxedEditorUIView );
 			expect( editor.ui.view.isRendered ).to.be.false;
-			expect( editor.ui.view.editableElement ).to.be.undefined;
+			expect( editor.ui.getEditableElement() ).to.be.undefined;
 		} );
 
 		it( 'creates main root element', () => {
@@ -89,11 +89,13 @@ describe( 'ClassicTestEditor', () => {
 		it( 'renders the view including #editable and sets #editableElement', () => {
 			return ClassicTestEditor.create( editorElement, { foo: 1 } )
 				.then( editor => {
-					const view = editor.ui.view;
+					const ui = editor.ui;
+					const view = ui.view;
 
 					expect( view.isRendered ).to.be.true;
-					expect( view.editableElement.tagName ).to.equal( 'DIV' );
-					expect( view.editableElement ).to.equal( view.editable.element );
+					expect( ui.getEditableElement().tagName ).to.equal( 'DIV' );
+					expect( ui.getEditableElement() ).to.equal( view.editable.element );
+					expect( view.editable.name ).to.equal( 'main' );
 				} );
 		} );
 

+ 7 - 2
packages/ckeditor5-core/tests/_utils/classictesteditor.js

@@ -36,7 +36,7 @@ export default class ClassicTestEditor extends Editor {
 		this.ui = new ClassicTestEditorUI( this, new BoxedEditorUIView( this.locale ) );
 
 		// Expose properties normally exposed by the ClassicEditorUI.
-		this.ui.view.editable = new InlineEditableUIView( this.ui.view.locale );
+		this.ui.view.editable = new InlineEditableUIView( this.ui.view.locale, this.editing.view );
 
 		// Create the ("main") root element of the model tree.
 		this.model.document.createRoot();
@@ -106,10 +106,15 @@ class ClassicTestEditorUI extends EditorUI {
 
 	init( element ) {
 		const view = this.view;
+		const editable = view.editable;
+		const editingView = this.editor.editing.view;
+		const editingRoot = editingView.document.getRoot();
+
+		editable.name = editingRoot.rootName;
 
 		view.render();
+
 		view.main.add( view.editable );
-		view.editableElement = view.editable.element;
 
 		this._editableElements.set( 'main', view.editable.element );