ソースを参照

Converters for the horizontal rule.

Kamil Piechaczek 6 年 前
コミット
8bc413c57a

+ 3 - 0
packages/ckeditor5-horizontal-line/package.json

@@ -10,8 +10,11 @@
     "ckeditor5-plugin"
   ],
   "dependencies": {
+    "@ckeditor/ckeditor5-core": "^12.2.1",
+    "@ckeditor/ckeditor5-widget": "^11.0.4"
   },
   "devDependencies": {
+    "@ckeditor/ckeditor5-editor-classic": "^12.1.3",
     "eslint": "^5.5.0",
     "eslint-config-ckeditor5": "^2.0.0",
     "husky": "^1.3.1",

+ 34 - 0
packages/ckeditor5-horizontal-line/src/horizontalrule.js

@@ -0,0 +1,34 @@
+/**
+ * @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 horizontal-rule/horizontalrule
+ */
+
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+import HorizontalRuleEditing from './horizontalruleediting';
+import HorizontalRuleUI from './horizontalruleui';
+
+/**
+ * The horizontal rule plugin.
+ *
+ *
+ * @extends module:core/plugin~Plugin
+ */
+export default class HorizontalRule extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	static get requires() {
+		return [ HorizontalRuleEditing, HorizontalRuleUI ];
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	static get pluginName() {
+		return 'HorizontalRule';
+	}
+}

+ 59 - 0
packages/ckeditor5-horizontal-line/src/horizontalruleediting.js

@@ -0,0 +1,59 @@
+/**
+ * @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 horizontal-rule/horizontalruleediting
+ */
+
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+import { toWidget } from '@ckeditor/ckeditor5-widget/src/utils';
+
+/**
+ * @extends module:core/plugin~Plugin
+ */
+export default class HorizontalRuleEditing extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		const editor = this.editor;
+		const schema = editor.model.schema;
+		const t = editor.t;
+		const conversion = editor.conversion;
+
+		schema.register( 'horizontalRule', {
+			isBlock: true,
+			isObject: true,
+			allowWhere: '$block'
+		} );
+
+		conversion.for( 'dataDowncast' ).elementToElement( {
+			model: 'horizontalRule',
+			view: ( modelElement, viewWriter ) => {
+				return viewWriter.createEmptyElement( 'hr' );
+			}
+		} );
+
+		conversion.for( 'editingDowncast' ).elementToElement( {
+			model: 'horizontalRule',
+			view: ( modelElement, viewWriter ) => {
+				const label = t( 'Horizontal rule' );
+				const viewElement = viewWriter.createEmptyElement( 'hr' );
+
+				viewWriter.setCustomProperty( 'hr', true, viewElement );
+
+				return toWidget( viewElement, viewWriter, { label } );
+			}
+		} );
+
+		conversion.for( 'upcast' )
+			.elementToElement( {
+				view: 'hr',
+				model: ( viewElement, modelWriter ) => {
+					return modelWriter.createElement( 'horizontalRule' );
+				}
+			} );
+	}
+}

+ 16 - 0
packages/ckeditor5-horizontal-line/src/horizontalruleui.js

@@ -0,0 +1,16 @@
+/**
+ * @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 horizontal-rule/horizontalruleui
+ */
+
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+
+/**
+ * @extends module:core/plugin~Plugin
+ */
+export default class HorizontalRuleUI extends Plugin {
+}