Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Align feature class naming to a new scheme. #19

Merged
merged 2 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 5 additions & 62 deletions src/blockquote.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import BlockQuoteEngine from './blockquoteengine';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';

import quoteIcon from '@ckeditor/ckeditor5-core/theme/icons/quote.svg';
import '../theme/blockquote.css';
import BlockQuoteEditing from './blockquoteediting';
import BlockQuoteUI from './blockquoteui';

/**
* The block quote plugin.
*
* It introduces the `'blockQuote'` button and requires the {@link module:block-quote/blockquoteengine~BlockQuoteEngine}
* plugin. It also changes <kbd>Enter</kbd> key behavior so it escapes block quotes when pressed in an
* empty quoted block.
* It loads the {@link module:block-quote/blockquoteediting~BlockQuoteEditing block quote editing feature}
* and {@link module:block-quote/blockquoteui~BlockQuoteUI block quote UI feature}.
*
* @extends module:core/plugin~Plugin
*/
Expand All @@ -28,7 +24,7 @@ export default class BlockQuote extends Plugin {
* @inheritDoc
*/
static get requires() {
return [ BlockQuoteEngine ];
return [ BlockQuoteEditing, BlockQuoteUI ];
}

/**
Expand All @@ -37,57 +33,4 @@ export default class BlockQuote extends Plugin {
static get pluginName() {
return 'BlockQuote';
}

/**
* @inheritDoc
*/
init() {
const editor = this.editor;
const t = editor.t;
const command = editor.commands.get( 'blockQuote' );

editor.ui.componentFactory.add( 'blockQuote', locale => {
const buttonView = new ButtonView( locale );

buttonView.set( {
label: t( 'Block quote' ),
icon: quoteIcon,
tooltip: true
} );

// Bind button model to command.
buttonView.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );

// Execute command.
this.listenTo( buttonView, 'execute', () => editor.execute( 'blockQuote' ) );

return buttonView;
} );
}

/**
* @inheritDoc
*/
afterInit() {
const editor = this.editor;
const command = editor.commands.get( 'blockQuote' );

// Overwrite default Enter key behavior.
// If Enter key is pressed with selection collapsed in empty block inside a quote, break the quote.
// This listener is added in afterInit in order to register it after list's feature listener.
// We can't use a priority for this, because 'low' is already used by the enter feature, unless
// we'd use numeric priority in this case.
this.listenTo( this.editor.editing.view.document, 'enter', ( evt, data ) => {
const doc = this.editor.model.document;
const positionParent = doc.selection.getLastPosition().parent;

if ( doc.selection.isCollapsed && positionParent.isEmpty && command.value ) {
this.editor.execute( 'blockQuote' );
this.editor.editing.view.scrollToTheSelection();

data.preventDefault();
evt.stop();
}
} );
}
}
70 changes: 70 additions & 0 deletions src/blockquoteediting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

/**
* @module block-quote/blockquoteediting
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import BlockQuoteCommand from './blockquotecommand';

/**
* The block quote editing.
*
* Introduces the `'blockQuote'` command and the `'blockQuote'` model element.
*
* @extends module:core/plugin~Plugin
*/
export default class BlockQuoteEditing extends Plugin {
/**
* @inheritDoc
*/
init() {
const editor = this.editor;
const schema = editor.model.schema;

editor.commands.add( 'blockQuote', new BlockQuoteCommand( editor ) );

schema.register( 'blockQuote', {
allowWhere: '$block',
allowContentOf: '$root'
} );

// Disallow blockQuote in blockQuote.
schema.addChildCheck( ( ctx, childDef ) => {
if ( ctx.endsWith( 'blockQuote' ) && childDef.name == 'blockQuote' ) {
return false;
}
} );

editor.conversion.elementToElement( { model: 'blockQuote', view: 'blockquote' } );
}

/**
* @inheritDoc
*/
afterInit() {
const editor = this.editor;
const command = editor.commands.get( 'blockQuote' );

// Overwrite default Enter key behavior.
// If Enter key is pressed with selection collapsed in empty block inside a quote, break the quote.
// This listener is added in afterInit in order to register it after list's feature listener.
// We can't use a priority for this, because 'low' is already used by the enter feature, unless
// we'd use numeric priority in this case.
this.listenTo( this.editor.editing.view.document, 'enter', ( evt, data ) => {
const doc = this.editor.model.document;
const positionParent = doc.selection.getLastPosition().parent;

if ( doc.selection.isCollapsed && positionParent.isEmpty && command.value ) {
this.editor.execute( 'blockQuote' );
this.editor.editing.view.scrollToTheSelection();

data.preventDefault();
evt.stop();
}
} );
}
}
44 changes: 0 additions & 44 deletions src/blockquoteengine.js

This file was deleted.

50 changes: 50 additions & 0 deletions src/blockquoteui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

