Browse Source

Introduced 2 presets.

Piotrek Koszuliński 8 years ago
parent
commit
690e6a25a3

+ 1 - 0
packages/ckeditor5-essentials/package.json

@@ -20,6 +20,7 @@
   },
   "devDependencies": {
     "@ckeditor/ckeditor5-dev-lint": "^2.0.2",
+    "@ckeditor/ckeditor5-utils": "*",
     "gulp": "^3.9.0",
     "guppy-pre-commit": "^0.4.0"
   },

+ 4 - 2
packages/ckeditor5-essentials/src/article.js

@@ -9,11 +9,13 @@
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 
-import TextboxPreset from './textbox';
+import EssentialsPreset from './essentials';
 
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
 import Heading from '@ckeditor/ckeditor5-heading/src/heading';
 import Image from '@ckeditor/ckeditor5-image/src/image';
+import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
 import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle';
 import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar';
 import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
@@ -29,6 +31,6 @@ import List from '@ckeditor/ckeditor5-list/src/list';
  */
 export default class Article extends Plugin {
 	static get requires() {
-		return [ TextboxPreset, Bold, Heading, Image, ImageStyle, ImageToolbar, Italic, Link, List ];
+		return [ EssentialsPreset, Paragraph, Bold, Heading, Image, ImageCaption, ImageStyle, ImageToolbar, Italic, Link, List ];
 	}
 }

+ 34 - 0
packages/ckeditor5-essentials/src/essentials.js

@@ -0,0 +1,34 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/**
+ * @module presets/essentials
+ */
+
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+
+import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
+import Enter from '@ckeditor/ckeditor5-enter/src/enter';
+import Typing from '@ckeditor/ckeditor5-typing/src/typing';
+import Undo from '@ckeditor/ckeditor5-undo/src/undo';
+
+/**
+ * Essential editing features preset. Represents a set of features which enable in the editor
+ * similar functionalities to a `<textarea>`.
+ *
+ * It includes: {@link module:clipboard/clipboard~Clipboard}, {@link module:enter/enter~Enter},
+ * {@link module:typing/typing~Typing}, {@link module:undo/undo~Undo}.
+ *
+ * This preset does not define any block-level containers (such as {@link module:paragraph/paragraph~Paragraph}).
+ * If your editor is supposed to handle block content, make sure to include it. You can also inlcude
+ * the {@link module:presets/article~Article article preset}.
+ *
+ * @extends module:core/plugin~Plugin
+ */
+export default class Essentials extends Plugin {
+	static get requires() {
+		return [ Clipboard, Enter, Typing, Undo ];
+	}
+}

+ 0 - 28
packages/ckeditor5-essentials/src/textbox.js

@@ -1,28 +0,0 @@
-/**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module presets/textbox
- */
-
-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-
-import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
-import Enter from '@ckeditor/ckeditor5-enter/src/enter';
-import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
-import Typing from '@ckeditor/ckeditor5-typing/src/typing';
-import Undo from '@ckeditor/ckeditor5-undo/src/undo';
-
-/**
- * Textbox preset. Represents a set of features which enable in the editor
- * similar functionalities to a `<textarea>`.
- *
- * @extends module:core/plugin~Plugin
- */
-export default class Textbox extends Plugin {
-	static get requires() {
-		return [ Clipboard, Enter, Paragraph, Typing, Undo ];
-	}
-}

+ 105 - 0
packages/ckeditor5-essentials/tests/article.js

@@ -0,0 +1,105 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global document */
+
+import ArticlePreset from '../src/article';
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+
+import EssentialsPreset from '../src/essentials';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
+import Heading from '@ckeditor/ckeditor5-heading/src/heading';
+import Image from '@ckeditor/ckeditor5-image/src/image';
+import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
+import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle';
+import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar';
+import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
+import Link from '@ckeditor/ckeditor5-link/src/link';
+import List from '@ckeditor/ckeditor5-list/src/list';
+
+import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
+
+describe( 'Article preset', () => {
+	let editor, editorElement;
+
+	beforeEach( () => {
+		editorElement = document.createElement( 'div' );
+		document.body.appendChild( editorElement );
+
+		return ClassicTestEditor.create( editorElement, {
+				plugins: [ ArticlePreset ]
+			} )
+			.then( newEditor => {
+				editor = newEditor;
+			} );
+	} );
+
+	afterEach( () => {
+		editor.destroy();
+
+		editorElement.remove();
+	} );
+
+	it( 'should be loaded', () => {
+		expect( editor.plugins.get( ArticlePreset ) ).to.be.instanceOf( ArticlePreset );
+	} );
+
+	it( 'should load all its dependencies', () => {
+		expect( editor.plugins.get( EssentialsPreset ) ).to.be.instanceOf( EssentialsPreset );
+
+		expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph );
+		expect( editor.plugins.get( Bold ) ).to.be.instanceOf( Bold );
+		expect( editor.plugins.get( Heading ) ).to.be.instanceOf( Heading );
+		expect( editor.plugins.get( Image ) ).to.be.instanceOf( Image );
+		expect( editor.plugins.get( ImageCaption ) ).to.be.instanceOf( ImageCaption );
+		expect( editor.plugins.get( ImageStyle ) ).to.be.instanceOf( ImageStyle );
+		expect( editor.plugins.get( ImageToolbar ) ).to.be.instanceOf( ImageToolbar );
+		expect( editor.plugins.get( Italic ) ).to.be.instanceOf( Italic );
+		expect( editor.plugins.get( Link ) ).to.be.instanceOf( Link );
+		expect( editor.plugins.get( List ) ).to.be.instanceOf( List );
+	} );
+
+	it( 'loads data', () => {
+		const data =
+			'<h2>Heading 1</h2>' +
+			'<p>Paragraph</p>' +
+			'<p><strong>Bold</strong> <em>Italic</em> <a href="foo">Link</a></p>' +
+			'<ul>' +
+				'<li>UL List item 1</li>' +
+				'<li>UL List item 2</li>' +
+			'</ul>' +
+			'<ol>' +
+				'<li>OL List item 1</li>' +
+				'<li>OL List item 2</li>' +
+			'</ol>' +
+			'<figure class="image image-style-side">' +
+				'<img alt="bar" src="foo">' +
+				'<figcaption>Caption</figcaption>' +
+			'</figure>';
+
+		// Can't use data twice due to https://github.com/ckeditor/ckeditor5-utils/issues/128.
+		const expectedOutput =
+			'<h2>Heading 1</h2>' +
+			'<p>Paragraph</p>' +
+			'<p><strong>Bold</strong> <em>Italic</em> <a href="foo">Link</a></p>' +
+			'<ul>' +
+				'<li>UL List item 1</li>' +
+				'<li>UL List item 2</li>' +
+			'</ul>' +
+			'<ol>' +
+				'<li>OL List item 1</li>' +
+				'<li>OL List item 2</li>' +
+			'</ol>' +
+			'<figure class="image image-style-side">' +
+				'<img alt="bar" src="foo"></img>' +
+				'<figcaption>Caption</figcaption>' +
+			'</figure>';
+
+		editor.setData( data );
+
+		expect( normalizeHtml( editor.getData() ) ).to.equal( expectedOutput );
+	} );
+} );

