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 #177 from ckeditor/t/ckeditor5/488
Browse files Browse the repository at this point in the history
Other: Align feature class naming to a new scheme.
  • Loading branch information
scofalik authored Feb 27, 2018
2 parents 70ea9ee + c0cd431 commit 8690765
Show file tree
Hide file tree
Showing 33 changed files with 1,142 additions and 1,044 deletions.
2 changes: 1 addition & 1 deletion docs/features/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ See the result below:

### Defining custom styles

Besides using the {@link module:image/imagestyle/imagestyleengine~ImageStyleEngine.defaultStyles 5 predefined styles}:
Besides using the {@link module:image/imagestyle/imagestyleediting~ImageStyleEditing.defaultStyles 5 predefined styles}:

* `'imageStyleFull'`,
* `'imageStyleSide'`,
Expand Down
26 changes: 3 additions & 23 deletions src/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ImageEngine from './image/imageengine';
import ImageEditing from '../src/image/imageediting';
import Widget from '@ckeditor/ckeditor5-widget/src/widget';
import ImageTextAlternative from './imagetextalternative';
import { isImageWidgetSelected } from './image/utils';

import '../theme/image.css';

/**
* The image plugin.
*
* Uses the {@link module:image/image/imageengine~ImageEngine}.
* Uses the {@link module:image/image/imageediting~ImageEditing}.
*
* @extends module:core/plugin~Plugin
*/
Expand All @@ -27,7 +26,7 @@ export default class Image extends Plugin {
* @inheritDoc
*/
static get requires() {
return [ ImageEngine, Widget, ImageTextAlternative ];
return [ ImageEditing, Widget, ImageTextAlternative ];
}

/**
Expand All @@ -36,25 +35,6 @@ export default class Image extends Plugin {
static get pluginName() {
return 'Image';
}

/**
* @inheritDoc
*/
init() {
const editor = this.editor;
const balloonToolbar = editor.plugins.get( 'BalloonToolbar' );

// If `BalloonToolbar` plugin is loaded, it should be disabled for images
// which have their own toolbar to avoid duplication.
// https://github.com/ckeditor/ckeditor5-image/issues/110
if ( balloonToolbar ) {
this.listenTo( balloonToolbar, 'show', evt => {
if ( isImageWidgetSelected( editor.editing.view.document.selection ) ) {
evt.stop();
}
}, { priority: 'high' } );
}
}
}

