Socket
Socket
Sign inDemoInstall

@ckeditor/ckeditor5-heading

Package Overview
Dependencies
Maintainers
1
Versions
620
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckeditor/ckeditor5-heading - npm Package Compare versions

Comparing version 0.9.1 to 0.10.0

.eslintrc.js

22

CHANGELOG.md
Changelog
=========
## [0.10.0](https://github.com/ckeditor/ckeditor5-heading/compare/v0.9.1...v0.10.0) (2017-09-03)
### Bug fixes
* It should not be possible to apply a heading to an image. Closes [#73](https://github.com/ckeditor/ckeditor5-heading/issues/73). ([02f66a0](https://github.com/ckeditor/ckeditor5-heading/commit/02f66a0))
### Other changes
* Aligned the implementation to the new Command API (see https://github.com/ckeditor/ckeditor5-core/issues/88). ([63b6c1c](https://github.com/ckeditor/ckeditor5-heading/commit/63b6c1c))
* Heading dropdown items should never revert the state, apply only. Closes [#83](https://github.com/ckeditor/ckeditor5-heading/issues/83). ([3f25a21](https://github.com/ckeditor/ckeditor5-heading/commit/3f25a21))
* Removed `HeadingCommand`'s properties which were exposed unnecessarily. Closes [#78](https://github.com/ckeditor/ckeditor5-heading/issues/78). ([c80e691](https://github.com/ckeditor/ckeditor5-heading/commit/c80e691))
### BREAKING CHANGES
* The command API has been changed.
* The `HeadingCommand` constructor's second parameter was changed from the `options` object to the `modelElement` alone.
### NOTE
* The `HeadingOption` interface was moved to the `heading/heading` module.
## [0.9.1](https://github.com/ckeditor/ckeditor5-heading/compare/v0.9.0...v0.9.1) (2017-05-07)

@@ -5,0 +27,0 @@

11

gulpfile.js

@@ -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-heading",
"version": "0.9.1",
"version": "0.10.0",
"description": "Headings feature for CKEditor 5.",
"keywords": [],
"dependencies": {
"@ckeditor/ckeditor5-core": "^0.8.1",
"@ckeditor/ckeditor5-ui": "^0.9.0",
"@ckeditor/ckeditor5-utils": "^0.9.1",
"@ckeditor/ckeditor5-engine": "^0.10.0",
"@ckeditor/ckeditor5-paragraph": "^0.8.0",
"@ckeditor/ckeditor5-theme-lark": "^0.8.0"
"@ckeditor/ckeditor5-core": "^0.9.0",
"@ckeditor/ckeditor5-ui": "^0.10.0",
"@ckeditor/ckeditor5-utils": "^0.10.0",
"@ckeditor/ckeditor5-engine": "^0.11.0",
"@ckeditor/ckeditor5-paragraph": "^0.9.0",
"@ckeditor/ckeditor5-theme-lark": "^0.9.0"
},
"devDependencies": {
"@ckeditor/ckeditor5-dev-lint": "^2.0.2",
"@ckeditor/ckeditor5-enter": "^0.9.1",
"@ckeditor/ckeditor5-editor-classic": "^0.7.3",
"@ckeditor/ckeditor5-typing": "^0.9.1",
"@ckeditor/ckeditor5-undo": "^0.8.1",
"gulp": "^3.9.0",
"@ckeditor/ckeditor5-dev-lint": "^3.1.0",
"@ckeditor/ckeditor5-enter": "^0.10.0",
"@ckeditor/ckeditor5-editor-classic": "^0.8.0",
"@ckeditor/ckeditor5-image": "^0.7.0",
"@ckeditor/ckeditor5-typing": "^0.10.0",
"@ckeditor/ckeditor5-undo": "^0.9.0",
"eslint-config-ckeditor5": "^1.0.5",
"gulp": "^3.9.1",
"guppy-pre-commit": "^0.4.0"

@@ -22,0 +24,0 @@ },

@@ -1,4 +0,5 @@

CKEditor 5 Headings Feature
CKEditor 5 headings 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-heading.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-heading)

@@ -5,0 +6,0 @@ [![Build Status](https://travis-ci.org/ckeditor/ckeditor5-heading.svg?branch=master)](https://travis-ci.org/ckeditor/ckeditor5-heading)

@@ -22,3 +22,4 @@ /**

* The headings feature. It introduces the `headings` drop-down list and the `heading` command which allow
* to convert paragraphs into headings.
* to convert paragraphs into headings. For a detailed overview, check the
* {@glink features/headings Headings feature documentation}.
*

@@ -39,3 +40,3 @@ * @extends module:core/plugin~Plugin

static get pluginName() {
return 'heading/heading';
return 'Heading';
}

@@ -55,3 +56,3 @@

for ( let option of options ) {
for ( const option of options ) {
const command = editor.commands.get( option.modelElement );

@@ -99,3 +100,3 @@ const itemModel = new Model( {

// Register UI component.
editor.ui.componentFactory.add( 'headings', ( locale ) => {
editor.ui.componentFactory.add( 'headings', locale => {
const dropdown = createListDropdown( dropdownModel, locale );

@@ -112,3 +113,3 @@

// Execute command when an item from the dropdown is selected.
this.listenTo( dropdown, 'execute', ( evt ) => {
this.listenTo( dropdown, 'execute', evt => {
editor.execute( evt.source.commandName );

@@ -124,3 +125,3 @@ editor.editing.view.focus();

* Returns heading options as defined in `config.heading.options` but processed to consider
* editor localization, i.e. to display {@link module:heading/headingcommand~HeadingOption}
* editor localization, i.e. to display {@link module:heading/heading~HeadingOption}
* in the correct language.

@@ -132,3 +133,3 @@ *

* @private
* @returns {Array.<module:heading/headingcommand~HeadingOption>}.
* @returns {Array.<module:heading/heading~HeadingOption>}.
*/

@@ -163,3 +164,3 @@ _getLocalizedOptions() {

// @private
// @param {Iterable.<module:core/command/command~Command>} commands
// @param {Iterable.<module:core/command~Command>} commands
// @param {String} attribute

@@ -170,1 +171,72 @@ // @returns {Array.<String>}

}
/**
* Heading option descriptor.
*
* @typedef {Object} module:heading/heading~HeadingOption
* @property {String} modelElement Element's name in the model.
* @property {String} viewElement The name of the view element that will be used to represent the model element in the view.
* @property {String} title The user-readable title of the option.
* @property {String} class The class which will be added to the dropdown item representing this option.
*/
/**
* The configuration of the heading feature. Introduced by the {@link module:heading/headingengine~HeadingEngine} feature.
*
* Read more in {@link module:heading/heading~HeadingConfig}.
*
* @member {module:heading/heading~HeadingConfig} module:core/editor/editorconfig~EditorConfig#heading
*/
/**
* The configuration of the heading feature.
* The option is used by the {@link module:heading/headingengine~HeadingEngine} feature.
*
* ClassicEditor
* .create( {
* heading: ... // Heading feature config.
* } )
* .then( ... )
* .catch( ... );
*
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
*
* @interface HeadingConfig
*/
/**
* The available heading options.
*
* The default value is:
*
* const headingConfig = {
* options: [
* { modelElement: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
* { modelElement: 'heading1', viewElement: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
* { modelElement: 'heading2', viewElement: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
* { modelElement: 'heading3', viewElement: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
* ]
* };
*
* It defines 3 levels of headings. In the editor model they will use `heading1`, `heading2`, and `heading3` elements.
* Their respective view elements (so the elements output by the editor) will be: `h2`, `h3`, and `h4`. This means that
* if you choose "Heading 1" in the headings dropdown the editor will turn the current block to `<heading1>` in the model
* which will result in rendering (and outputting to data) the `<h2>` element.
*
* The `title` and `class` properties will be used by the `headings` dropdown to render available options.
* Usually, the first option in the headings dropdown is the "Paragraph" option, hence it's also defined on the list.
* However, you don't need to define its view representation because it's handled by
* the {@link module:paragraph/paragraph~Paragraph} feature (which is required by
* the {@link module:heading/headingengine~HeadingEngine} feature).
*
* Note: In the model you should always start from `heading1`, regardless of how the headings are represented in the view.
* That's assumption is used by features like {@link module:autoformat/autoformat~Autoformat} to know which element
* they should use when applying the first level heading.
*
* The defined headings are also available in {@link module:core/commandcollection~CommandCollection} under their model names.
* For example, the below code will apply `<heading1>` to the current selection:
*
* editor.execute( 'heading1' );
*
* @member {Array.<module:heading/heading~HeadingOption>} module:heading/heading~HeadingConfig#options
*/

@@ -10,5 +10,3 @@ /**

import Range from '@ckeditor/ckeditor5-engine/src/model/range';
import Command from '@ckeditor/ckeditor5-core/src/command/command';
import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
import Command from '@ckeditor/ckeditor5-core/src/command';
import Position from '@ckeditor/ckeditor5-engine/src/model/position';

@@ -20,3 +18,3 @@ import first from '@ckeditor/ckeditor5-utils/src/first';

*
* @extends module:core/command/command~Command
* @extends module:core/command~Command
*/

@@ -28,54 +26,40 @@ export default class HeadingCommand extends Command {

* @param {module:core/editor/editor~Editor} editor Editor instance.
* @param {module:heading/headingcommand~HeadingOption} option An option to be used by the command instance.
* @param {String} modelElement Name of the element which this command will apply in the model.
*/
constructor( editor, option ) {
constructor( editor, modelElement ) {
super( editor );
Object.assign( this, option );
/**
* Value of the command, indicating whether it is applied in the context
* of current {@link module:engine/model/document~Document#selection selection}.
* Whether the selection starts in a heading of {@link #modelElement this level}.
*
* @observable
* @readonly
* @observable
* @member {Boolean}
* @member {Boolean} #value
*/
this.set( 'value', false );
// Update current value each time changes are done on document.
this.listenTo( editor.document, 'changesDone', () => {
this.refreshValue();
this.refreshState();
} );
/**
* Unique identifier of the command, also element's name in the model.
* See {@link module:heading/headingcommand~HeadingOption}.
* See {@link module:heading/heading~HeadingOption}.
*
* @readonly
* @member {String} #modelElement
* @member {String}
*/
this.modelElement = modelElement;
}
/**
* Element this command creates in the view.
* See {@link module:heading/headingcommand~HeadingOption}.
*
* @readonly
* @member {String} #viewElement
*/
/**
* @inheritDoc
*/
refresh() {
const block = first( this.editor.document.selection.getSelectedBlocks() );
/**
* User-readable title of the command.
* See {@link module:heading/headingcommand~HeadingOption}.
*
* @readonly
* @member {String} #title
*/
this.value = !!block && block.is( this.modelElement );
this.isEnabled = !!block && checkCanBecomeHeading( block, this.modelElement, this.editor.document.schema );
}
/**
* Executes command.
* Executes the command. Applies the heading to the selected blocks or, if the first selected
* block is a heading already, turns selected headings (of this level only) to paragraphs.
*
* @protected
* @fires execute
* @param {Object} [options] Options for executed command.

@@ -85,27 +69,15 @@ * @param {module:engine/model/batch~Batch} [options.batch] Batch to collect all the change steps.

*/
_doExecute( options = {} ) {
execute( options = {} ) {
const editor = this.editor;
const document = editor.document;
// If current option is same as new option - toggle already applied option back to default one.
const shouldRemove = this.value;
document.enqueueChanges( () => {
const batch = options.batch || document.batch();
const blocks = Array.from( document.selection.getSelectedBlocks() )
.filter( block => {
return checkCanBecomeHeading( block, this.modelElement, document.schema );
} );
for ( let block of document.selection.getSelectedBlocks() ) {
// When removing applied option.
if ( shouldRemove ) {
if ( block.is( this.modelElement ) ) {
// Apply paragraph to the selection withing that particular block only instead
// of working on the entire document selection.
const selection = new Selection();
selection.addRange( Range.createIn( block ) );
// Share the batch with the paragraph command.
editor.execute( 'paragraph', { selection, batch } );
}
}
// When applying new option.
else if ( !block.is( this.modelElement ) ) {
for ( const block of blocks ) {
if ( !block.is( this.modelElement ) ) {
batch.rename( block, this.modelElement );

@@ -116,32 +88,16 @@ }

}
}
/**
* Updates command's {@link #value value} based on current selection.
*/
refreshValue() {
const block = first( this.editor.document.selection.getSelectedBlocks() );
this.value = !!block && block.is( this.modelElement );
}
/**
* @inheritDoc
*/
_checkEnabled() {
const block = first( this.editor.document.selection.getSelectedBlocks() );
return !!block && this.editor.document.schema.check( {
name: this.modelElement,
inside: Position.createBefore( block )
} );
}
// Checks whether the given block can be replaced by a specific heading.
//
// @private
// @param {module:engine/model/element~Element} block A block to be tested.
// @param {module:heading/headingcommand~HeadingCommand#modelElement} heading Command element name in the model.
// @param {module:engine/model/schema~Schema} schema The schema of the document.
// @returns {Boolean}
function checkCanBecomeHeading( block, heading, schema ) {
return schema.check( {
name: heading,
inside: Position.createBefore( block )
} );
}
/**
* Heading option descriptor.
*
* @typedef {Object} module:heading/headingcommand~HeadingOption
* @property {String} modelElement Element's name in the model.
* @property {String} viewElement The name of the view element that will be used to represent the model element in the view.
* @property {String} title The user-readable title of the option.
*/

@@ -22,3 +22,3 @@ /**

*
* @extends modules:core/plugin~Plugin
* @extends module:core/plugin~Plugin
*/

@@ -32,5 +32,2 @@ export default class HeadingEngine extends Plugin {

// TODO: This needs proper documentation, i.e. why paragraph entry does not need
// more properties (https://github.com/ckeditor/ckeditor5/issues/403).
// TODO: Document CSS classes as well.
editor.config.define( 'heading', {

@@ -62,3 +59,3 @@ options: [

for ( let option of options ) {
for ( const option of options ) {
// Skip paragraph - it is defined in required Paragraph feature.

@@ -80,3 +77,3 @@ if ( option.modelElement !== defaultModelElement ) {

// Register the heading command for this option.
editor.commands.set( option.modelElement, new HeadingCommand( editor, option ) );
editor.commands.add( option.modelElement, new HeadingCommand( editor, option.modelElement ) );
}

@@ -83,0 +80,0 @@ }

@@ -33,13 +33,14 @@ /**

return ClassicTestEditor.create( editorElement, {
plugins: [ Heading ],
toolbar: [ 'heading' ]
} )
.then( newEditor => {
editor = newEditor;
dropdown = editor.ui.componentFactory.create( 'headings' );
return ClassicTestEditor
.create( editorElement, {
plugins: [ Heading ],
toolbar: [ 'heading' ]
} )
.then( newEditor => {
editor = newEditor;
dropdown = editor.ui.componentFactory.create( 'headings' );
// Set data so the commands will be enabled.
setData( editor.document, '<paragraph>f{}oo</paragraph>' );
} );
// Set data so the commands will be enabled.
setData( editor.document, '<paragraph>f{}oo</paragraph>' );
} );
} );

@@ -110,3 +111,3 @@

it( 'isEnabled', () => {
for ( let name in commands ) {
for ( const name in commands ) {
commands[ name ].isEnabled = false;

@@ -122,3 +123,3 @@ }

it( 'label', () => {
for ( let name in commands ) {
for ( const name in commands ) {
commands[ name ].value = false;

@@ -210,23 +211,24 @@ }

return ClassicTestEditor.create( editorElement, {
plugins: [ Heading ],
toolbar: [ 'heading' ],
lang: 'pl',
heading: {
options: options
}
} )
.then( newEditor => {
editor = newEditor;
dropdown = editor.ui.componentFactory.create( 'headings' );
commands = {};
return ClassicTestEditor
.create( editorElement, {
plugins: [ Heading ],
toolbar: [ 'heading' ],
lang: 'pl',
heading: {
options
}
} )
.then( newEditor => {
editor = newEditor;
dropdown = editor.ui.componentFactory.create( 'headings' );
commands = {};
editor.config.get( 'heading.options' ).forEach( ( { modelElement } ) => {
commands[ modelElement ] = editor.commands.get( modelElement );
} );
editor.config.get( 'heading.options' ).forEach( ( { modelElement } ) => {
commands[ modelElement ] = editor.commands.get( modelElement );
} );
editorElement.remove();
editorElement.remove();
return editor.destroy();
} );
return editor.destroy();
} );
}

@@ -233,0 +235,0 @@ } );

@@ -28,7 +28,7 @@ /**

editor.commands.set( 'paragraph', new ParagraphCommand( editor ) );
editor.commands.add( 'paragraph', new ParagraphCommand( editor ) );
schema.registerItem( 'paragraph', '$block' );
for ( let option of options ) {
commands[ option.modelElement ] = new HeadingCommand( editor, option );
for ( const option of options ) {
commands[ option.modelElement ] = new HeadingCommand( editor, option.modelElement );
schema.registerItem( option.modelElement, '$block' );

@@ -46,3 +46,3 @@ }

afterEach( () => {
for ( let modelElement in commands ) {
for ( const modelElement in commands ) {
commands[ modelElement ].destroy();

@@ -52,18 +52,10 @@ }

describe( 'basic properties', () => {
for ( let option of options ) {
test( option );
}
function test( { modelElement, viewElement, title } ) {
it( `are set for option.modelElement = ${ modelElement }`, () => {
expect( commands[ modelElement ].modelElement ).to.equal( modelElement );
expect( commands[ modelElement ].viewElement ).to.equal( viewElement );
expect( commands[ modelElement ].title ).to.equal( title );
} );
}
describe( 'modelElement', () => {
it( 'is set', () => {
expect( commands.heading1.modelElement ).to.equal( 'heading1' );
} );
} );
describe( 'value', () => {
for ( let option of options ) {
for ( const option of options ) {
test( option );

@@ -81,4 +73,4 @@ }

it( `equals false if inside to non-block element`, () => {
setData( document, `<notBlock>[foo]</notBlock>` );
it( 'equals false if inside to non-block element', () => {
setData( document, '<notBlock>[foo]</notBlock>' );

@@ -99,3 +91,3 @@ expect( commands[ modelElement ].value ).to.be.false;

it( 'should be refreshed after calling refreshValue()', () => {
it( 'should be refreshed after calling refresh()', () => {
const command = commands[ modelElement ];

@@ -109,3 +101,3 @@ setData( document, `<${ modelElement }>[foo]</${ modelElement }><notBlock>foo</notBlock>` );

expect( command.value ).to.be.true;
command.refreshValue();
command.refresh();
expect( command.value ).to.be.false;

@@ -116,3 +108,3 @@ } );

describe( '_doExecute', () => {
describe( 'execute()', () => {
it( 'should update value after execution', () => {

@@ -122,3 +114,3 @@ const command = commands.heading1;

setData( document, '<paragraph>[]</paragraph>' );
command._doExecute();
command.execute();

@@ -129,25 +121,37 @@ expect( getData( document ) ).to.equal( '<heading1>[]</heading1>' );

describe( 'custom options', () => {
it( 'should use provided batch', () => {
const batch = editor.document.batch();
const command = commands.heading1;
// https://github.com/ckeditor/ckeditor5-heading/issues/73
it( 'should not rename blocks which cannot become headings', () => {
document.schema.registerItem( 'restricted' );
document.schema.allow( { name: 'restricted', inside: '$root' } );
document.schema.disallow( { name: 'heading1', inside: 'restricted' } );
setData( document, '<paragraph>foo[]bar</paragraph>' );
document.schema.registerItem( 'fooBlock', '$block' );
document.schema.allow( { name: 'fooBlock', inside: 'restricted' } );
expect( batch.deltas.length ).to.equal( 0 );
setData(
document,
'<paragraph>a[bc</paragraph>' +
'<restricted><fooBlock></fooBlock></restricted>' +
'<paragraph>de]f</paragraph>'
);
command._doExecute( { batch } );
commands.heading1.execute();
expect( batch.deltas.length ).to.be.above( 0 );
} );
expect( getData( document ) ).to.equal(
'<heading1>a[bc</heading1>' +
'<restricted><fooBlock></fooBlock></restricted>' +
'<heading1>de]f</heading1>'
);
} );
it( 'should use provided batch (converting to default option)', () => {
describe( 'custom options', () => {
it( 'should use provided batch', () => {
const batch = editor.document.batch();
const command = commands.heading1;
setData( document, '<heading1>foo[]bar</heading1>' );
setData( document, '<paragraph>foo[]bar</paragraph>' );
expect( batch.deltas.length ).to.equal( 0 );
command._doExecute( { batch } );
command.execute( { batch } );

@@ -161,3 +165,3 @@ expect( batch.deltas.length ).to.be.above( 0 );

for ( let option of options ) {
for ( const option of options ) {
test( option, convertTo );

@@ -167,9 +171,7 @@ convertTo = option;

it( 'converts to default option when executed with already applied option', () => {
const command = commands.heading1;
it( 'does nothing when executed with already applied option', () => {
setData( document, '<heading1>foo[]bar</heading1>' );
command._doExecute();
expect( getData( document ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
commands.heading1.execute();
expect( getData( document ) ).to.equal( '<heading1>foo[]bar</heading1>' );
} );

@@ -182,3 +184,3 @@

setData( document, '<paragraph><inlineImage>foo[]</inlineImage>bar</paragraph>' );
commands.heading1._doExecute();
commands.heading1.execute();

@@ -191,3 +193,3 @@ expect( getData( document ) ).to.equal( '<heading1><inlineImage>foo[]</inlineImage>bar</heading1>' );

setData( document, `<${ from.modelElement }>foo[]bar</${ from.modelElement }>` );
commands[ to.modelElement ]._doExecute();
commands[ to.modelElement ].execute();

@@ -202,3 +204,3 @@ expect( getData( document ) ).to.equal( `<${ to.modelElement }>foo[]bar</${ to.modelElement }>` );

for ( let option of options ) {
for ( const option of options ) {
test( option, convertTo );

@@ -209,19 +211,29 @@ convertTo = option;

it( 'converts all elements where selection is applied', () => {
setData( document, '<heading1>foo[</heading1><heading2>bar</heading2><heading3>]baz</heading3>' );
commands.heading3._doExecute();
setData( document, '<heading1>foo[</heading1><heading2>bar</heading2><heading3>baz]</heading3>' );
commands.heading3.execute();
expect( getData( document ) ).to.equal(
'<heading3>foo[</heading3><heading3>bar</heading3><heading3>]baz</heading3>'
'<heading3>foo[</heading3><heading3>bar</heading3><heading3>baz]</heading3>'
);
} );
it( 'resets to default value all elements with same option', () => {
setData( document, '<heading1>foo[</heading1><heading1>bar</heading1><heading2>baz</heading2>]' );
commands.heading1._doExecute();
it( 'does nothing to the elements with same option (#1)', () => {
setData( document, '<heading1>[foo</heading1><heading1>bar]</heading1>' );
commands.heading1.execute();
expect( getData( document ) ).to.equal(
'<paragraph>foo[</paragraph><paragraph>bar</paragraph><heading2>baz</heading2>]'
'<heading1>[foo</heading1><heading1>bar]</heading1>'
);
} );
it( 'does nothing to the elements with same option (#2)', () => {
setData( document, '<heading1>[foo</heading1><heading1>bar</heading1><heading2>baz]</heading2>' );
commands.heading1.execute();
expect( getData( document ) ).to.equal(
'<heading1>[foo</heading1><heading1>bar</heading1><heading1>baz]</heading1>'
);
} );
function test( { modelElement: fromElement }, { modelElement: toElement } ) {

@@ -234,3 +246,3 @@ it( `converts ${ fromElement } to ${ toElement } on non-collapsed selection`, () => {

commands[ toElement ]._doExecute();
commands[ toElement ].execute();

@@ -246,3 +258,3 @@ expect( getData( document ) ).to.equal(

describe( 'isEnabled', () => {
for ( let option of options ) {
for ( const option of options ) {
test( option.modelElement );

@@ -249,0 +261,0 @@ }

@@ -11,3 +11,2 @@ /**

import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';

@@ -19,9 +18,10 @@

beforeEach( () => {
return VirtualTestEditor.create( {
plugins: [ Enter, HeadingEngine ]
} )
.then( newEditor => {
editor = newEditor;
document = editor.document;
} );
return VirtualTestEditor
.create( {
plugins: [ HeadingEngine ]
} )
.then( newEditor => {
editor = newEditor;
document = editor.document;
} );
} );

@@ -80,25 +80,7 @@

it( 'should make enter command insert a defaultOption block if selection ended at the end of heading block', () => {
editor.setData( '<h2>foobar</h2>' );
document.selection.collapse( document.getRoot().getChild( 0 ), 'end' );
editor.execute( 'enter' );
expect( getData( document ) ).to.equal( '<heading1>foobar</heading1><paragraph>[]</paragraph>' );
} );
it( 'should not alter enter command if selection not ended at the end of heading block', () => {
// This test is to fill code coverage.
editor.setData( '<h2>foobar</h2>' );
document.selection.collapse( document.getRoot().getChild( 0 ), 3 );
editor.execute( 'enter' );
expect( getData( document ) ).to.equal( '<heading1>foo</heading1><heading1>[]bar</heading1>' );
} );
it( 'should not blow up if there\'s no enter command in the editor', () => {
return VirtualTestEditor.create( {
plugins: [ HeadingEngine ]
} );
return VirtualTestEditor
.create( {
plugins: [ HeadingEngine ]
} );
} );

@@ -125,21 +107,22 @@

return VirtualTestEditor.create( {
plugins: [ Enter, HeadingEngine ],
heading: {
options: options
}
} )
.then( editor => {
document = editor.document;
return VirtualTestEditor
.create( {
plugins: [ HeadingEngine ],
heading: {
options
}
} )
.then( editor => {
document = editor.document;
expect( editor.commands.get( 'h4' ) ).to.be.instanceOf( HeadingCommand );
expect( editor.commands.get( 'paragraph' ) ).to.be.instanceOf( ParagraphCommand );
expect( editor.commands.get( 'h4' ) ).to.be.instanceOf( HeadingCommand );
expect( editor.commands.get( 'paragraph' ) ).to.be.instanceOf( ParagraphCommand );
expect( document.schema.hasItem( 'paragraph' ) ).to.be.true;
expect( document.schema.hasItem( 'h4' ) ).to.be.true;
expect( document.schema.hasItem( 'paragraph' ) ).to.be.true;
expect( document.schema.hasItem( 'h4' ) ).to.be.true;
expect( document.schema.hasItem( 'heading1' ) ).to.be.false;
expect( document.schema.hasItem( 'heading2' ) ).to.be.false;
expect( document.schema.hasItem( 'heading3' ) ).to.be.false;
} );
expect( document.schema.hasItem( 'heading1' ) ).to.be.false;
expect( document.schema.hasItem( 'heading2' ) ).to.be.false;
expect( document.schema.hasItem( 'heading3' ) ).to.be.false;
} );
} );

@@ -146,0 +129,0 @@ } );

@@ -8,3 +8,3 @@ /**

import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic';
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import Enter from '@ckeditor/ckeditor5-enter/src/enter';

@@ -16,11 +16,12 @@ import Typing from '@ckeditor/ckeditor5-typing/src/typing';

ClassicEditor.create( document.querySelector( '#editor' ), {
plugins: [ Enter, Typing, Undo, Heading, Paragraph ],
toolbar: [ 'headings', 'undo', 'redo' ]
} )
.then( editor => {
window.editor = editor;
} )
.catch( err => {
console.error( err.stack );
} );
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ Enter, Typing, Undo, Heading, Paragraph ],
toolbar: [ 'headings', 'undo', 'redo' ]
} )
.then( editor => {
window.editor = editor;
} )
.catch( err => {
console.error( err.stack );
} );

@@ -19,30 +19,32 @@ /**

it( 'enter at the end of a heading creates a paragraph, when heading was loaded before enter', () => {
return VirtualTestEditor.create( {
plugins: [ HeadingEngine, Enter ]
} )
.then( newEditor => {
editor = newEditor;
return VirtualTestEditor
.create( {
plugins: [ HeadingEngine, Enter ]
} )
.then( newEditor => {
editor = newEditor;
setData( editor.document, '<heading1>foo[]</heading1>' );
setData( editor.document, '<heading1>foo[]</heading1>' );
editor.execute( 'enter' );
editor.execute( 'enter' );
expect( getData( editor.document ) ).to.equal( '<heading1>foo</heading1><paragraph>[]</paragraph>' );
} );
expect( getData( editor.document ) ).to.equal( '<heading1>foo</heading1><paragraph>[]</paragraph>' );
} );
} );
it( 'enter at the end of a heading creates a paragraph, when enter was loaded before heading', () => {
return VirtualTestEditor.create( {
plugins: [ Enter, HeadingEngine ]
} )
.then( newEditor => {
editor = newEditor;
return VirtualTestEditor
.create( {
plugins: [ Enter, HeadingEngine ]
} )
.then( newEditor => {
editor = newEditor;
setData( editor.document, '<heading1>foo[]</heading1>' );
setData( editor.document, '<heading1>foo[]</heading1>' );
editor.execute( 'enter' );
editor.execute( 'enter' );
expect( getData( editor.document ) ).to.equal( '<heading1>foo</heading1><paragraph>[]</paragraph>' );
} );
expect( getData( editor.document ) ).to.equal( '<heading1>foo</heading1><paragraph>[]</paragraph>' );
} );
} );
} );

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc