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

Commit

Permalink
Merge pull request #79 from ckeditor/t/78
Browse files Browse the repository at this point in the history
Other: Removed `HeadingCommand`'s properties which were exposed unnecessarily. Closes #78.

BREAKING CHANGE: 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.
  • Loading branch information
szymonkups authored Jun 8, 2017
2 parents 02f66a0 + 219e0e4 commit c80e691
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 52 deletions.
13 changes: 11 additions & 2 deletions src/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ export default class Heading extends Plugin {

/**
* 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.
*
* Note: The reason behind this method is that there's no way to use {@link module:utils/locale~Locale#t}
* when the user config is defined because the editor does not exist yet.
*
* @private
* @returns {Array.<module:heading/headingcommand~HeadingOption>}.
* @returns {Array.<module:heading/heading~HeadingOption>}.
*/
_getLocalizedOptions() {
const editor = this.editor;
Expand Down Expand Up @@ -159,3 +159,12 @@ export default class Heading extends Plugin {
function getCommandsBindingTargets( commands, attribute ) {
return Array.prototype.concat( ...commands.map( c => [ c, attribute ] ) );
}

/**
* 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.
*/
46 changes: 10 additions & 36 deletions src/headingcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ export default class HeadingCommand extends Command {
* Creates an instance of the 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 );
/**
* Unique identifier of the command, also element's name in the model.
* See {@link module:heading/heading~HeadingOption}.
*
* @readonly
* @member {String}
*/
this.modelElement = modelElement;

/**
* Value of the command, indicating whether it is applied in the context
Expand All @@ -45,30 +52,6 @@ export default class HeadingCommand extends Command {
this.refreshValue();
this.refreshState();
} );

/**
* Unique identifier of the command, also element's name in the model.
* See {@link module:heading/headingcommand~HeadingOption}.
*
* @readonly
* @member {String} #modelElement
*/

/**
* Element this command creates in the view.
* See {@link module:heading/headingcommand~HeadingOption}.
*
* @readonly
* @member {String} #viewElement
*/

/**
* User-readable title of the command.
* See {@link module:heading/headingcommand~HeadingOption}.
*
* @readonly
* @member {String} #title
*/
}

/**
Expand Down Expand Up @@ -147,12 +130,3 @@ function checkCanBecomeHeading( block, heading, schema ) {
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.
*/
2 changes: 1 addition & 1 deletion src/headingengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class HeadingEngine extends Plugin {
.toElement( option.modelElement );

// Register the heading command for this option.
editor.commands.set( option.modelElement, new HeadingCommand( editor, option ) );
editor.commands.set( option.modelElement, new HeadingCommand( editor, option.modelElement ) );
}
}
}
Expand Down
18 changes: 5 additions & 13 deletions tests/headingcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe( 'HeadingCommand', () => {
schema.registerItem( 'paragraph', '$block' );

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

Expand All @@ -47,18 +47,10 @@ describe( 'HeadingCommand', () => {
}
} );

describe( 'basic properties', () => {
for ( const 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', () => {
Expand Down

0 comments on commit c80e691

Please sign in to comment.