/**
Expand Down
13 changes: 4 additions & 9 deletions src/image/imageengine.js → src/image/imageediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/**
* @module image/image/imageengine
* @module image/image/imageediting
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
Expand All @@ -29,7 +29,7 @@ import ViewPosition from '@ckeditor/ckeditor5-engine/src/view/position';
*
* @extends module:core/plugin~Plugin
*/
export default class ImageEngine extends Plugin {
export default class ImageEditing extends Plugin {
/**
* @inheritDoc
*/
Expand All @@ -47,19 +47,14 @@ export default class ImageEngine extends Plugin {
allowAttributes: [ 'alt', 'src', 'srcset' ]
} );

const dataElementCreator = ( modelElement, viewWriter ) => createImageViewElement( viewWriter );
conversion.for( 'dataDowncast' ).add( downcastElementToElement( {
model: 'image',
view: dataElementCreator
view: ( modelElement, viewWriter ) => createImageViewElement( viewWriter )
} ) );

const editingElementCreator = ( modelElement, viewWriter ) => {
return toImageWidget( createImageViewElement( viewWriter ), viewWriter, t( 'image widget' ) );
};

conversion.for( 'editingDowncast' ).add( downcastElementToElement( {
model: 'image',
view: editingElementCreator
view: ( modelElement, viewWriter ) => toImageWidget( createImageViewElement( viewWriter ), viewWriter, t( 'image widget' ) )
} ) );

conversion.for( 'downcast' )
Expand Down
4 changes: 2 additions & 2 deletions src/imagecaption.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ImageCaptionEngine from './imagecaption/imagecaptionengine';
import ImageCaptionEditing from './imagecaption/imagecaptionediting';

import '../theme/imagecaption.css';

Expand All @@ -22,7 +22,7 @@ export default class ImageCaption extends Plugin {
* @inheritDoc
*/
static get requires() {
return [ ImageCaptionEngine ];
return [ ImageCaptionEditing ];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/**
* @module image/imagecaption/imagecaptionengine
* @module image/imagecaption/imagecaptionediting
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
Expand All @@ -25,7 +25,7 @@ import {
*
* @extends module:core/plugin~Plugin
*/
export default class ImageCaptionEngine extends Plugin {
export default class ImageCaptionEditing extends Plugin {
/**
* @inheritDoc
*/
Expand Down
65 changes: 12 additions & 53 deletions src/imagestyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
*/

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

import '../theme/imagestyle.css';
import ImageStyleEditing from './imagestyle/imagestyleediting';
import ImageStyleUI from './imagestyle/imagestyleui';

/**
* The image style plugin.
*
* Uses the {@link module:image/imagestyle/imagestyleengine~ImageStyleEngine}.
* It loads the {@link module:image/imagestyle/imagestyleediting~ImageStyleEditing}
* and {@link module:image/imagestyle/imagestyleui~ImageStyleUI} plugins.
*
* @extends module:core/plugin~Plugin
*/
Expand All @@ -25,7 +24,7 @@ export default class ImageStyle extends Plugin {
* @inheritDoc
*/
static get requires() {
return [ ImageStyleEngine ];
return [ ImageStyleEditing, ImageStyleUI ];
}

/**
Expand All @@ -34,55 +33,15 @@ export default class ImageStyle extends Plugin {
static get pluginName() {
return 'ImageStyle';
}

/**
* @inheritDoc
*/
init() {
const editor = this.editor;
const styles = editor.plugins.get( ImageStyleEngine ).imageStyles;

for ( const style of styles ) {
this._createButton( style );
}
}

/**
* Creates a button for each style and stores it in the editor {@link module:ui/componentfactory~ComponentFactory ComponentFactory}.
*
* @private
* @param {module:image/imagestyle/imagestyleengine~ImageStyleFormat} style
*/
_createButton( style ) {
const editor = this.editor;
const command = editor.commands.get( style.name );

editor.ui.componentFactory.add( style.name, locale => {
const view = new ButtonView( locale );

view.set( {
label: style.title,
icon: style.icon,
tooltip: true
} );

view.bind( 'isEnabled' ).to( command, 'isEnabled' );
view.bind( 'isOn' ).to( command, 'value' );

this.listenTo( view, 'execute', () => editor.execute( style.name ) );

return view;
} );
}
}

/**
* Available image styles.
* The option is used by the {@link module:image/imagestyle/imagestyleengine~ImageStyleEngine} feature.
* The option is used by the {@link module:image/imagestyle/imagestyleediting~ImageStyleEditing} feature.
*
* The default value is:
*
* const imageConfig = {
* const imageConfig = {
* styles: [ 'imageStyleFull', 'imageStyleSide' ]
* };
*
Expand All @@ -91,12 +50,12 @@ export default class ImageStyle extends Plugin {
* * the "full" style which doesn't apply any class, e.g. for images styled to span 100% width of the content,
* * the "side" style with the `.image-style-side` CSS class.
*
* See {@link module:image/imagestyle/imagestyleengine~ImageStyleEngine.defaultStyles} to learn more about default
* See {@link module:image/imagestyle/utils~defaultStyles} to learn more about default
* styles provided by the image feature.
*
* The {@link module:image/imagestyle/imagestyleengine~ImageStyleEngine.defaultStyles default styles} can be customized,
* The {@link module:image/imagestyle/utils~defaultStyles default styles} can be customized,
* e.g. to change the icon, title or CSS class of the style. The feature also provides several
* {@link module:image/imagestyle/imagestyleengine~ImageStyleEngine.defaultIcons default icons} to chose from.
* {@link module:image/imagestyle/utils~defaultIcons default icons} to chose from.
*
* import customIcon from 'custom-icon.svg';
*
Expand Down Expand Up @@ -129,7 +88,7 @@ export default class ImageStyle extends Plugin {
* ]
* };
*
* Note: Setting `title` to one of {@link module:image/imagestyle/imagestyleengine~ImageStyleEngine#localizedDefaultStylesTitles}
* Note: Setting `title` to one of {@link module:image/imagestyle/imagestyleui~ImageStyleUI#localizedDefaultStylesTitles}
* will automatically translate it to the language of the editor.
*
* Read more about styling images in the {@glink features/image#Image-styles Image styles guide}.
Expand All @@ -147,5 +106,5 @@ export default class ImageStyle extends Plugin {
* toolbar: [ 'imageStyleFull', 'imageStyleSide' ]
* };
*
* @member {Array.<module:image/imagestyle/imagestyleengine~ImageStyleFormat>} module:image/image~ImageConfig#styles
* @member {Array.<module:image/imagestyle/imagestyleediting~ImageStyleFormat>} module:image/image~ImageConfig#styles
*/
8 changes: 4 additions & 4 deletions src/imagestyle/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import first from '@ckeditor/ckeditor5-utils/src/first';
/**
* Returns a converter for the `imageStyle` attribute. It can be used for adding, changing and removing the attribute.
*
* @param {Object} styles An object containing available styles. See {@link module:image/imagestyle/imagestyleengine~ImageStyleFormat}
* @param {Object} styles An object containing available styles. See {@link module:image/imagestyle/imagestyleediting~ImageStyleFormat}
* for more details.
* @returns {Function} A model-to-view attribute converter.
*/
Expand Down Expand Up @@ -42,7 +42,7 @@ export function modelToViewStyleAttribute( styles ) {
/**
* Returns a view-to-model converter converting image CSS classes to a proper value in the model.
*
* @param {Array.<module:image/imagestyle/imagestyleengine~ImageStyleFormat>} styles Styles for which the converter is created.
* @param {Array.<module:image/imagestyle/imagestyleediting~ImageStyleFormat>} styles Styles for which the converter is created.
* @returns {Function} A view-to-model converter.
*/
export function viewToModelStyleAttribute( styles ) {
Expand Down Expand Up @@ -76,8 +76,8 @@ export function viewToModelStyleAttribute( styles ) {
// Returns style with given `name` from array of styles.
//
// @param {String} name
// @param {Array.<module:image/imagestyle/imagestyleengine~ImageStyleFormat> } styles
// @return {module:image/imagestyle/imagestyleengine~ImageStyleFormat|undefined}
// @param {Array.<module:image/imagestyle/imagestyleediting~ImageStyleFormat> } styles
// @return {module:image/imagestyle/imagestyleediting~ImageStyleFormat|undefined}
function getStyleByName( name, styles ) {
for ( const style of styles ) {
if ( style.name === name ) {
Expand Down
4 changes: 2 additions & 2 deletions src/imagestyle/imagestylecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class ImageStyleCommand extends Command {
* Creates an instance of the image style command. Each command instance is handling one style.
*
* @param {module:core/editor/editor~Editor} editor The editor instance.
* @param {module:image/imagestyle/imagestyleengine~ImageStyleFormat} style A style to be applied by this command.
* @param {module:image/imagestyle/imagestyleediting~ImageStyleFormat} style A style to be applied by this command.
*/
constructor( editor, style ) {
super( editor );
Expand All @@ -38,7 +38,7 @@ export default class ImageStyleCommand extends Command {
* A style handled by this command.
*
* @readonly
* @member {module:image/imagestyle/imagestyleengine~ImageStyleFormat} #style
* @member {module:image/imagestyle/imagestyleediting~ImageStyleFormat} #style
*/
this.style = style;
}
Expand Down
Loading

0 comments on commit 8690765

Please sign in to comment.