+ 47 - 0
packages/ckeditor5-essentials/tests/essentials.js

@@ -0,0 +1,47 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global document */
+
+import EssentialsPreset from '../src/essentials';
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+
+import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
+import Enter from '@ckeditor/ckeditor5-enter/src/enter';
+import Typing from '@ckeditor/ckeditor5-typing/src/typing';
+import Undo from '@ckeditor/ckeditor5-undo/src/undo';
+
+describe( 'Essentials preset', () => {
+	let editor, editorElement;
+
+	beforeEach( () => {
+		editorElement = document.createElement( 'div' );
+		document.body.appendChild( editorElement );
+
+		return ClassicTestEditor.create( editorElement, {
+				plugins: [ EssentialsPreset ]
+			} )
+			.then( newEditor => {
+				editor = newEditor;
+			} );
+	} );
+
+	afterEach( () => {
+		editor.destroy();
+
+		editorElement.remove();
+	} );
+
+	it( 'should be loaded', () => {
+		expect( editor.plugins.get( EssentialsPreset ) ).to.be.instanceOf( EssentialsPreset );
+	} );
+
+	it( 'should load all its dependencies', () => {
+		expect( editor.plugins.get( Clipboard ) ).to.be.instanceOf( Clipboard );
+		expect( editor.plugins.get( Enter ) ).to.be.instanceOf( Enter );
+		expect( editor.plugins.get( Typing ) ).to.be.instanceOf( Typing );
+		expect( editor.plugins.get( Undo ) ).to.be.instanceOf( Undo );
+	} );
+} );

+ 17 - 0
packages/ckeditor5-essentials/tests/manual/article.html

@@ -0,0 +1,17 @@
+<div id="editor">
+	<h2>Heading 1</h2>
+	<p>Paragraph</p>
+	<p><strong>Bold</strong> <em>Italic</em> <a href="foo">Link</a></p>
+	<ul>
+		<li>UL List item 1</li>
+		<li>UL List item 2</li>
+	</ul>
+	<ol>
+		<li>OL List item 1</li>
+		<li>OL List item 2</li>
+	</ol>
+	<figure class="image image-style-side">
+		<img alt="bar" src="sample.jpg">
+		<figcaption>Caption</figcaption>
+	</figure>
+</div>

+ 21 - 0
packages/ckeditor5-essentials/tests/manual/article.js

@@ -0,0 +1,21 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals console, window, document */
+
+import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic';
+
+import ArticlePreset from '../../src/article';
+
+ClassicEditor.create( document.querySelector( '#editor' ), {
+	plugins: [ ArticlePreset ],
+	toolbar: [ 'headings', 'bold', 'italic', 'link', 'unlink', 'bulletedList', 'numberedList', 'undo', 'redo' ]
+} )
+.then( editor => {
+	window.editor = editor;
+} )
+.catch( err => {
+	console.error( err.stack );
+} );

+ 3 - 0
packages/ckeditor5-essentials/tests/manual/article.md

@@ -0,0 +1,3 @@
+# Article preset
+
+Check whether all the available features work together.

+ 3 - 0
packages/ckeditor5-essentials/tests/manual/essentials.html

@@ -0,0 +1,3 @@
+<div id="editor">
+	<p>This is editor...</p>
+</div>

+ 23 - 0
packages/ckeditor5-essentials/tests/manual/essentials.js

@@ -0,0 +1,23 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals console, window, document */
+
+import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic';
+
+import EssentialsPreset from '../../src/essentials';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
+// Note: We need to load paragraph because we don't have inline editors yet.
+ClassicEditor.create( document.querySelector( '#editor' ), {
+	plugins: [ EssentialsPreset, Paragraph ],
+	toolbar: [ 'undo', 'redo' ]
+} )
+.then( editor => {
+	window.editor = editor;
+} )
+.catch( err => {
+	console.error( err.stack );
+} );

+ 5 - 0
packages/ckeditor5-essentials/tests/manual/essentials.md

@@ -0,0 +1,5 @@
+# Essentials preset
+
+Check whether typing, undo, clipboard and enter works together.
+
+Note: We also use the paragraph feature here because we don't have an inline editor yet.

BIN
packages/ckeditor5-essentials/tests/manual/sample.jpg