浏览代码

Move Indent* classes from core to intend plugin.

Maciej Gołaszewski 6 年之前
父节点
当前提交
c4a2e2ea7a

+ 51 - 0
packages/ckeditor5-indent/src/indent.js

@@ -0,0 +1,51 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/**
+ * @module core/indent/indent
+ */
+
+import Plugin from '../plugin';
+
+import IndentEditing from './indentediting';
+import IndentUI from './indentui';
+
+/**
+ * The indent feature.
+ *
+ * This plugin acts as a single entry point plugin for other features that implement indenting of elements like lists or paragraphs.
+ *
+ * The compatible features are:
+ 
+ * - the {@link module:list/list~List} or {@link module:list/listediting~ListEditing} feature for list indentation
+ * * the {@link module:list/list~List} or {@link module:list/listediting~ListEditing} feature for list indentation
+ *
+ * This is a "glue" plugin which loads the following plugins:
+ *
+ * * The {@link module:core/indent/indentediting~IndentEditing indent editing feature} and
+ * * The {@link module:core/indent/indentui~IndentUI indent UI feature}.
+ *
+ * The dependent plugins register the `'indent'` and `'outdent'` commands and it introduce the `'indent'` and `'outdent'` buttons
+ * which allow to increase or decrease text indentation of supported elements.
+ *
+ * **Note**: In order the commands and buttons to work at least one of compatible features is required.
+ *
+ * @extends module:core/plugin~Plugin
+ */
+export default class Indent extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	static get pluginName() {
+		return 'Indent';
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	static get requires() {
+		return [ IndentEditing, IndentUI ];
+	}
+}

+ 40 - 0
packages/ckeditor5-indent/src/indentediting.js

@@ -0,0 +1,40 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/**
+ * @module core/indent/indentediting
+ */
+
+import Plugin from '../plugin';
+import MultiCommand from '../multicommand';
+
+/**
+ * The indent editing feature.
+ *
+ * This plugin registers the `'indent'` and `'outdent'` commands.
+ *
+ * **Note**: In order the commands to work at least one of compatible features is required. Read more in
+ * {@link module:core/indent/indent~Indent indent feature} api docs.
+ *
+ * @extends module:core/plugin~Plugin
+ */
+export default class IndentEditing extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	static get pluginName() {
+		return 'IndentEditing';
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		const editor = this.editor;
+
+		editor.commands.add( 'indent', new MultiCommand( editor ) );
+		editor.commands.add( 'outdent', new MultiCommand( editor ) );
+	}
+}

+ 69 - 0
packages/ckeditor5-indent/src/indentui.js

@@ -0,0 +1,69 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/**
+ * @module core/indent/indentui
+ */
+import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
+
+import Plugin from '../plugin';
+
+/**
+ * The indent feature.
+ *
+ * This plugin registers the `'indent'` and `'outdent'` buttons.
+ *
+ * **Note**: In order the commands to work at least one of compatible features is required. Read more in
+ * {@link module:core/indent/indent~Indent indent feature} api docs.
+ *
+ * @extends module:core/plugin~Plugin
+ */
+export default class IndentUI extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	static get pluginName() {
+		return 'IndentUI';
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		const editor = this.editor;
+		const t = editor.t;
+
+		this._defineButton( 'indent', t( 'Increase indent' ) );
+		this._defineButton( 'outdent', t( 'Decrease indent' ) );
+	}
+
+	/**
+	 * Defines an UI button.
+	 *
+	 * @param {String} commandName
+	 * @param {String} label
+	 * @private
+	 */
+	_defineButton( commandName, label ) {
+		const editor = this.editor;
+
+		editor.ui.componentFactory.add( commandName, locale => {
+			const command = editor.commands.get( commandName );
+			const view = new ButtonView( locale );
+
+			view.set( {
+				label,
+				withText: true,
+				tooltip: true
+			} );
+
+			view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
+
+			this.listenTo( view, 'execute', () => editor.execute( commandName ) );
+
+			return view;
+		} );
+	}
+}