/**
* @module block-quote/blockquoteui
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';

import quoteIcon from '@ckeditor/ckeditor5-core/theme/icons/quote.svg';
import '../theme/blockquote.css';

/**
* The block quote UI plugin.
*
* It introduces the `'blockQuote'` button.
*
* @extends module:core/plugin~Plugin
*/
export default class BlockQuoteUI extends Plugin {
/**
* @inheritDoc
*/
init() {
const editor = this.editor;
const t = editor.t;

editor.ui.componentFactory.add( 'blockQuote', locale => {
const command = editor.commands.get( 'blockQuote' );
const buttonView = new ButtonView( locale );

buttonView.set( {
label: t( 'Block quote' ),
icon: quoteIcon,
tooltip: true
} );

// Bind button model to command.
buttonView.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );

// Execute command.
this.listenTo( buttonView, 'execute', () => editor.execute( 'blockQuote' ) );

return buttonView;
} );
}
}
74 changes: 4 additions & 70 deletions tests/blockquote.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,12 @@
* For licensing, see LICENSE.md.
*/

/* global document */

import BlockQuote from '../src/blockquote';
import BlockQuoteEngine from '../src/blockquoteengine';

import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import BlockQuoteEditing from '../src/blockquoteediting';
import BlockQuoteUI from '../src/blockquoteui';

describe( 'BlockQuote', () => {
let editor, command, element;

beforeEach( () => {
element = document.createElement( 'div' );
document.body.appendChild( element );

return ClassicTestEditor
.create( element, {
plugins: [ BlockQuote ]
} )
.then( newEditor => {
editor = newEditor;
command = editor.commands.get( 'blockQuote' );
} );
} );

afterEach( () => {
element.remove();

return editor.destroy();
} );

it( 'requires BlockQuoteEngine', () => {
expect( BlockQuote.requires ).to.deep.equal( [ BlockQuoteEngine ] );
} );

describe( 'blockQuote button', () => {
it( 'has the base properties', () => {
const button = editor.ui.componentFactory.create( 'blockQuote' );

expect( button ).to.have.property( 'label', 'Block quote' );
expect( button ).to.have.property( 'icon' );
expect( button ).to.have.property( 'tooltip', true );
} );

it( 'has isOn bound to command\'s value', () => {
const button = editor.ui.componentFactory.create( 'blockQuote' );

command.value = false;
expect( button ).to.have.property( 'isOn', false );

command.value = true;
expect( button ).to.have.property( 'isOn', true );
} );

it( 'has isEnabled bound to command\'s isEnabled', () => {
const button = editor.ui.componentFactory.create( 'blockQuote' );

command.isEnabled = true;
expect( button ).to.have.property( 'isEnabled', true );

command.isEnabled = false;
expect( button ).to.have.property( 'isEnabled', false );
} );

it( 'executes command when it\'s executed', () => {
const button = editor.ui.componentFactory.create( 'blockQuote' );

const spy = sinon.stub( editor, 'execute' );

button.fire( 'execute' );

expect( spy.calledOnce ).to.be.true;
expect( spy.args[ 0 ][ 0 ] ).to.equal( 'blockQuote' );
} );
it( 'requires BlockQuoteEditing and BlockQuoteUI', () => {
expect( BlockQuote.requires ).to.deep.equal( [ BlockQuoteEditing, BlockQuoteUI ] );
} );
} );
4 changes: 2 additions & 2 deletions tests/blockquotecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md.
*/

import BlockQuoteEngine from '../src/blockquoteengine';
import BlockQuoteEditing from '../src/blockquoteediting';
import BlockQuoteCommand from '../src/blockquotecommand';

import { downcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
Expand All @@ -20,7 +20,7 @@ describe( 'BlockQuoteCommand', () => {
beforeEach( () => {
return VirtualTestEditor
.create( {
plugins: [ BlockQuoteEngine ]
plugins: [ BlockQuoteEditing ]
} )
.then( newEditor => {
editor = newEditor;
Expand Down
10 changes: 5 additions & 5 deletions tests/blockquoteengine.js → tests/blockquoteediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
* For licensing, see LICENSE.md.
*/

import BlockQuoteEngine from '../src/blockquoteengine';
import BlockQuoteEditing from '../src/blockquoteediting';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import ListEngine from '@ckeditor/ckeditor5-list/src/listengine';
import ListEditing from '@ckeditor/ckeditor5-list/src/listediting';

import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';

import BlockQuoteCommand from '../src/blockquotecommand';

describe( 'BlockQuoteEngine', () => {
describe( 'BlockQuoteEditing', () => {
let editor, model;

beforeEach( () => {
return VirtualTestEditor
.create( {
plugins: [ BlockQuoteEngine, Paragraph ]
plugins: [ BlockQuoteEditing, Paragraph ]
} )
.then( newEditor => {
editor = newEditor;
Expand Down Expand Up @@ -69,7 +69,7 @@ describe( 'BlockQuoteEngine', () => {
it( 'allows list items inside blockQuote', () => {
return VirtualTestEditor
.create( {
plugins: [ BlockQuoteEngine, Paragraph, ListEngine ]
plugins: [ BlockQuoteEditing, Paragraph, ListEditing ]
} )
.then( editor => {
editor.setData( '<blockquote><ul><li>xx</li></ul></blockquote>' );
Expand Down
Loading