@ckeditor/ckeditor5-block-quote
Advanced tools
Comparing version 0.1.1 to 0.2.0
Changelog | ||
========= | ||
## [0.2.0](https://github.com/ckeditor/ckeditor5-block-quote/compare/v0.1.1...v0.2.0) (2017-09-03) | ||
### Features | ||
* <kbd>Enter</kbd> in the block quote will scroll the viewport to the selection. See ckeditor/ckeditor5-engine#660. ([09dc740](https://github.com/ckeditor/ckeditor5-block-quote/commit/09dc740)) | ||
### Other changes | ||
* Aligned the implementation to the new Command API (see https://github.com/ckeditor/ckeditor5-core/issues/88). ([627510a](https://github.com/ckeditor/ckeditor5-block-quote/commit/627510a)) | ||
### BREAKING CHANGES | ||
* The command API has been changed. | ||
## [0.1.1](https://github.com/ckeditor/ckeditor5-block-quote/compare/v0.1.0...v0.1.1) (2017-05-07) | ||
@@ -5,0 +20,0 @@ |
@@ -6,3 +6,3 @@ /** | ||
/* jshint browser: false, node: true, strict: true */ | ||
/* eslint-env node */ | ||
@@ -12,3 +12,4 @@ 'use strict'; | ||
const gulp = require( 'gulp' ); | ||
const ckeditor5Lint = require( '@ckeditor/ckeditor5-dev-lint' )( { | ||
const ckeditor5Lint = require( '@ckeditor/ckeditor5-dev-lint' ); | ||
const options = { | ||
// Files ignored by `gulp lint` task. | ||
@@ -19,6 +20,6 @@ // Files from .gitignore will be added automatically during task execution. | ||
] | ||
} ); | ||
}; | ||
gulp.task( 'lint', ckeditor5Lint.lint ); | ||
gulp.task( 'lint-staged', ckeditor5Lint.lintStaged ); | ||
gulp.task( 'lint', () => ckeditor5Lint.lint( options ) ); | ||
gulp.task( 'lint-staged', () => ckeditor5Lint.lintStaged( options ) ); | ||
gulp.task( 'pre-commit', [ 'lint-staged' ] ); |
{ | ||
"name": "@ckeditor/ckeditor5-block-quote", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Block quote feature for CKEditor 5.", | ||
@@ -9,17 +9,18 @@ "keywords": [ | ||
"dependencies": { | ||
"@ckeditor/ckeditor5-core": "^0.8.1", | ||
"@ckeditor/ckeditor5-engine": "^0.10.0", | ||
"@ckeditor/ckeditor5-ui": "^0.9.0", | ||
"@ckeditor/ckeditor5-utils": "^0.9.1" | ||
"@ckeditor/ckeditor5-core": "^0.9.0", | ||
"@ckeditor/ckeditor5-engine": "^0.11.0", | ||
"@ckeditor/ckeditor5-ui": "^0.10.0", | ||
"@ckeditor/ckeditor5-utils": "^0.10.0" | ||
}, | ||
"devDependencies": { | ||
"@ckeditor/ckeditor5-dev-lint": "^2.0.2", | ||
"@ckeditor/ckeditor5-editor-classic": "^0.7.3", | ||
"@ckeditor/ckeditor5-enter": "^0.9.1", | ||
"@ckeditor/ckeditor5-image": "^0.6.0", | ||
"@ckeditor/ckeditor5-list": "^0.6.1", | ||
"@ckeditor/ckeditor5-paragraph": "^0.8.0", | ||
"@ckeditor/ckeditor5-presets": "^0.2.2", | ||
"@ckeditor/ckeditor5-typing": "^0.9.1", | ||
"gulp": "^3.9.0", | ||
"@ckeditor/ckeditor5-dev-lint": "^3.1.0", | ||
"@ckeditor/ckeditor5-editor-classic": "^0.8.0", | ||
"@ckeditor/ckeditor5-enter": "^0.10.0", | ||
"@ckeditor/ckeditor5-image": "^0.7.0", | ||
"@ckeditor/ckeditor5-list": "^0.7.0", | ||
"@ckeditor/ckeditor5-paragraph": "^0.9.0", | ||
"@ckeditor/ckeditor5-presets": "^0.3.0", | ||
"@ckeditor/ckeditor5-typing": "^0.10.0", | ||
"eslint-config-ckeditor5": "^1.0.5", | ||
"gulp": "^3.9.1", | ||
"guppy-pre-commit": "^0.4.0" | ||
@@ -26,0 +27,0 @@ }, |
@@ -1,4 +0,5 @@ | ||
CKEditor 5 Block Quote Feature | ||
CKEditor 5 block quote feature | ||
======================================== | ||
[![Join the chat at https://gitter.im/ckeditor/ckeditor5](https://badges.gitter.im/ckeditor/ckeditor5.svg)](https://gitter.im/ckeditor/ckeditor5?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-block-quote.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-block-quote) | ||
@@ -10,3 +11,3 @@ [![Build Status](https://travis-ci.org/ckeditor/ckeditor5-block-quote.svg?branch=master)](https://travis-ci.org/ckeditor/ckeditor5-block-quote) | ||
The block quote feature for CKEditor 5 project. More information about the project can be found at the following url: <https://github.com/ckeditor/ckeditor5>. | ||
The block quote feature for CKEditor 5. More information about the project can be found at the following URL: <https://github.com/ckeditor/ckeditor5>. | ||
@@ -13,0 +14,0 @@ ## License |
@@ -21,3 +21,3 @@ /** | ||
* | ||
* It introduces the `'blockQuote'` button and requires {@link module:block-quote/blockquoteengine~BlockQuoteEngine} | ||
* 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 | ||
@@ -40,3 +40,3 @@ * empty quoted block. | ||
static get pluginName() { | ||
return 'block-quote/blockquote'; | ||
return 'BlockQuote'; | ||
} | ||
@@ -52,3 +52,3 @@ | ||
editor.ui.componentFactory.add( 'blockQuote', ( locale ) => { | ||
editor.ui.componentFactory.add( 'blockQuote', locale => { | ||
const buttonView = new ButtonView( locale ); | ||
@@ -79,4 +79,4 @@ | ||
// Overwrite default enter key behavior. | ||
// If enter key is pressed with selection collapsed in empty block inside a quote, break the quote. | ||
// 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. | ||
@@ -91,2 +91,3 @@ // We can't use a priority for this, because 'low' is already used by the enter feature, unless | ||
this.editor.execute( 'blockQuote' ); | ||
this.editor.editing.view.scrollToTheSelection(); | ||
@@ -93,0 +94,0 @@ data.preventDefault(); |
@@ -10,3 +10,4 @@ /** | ||
import Command from '@ckeditor/ckeditor5-core/src/command/command'; | ||
import Command from '@ckeditor/ckeditor5-core/src/command'; | ||
import Position from '@ckeditor/ckeditor5-engine/src/model/position'; | ||
@@ -18,51 +19,34 @@ import Element from '@ckeditor/ckeditor5-engine/src/model/element'; | ||
/** | ||
* The block quote command. | ||
* The block quote command plugin. | ||
* | ||
* @extends module:core/command/command~Command | ||
* @extends module:core/command~Command | ||
*/ | ||
export default class BlockQuoteCommand extends Command { | ||
/** | ||
* @inheritDoc | ||
* Whether the selection starts in a block quote. | ||
* | ||
* @observable | ||
* @readonly | ||
* @member {Boolean} #value | ||
*/ | ||
constructor( editor ) { | ||
super( editor ); | ||
/** | ||
* Flag indicating whether the command is active. It's on when the selection starts | ||
* in a quoted block. | ||
* | ||
* @readonly | ||
* @observable | ||
* @member {Boolean} #value | ||
*/ | ||
this.set( 'value', false ); | ||
// Update current value each time changes are done to the document. | ||
this.listenTo( editor.document, 'changesDone', () => { | ||
this.refreshValue(); | ||
this.refreshState(); | ||
} ); | ||
} | ||
/** | ||
* Updates command's {@link #value} based on the current selection. | ||
* @inheritDoc | ||
*/ | ||
refreshValue() { | ||
const firstBlock = first( this.editor.document.selection.getSelectedBlocks() ); | ||
// In the current implementation, the block quote must be an immediate parent of a block element. | ||
this.value = !!( firstBlock && findQuote( firstBlock ) ); | ||
refresh() { | ||
this.value = this._getValue(); | ||
this.isEnabled = this._checkEnabled(); | ||
} | ||
/** | ||
* Executes the command. When the command {@link #value is on}, then all block quotes within | ||
* the selection will be removed. If it's off, then all selected blocks will be wrapped with | ||
* Executes the command. When the command {@link #value is on}, all block quotes within | ||
* the selection will be removed. If it is off, all selected blocks will be wrapped with | ||
* a block quote. | ||
* | ||
* @protected | ||
* @fires execute | ||
* @param {Object} [options] Options for executed command. | ||
* @param {module:engine/model/batch~Batch} [options.batch] Batch to collect all the change steps. | ||
* New batch will be created if this option is not set. | ||
* A new batch will be created if this option is not set. | ||
*/ | ||
_doExecute( options = {} ) { | ||
execute( options = {} ) { | ||
const doc = this.editor.document; | ||
@@ -89,4 +73,20 @@ const schema = doc.schema; | ||
/** | ||
* @inheritDoc | ||
* Checks the command's {@link #value}. | ||
* | ||
* @private | ||
* @returns {Boolean} The current value. | ||
*/ | ||
_getValue() { | ||
const firstBlock = first( this.editor.document.selection.getSelectedBlocks() ); | ||
// In the current implementation, the block quote must be an immediate parent of a block element. | ||
return !!( firstBlock && findQuote( firstBlock ) ); | ||
} | ||
/** | ||
* Checks whether the command can be enabled in the current context. | ||
* | ||
* @private | ||
* @returns {Boolean} Whether the command should be enabled. | ||
*/ | ||
_checkEnabled() { | ||
@@ -110,3 +110,3 @@ if ( this.value ) { | ||
/** | ||
* Removes the quote from the given blocks. | ||
* Removes the quote from given blocks. | ||
* | ||
@@ -117,2 +117,3 @@ * If blocks which are supposed to be "unquoted" are in the middle of a quote, | ||
* | ||
* @private | ||
* @param {module:engine/model/batch~Batch} batch | ||
@@ -123,3 +124,3 @@ * @param {Array.<module:engine/model/element~Element>} blocks | ||
// Unquote all groups of block. Iterate in the reverse order to not break following ranges. | ||
getRangesOfBlockGroups( blocks ).reverse().forEach( ( groupRange ) => { | ||
getRangesOfBlockGroups( blocks ).reverse().forEach( groupRange => { | ||
if ( groupRange.start.isAtStart && groupRange.end.isAtEnd ) { | ||
@@ -155,4 +156,5 @@ batch.unwrap( groupRange.start.parent ); | ||
/** | ||
* Applies the quote to the given blocks. | ||
* Applies the quote to given blocks. | ||
* | ||
* @private | ||
* @param {module:engine/model/batch~Batch} batch | ||
@@ -165,3 +167,3 @@ * @param {Array.<module:engine/model/element~Element>} blocks | ||
// Quote all groups of block. Iterate in the reverse order to not break following ranges. | ||
getRangesOfBlockGroups( blocks ).reverse().forEach( ( groupRange ) => { | ||
getRangesOfBlockGroups( blocks ).reverse().forEach( groupRange => { | ||
let quote = findQuote( groupRange.start ); | ||
@@ -168,0 +170,0 @@ |
@@ -20,3 +20,3 @@ /** | ||
* | ||
* Introduces the `'blockQuote'` command and `'blockQuote'` model element. | ||
* Introduces the `'blockQuote'` command and the `'blockQuote'` model element. | ||
* | ||
@@ -33,3 +33,3 @@ * @extends module:core/plugin~Plugin | ||
editor.commands.set( 'blockQuote', new BlockQuoteCommand( editor ) ); | ||
editor.commands.add( 'blockQuote', new BlockQuoteCommand( editor ) ); | ||
@@ -36,0 +36,0 @@ schema.registerItem( 'blockQuote' ); |
@@ -14,3 +14,3 @@ /** | ||
describe( 'BlockQuote', () => { | ||
let editor, doc, command, element; | ||
let editor, command, element; | ||
@@ -21,10 +21,10 @@ beforeEach( () => { | ||
return ClassicTestEditor.create( element, { | ||
plugins: [ BlockQuote ] | ||
} ) | ||
.then( newEditor => { | ||
editor = newEditor; | ||
doc = editor.document; | ||
command = editor.commands.get( 'blockQuote' ); | ||
} ); | ||
return ClassicTestEditor | ||
.create( element, { | ||
plugins: [ BlockQuote ] | ||
} ) | ||
.then( newEditor => { | ||
editor = newEditor; | ||
command = editor.commands.get( 'blockQuote' ); | ||
} ); | ||
} ); | ||
@@ -31,0 +31,0 @@ |
@@ -15,3 +15,3 @@ /** | ||
import Command from '@ckeditor/ckeditor5-core/src/command/command'; | ||
import Command from '@ckeditor/ckeditor5-core/src/command'; | ||
@@ -22,33 +22,34 @@ describe( 'BlockQuoteCommand', () => { | ||
beforeEach( () => { | ||
return VirtualTestEditor.create( { | ||
plugins: [ BlockQuoteEngine ] | ||
} ) | ||
.then( newEditor => { | ||
editor = newEditor; | ||
return VirtualTestEditor | ||
.create( { | ||
plugins: [ BlockQuoteEngine ] | ||
} ) | ||
.then( newEditor => { | ||
editor = newEditor; | ||
doc = editor.document; | ||
doc = editor.document; | ||
doc.schema.registerItem( 'paragraph', '$block' ); | ||
doc.schema.registerItem( 'heading', '$block' ); | ||
doc.schema.registerItem( 'widget' ); | ||
doc.schema.registerItem( 'paragraph', '$block' ); | ||
doc.schema.registerItem( 'heading', '$block' ); | ||
doc.schema.registerItem( 'widget' ); | ||
doc.schema.allow( { name: 'widget', inside: '$root' } ); | ||
doc.schema.allow( { name: '$text', inside: 'widget' } ); | ||
doc.schema.allow( { name: 'widget', inside: '$root' } ); | ||
doc.schema.allow( { name: '$text', inside: 'widget' } ); | ||
doc.schema.limits.add( 'widget' ); | ||
doc.schema.limits.add( 'widget' ); | ||
buildModelConverter().for( editor.editing.modelToView ) | ||
.fromElement( 'paragraph' ) | ||
.toElement( 'p' ); | ||
buildModelConverter().for( editor.editing.modelToView ) | ||
.fromElement( 'paragraph' ) | ||
.toElement( 'p' ); | ||
buildModelConverter().for( editor.editing.modelToView ) | ||
.fromElement( 'heading' ) | ||
.toElement( 'h' ); | ||
buildModelConverter().for( editor.editing.modelToView ) | ||
.fromElement( 'heading' ) | ||
.toElement( 'h' ); | ||
buildModelConverter().for( editor.editing.modelToView ) | ||
.fromElement( 'widget' ) | ||
.toElement( 'widget' ); | ||
buildModelConverter().for( editor.editing.modelToView ) | ||
.fromElement( 'widget' ) | ||
.toElement( 'widget' ); | ||
command = editor.commands.get( 'blockQuote' ); | ||
} ); | ||
command = editor.commands.get( 'blockQuote' ); | ||
} ); | ||
} ); | ||
@@ -144,3 +145,3 @@ | ||
describe( '_doExecute()', () => { | ||
describe( 'execute()', () => { | ||
describe( 'applying quote', () => { | ||
@@ -147,0 +148,0 @@ it( 'should wrap a single block', () => { |
@@ -19,10 +19,11 @@ /** | ||
beforeEach( () => { | ||
return VirtualTestEditor.create( { | ||
plugins: [ BlockQuoteEngine, Paragraph ] | ||
} ) | ||
.then( newEditor => { | ||
editor = newEditor; | ||
return VirtualTestEditor | ||
.create( { | ||
plugins: [ BlockQuoteEngine, Paragraph ] | ||
} ) | ||
.then( newEditor => { | ||
editor = newEditor; | ||
doc = editor.document; | ||
} ); | ||
doc = editor.document; | ||
} ); | ||
} ); | ||
@@ -63,11 +64,12 @@ | ||
it( 'allows list items inside blockQuote', () => { | ||
return VirtualTestEditor.create( { | ||
plugins: [ BlockQuoteEngine, Paragraph, ListEngine ] | ||
} ) | ||
.then( editor => { | ||
editor.setData( '<blockquote><ul><li>xx</li></ul></blockquote>' ); | ||
return VirtualTestEditor | ||
.create( { | ||
plugins: [ BlockQuoteEngine, Paragraph, ListEngine ] | ||
} ) | ||
.then( editor => { | ||
editor.setData( '<blockquote><ul><li>xx</li></ul></blockquote>' ); | ||
expect( editor.getData() ).to.equal( '<blockquote><ul><li>xx</li></ul></blockquote>' ); | ||
} ); | ||
expect( editor.getData() ).to.equal( '<blockquote><ul><li>xx</li></ul></blockquote>' ); | ||
} ); | ||
} ); | ||
} ); |
@@ -26,9 +26,10 @@ /** | ||
return ClassicTestEditor.create( element, { | ||
plugins: [ BlockQuote, Paragraph, Image, ImageCaption, List, Enter, Delete ] | ||
} ) | ||
.then( newEditor => { | ||
editor = newEditor; | ||
doc = editor.document; | ||
} ); | ||
return ClassicTestEditor | ||
.create( element, { | ||
plugins: [ BlockQuote, Paragraph, Image, ImageCaption, List, Enter, Delete ] | ||
} ) | ||
.then( newEditor => { | ||
editor = newEditor; | ||
doc = editor.document; | ||
} ); | ||
} ); | ||
@@ -194,2 +195,19 @@ | ||
} ); | ||
it( 'scrolls the view document to the selection after the command is executed', () => { | ||
const data = fakeEventData(); | ||
const execSpy = sinon.spy( editor, 'execute' ); | ||
const scrollSpy = sinon.stub( editor.editing.view, 'scrollToTheSelection' ); | ||
setModelData( doc, | ||
'<paragraph>x</paragraph>' + | ||
'<blockQuote><paragraph>a</paragraph><paragraph>[]</paragraph></blockQuote>' + | ||
'<paragraph>x</paragraph>' | ||
); | ||
editor.editing.view.fire( 'enter', data ); | ||
sinon.assert.calledOnce( scrollSpy ); | ||
sinon.assert.callOrder( execSpy, scrollSpy ); | ||
} ); | ||
} ); | ||
@@ -303,6 +321,7 @@ | ||
// We can't load ImageCaption in this test because it adds <caption> to all images automatically. | ||
return ClassicTestEditor.create( element, { | ||
return ClassicTestEditor | ||
.create( element, { | ||
plugins: [ BlockQuote, Paragraph, Image ] | ||
} ) | ||
.then( ( editor ) => { | ||
.then( editor => { | ||
setModelData( editor.document, | ||
@@ -309,0 +328,0 @@ '<paragraph>fo[o</paragraph>' + |
@@ -8,3 +8,3 @@ /** | ||
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic'; | ||
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; | ||
import ArticlePreset from '@ckeditor/ckeditor5-presets/src/article'; | ||
@@ -14,14 +14,15 @@ | ||
ClassicEditor.create( document.querySelector( '#editor' ), { | ||
plugins: [ | ||
ArticlePreset | ||
], | ||
toolbar: [ 'headings', 'bold', 'italic', 'link', 'unlink', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ] | ||
} ) | ||
.then( editor => { | ||
window.editor = editor; | ||
} ) | ||
.catch( err => { | ||
console.error( err.stack ); | ||
} ); | ||
ClassicEditor | ||
.create( document.querySelector( '#editor' ), { | ||
plugins: [ | ||
ArticlePreset | ||
], | ||
toolbar: [ 'headings', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ] | ||
} ) | ||
.then( editor => { | ||
window.editor = editor; | ||
} ) | ||
.catch( err => { | ||
console.error( err.stack ); | ||
} ); | ||
@@ -28,0 +29,0 @@ window.setInterval( function() { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87263
47
1283
16
11
+ Added@ckeditor/ckeditor5-core@0.9.0(transitive)
+ Added@ckeditor/ckeditor5-engine@0.11.0(transitive)
+ Added@ckeditor/ckeditor5-theme-lark@0.9.0(transitive)
+ Added@ckeditor/ckeditor5-ui@0.10.0(transitive)
+ Added@ckeditor/ckeditor5-utils@0.10.0(transitive)
- Removed@ckeditor/ckeditor5-core@0.8.1(transitive)
- Removed@ckeditor/ckeditor5-engine@0.10.0(transitive)
- Removed@ckeditor/ckeditor5-theme-lark@0.8.0(transitive)
- Removed@ckeditor/ckeditor5-ui@0.9.0(transitive)
- Removed@ckeditor/ckeditor5-utils@0.9.1(transitive)