Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I/7559: Update ImageResizeUI plugin #7616

Merged
merged 27 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0fd6e0b
Add icons.
panr Jul 10, 2020
75dfc30
Update manual test.
panr Jul 10, 2020
ba29358
Update unit tests.
panr Jul 10, 2020
b93c435
Fix styles.
panr Jul 10, 2020
5376350
Change plugin behavior and refactor existing code.
panr Jul 10, 2020
06f6cf8
Update API docs.
panr Jul 13, 2020
edabdcd
Update module path for `image/imageresize/imageresizeediting`.
panr Jul 13, 2020
66f6d04
Update the `ImageResizeUI` plugin and tests.
panr Jul 13, 2020
5256591
Clean plugin icons.
panr Jul 13, 2020
567ce7e
Update manual test description.
panr Jul 13, 2020
1d803c6
Fix comment formatting.
panr Jul 13, 2020
5a0f4ea
Update unit tests.
panr Jul 13, 2020
0584d97
Merge branch 'master' into i/7559
panr Jul 13, 2020
8440968
Move icons to the `ckeditor5-core` package.
panr Jul 15, 2020
def39ba
Refactor plugin.
panr Jul 15, 2020
a7d8714
Fix unit tests.
panr Jul 15, 2020
4f53ee1
Update plugin styling.
panr Jul 15, 2020
78a2e8e
Remove icons from the plugin.
panr Jul 15, 2020
41ad1ea
Replace width/height with viewBox in svgs.
panr Jul 16, 2020
24c6e28
Refactor the plugin options API docs.
panr Jul 16, 2020
1d45d2c
Refactor plugin code.
panr Jul 16, 2020
166ef08
Merge branch 'master' into i/7559
oleq Jul 16, 2020
71dbcb3
Tests: Improved the ImageResizeUI manual test instructions.
oleq Jul 16, 2020
27fee04
Docs and code refactoring.
oleq Jul 16, 2020
e3661dd
Docs: Minor corrections in image resize docs.
oleq Jul 16, 2020
21cc867
Fix image resize snippets configuration.
panr Jul 16, 2020
7f2b25e
Update translations.
panr Jul 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ckeditor5-core/theme/icons/object-size-full.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/ckeditor5-core/theme/icons/object-size-large.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/ckeditor5-core/theme/icons/object-size-medium.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/ckeditor5-core/theme/icons/object-size-small.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 66 additions & 22 deletions packages/ckeditor5-image/src/imageresize.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,21 @@ export default class ImageResize extends Plugin {
*/

/**
* The resize options.
* The image resize options.
*
* Each option should have its `name`, which is a component name definition that will be
* used in the {@link module:image/imageresize/imageresizeui~ImageResizeUI} plugin.
* Other properties like `label` and `value` define the following:
* a text label for the option button and the value that will be applied to the image's width.
* Each option should have at least these two properties:
*
* The value property is combined with the `resizeUnit` (`%` by default), eg: `value: '50'` and `resizeUnit: '%'` is `50%`.
* * name: The name of the UI component registered in the global
* {@link module:core/editor/editorui~EditorUI#componentFactory component factory} of the editor,
* representing the button a user can click to change the size of an image,
* * value: An actual image width applied when a user clicks the mentioned button
* ({@link module:image/imageresize/imageresizecommand~ImageResizeCommand} gets executed).
* The value property is combined with the {@link module:image/image~ImageConfig#resizeUnit `config.image.resizeUnit`} (`%` by default).
* For instance: `value: '50'` and `resizeUnit: '%'` will render as `'50%'` in the UI.
*
* **NOTE:** If you want to set an option that will reset image to its original size, you need to pass a `null` value
* **Resetting the image size**
*
* If you want to set an option that will reset image to its original size, you need to pass a `null` value
* to one of the options. The `:original` token is not mandatory, you can call it anything you wish, but it must reflect
* in the standalone buttons configuration for the image toolbar.
*
Expand All @@ -77,45 +82,41 @@ export default class ImageResize extends Plugin {
* resizeUnit: "%",
* resizeOptions: [ {
* name: 'imageResize:original',
* label: 'Original size',
* value: null
* },
* {
* name: 'imageResize:50',
* label: '50%',
* value: '50'
* },
* {
* name: 'imageResize:75',
* label: '75%',
* value: '75'
* } ]
* }
* } )
* .then( ... )
* .catch( ... );
*
* **Resizing images using a dropdown**
*
* With resize options defined, you can decide whether you want to display them as a dropdown or as standalone buttons.
* For the dropdown, you need to pass only the `imageResize` token to the `image.toolbar`.
* The dropdown contains all defined options by default:
* For the dropdown, you need to pass only the `imageResize` token to the
{@link module:image/image~ImageConfig#toolbar `config.image.toolbar`}. The dropdown contains all defined options by default:
*
* ClassicEditor
* ClassicEditor
* .create( editorElement, {
* image: {
* resizeUnit: "%",
* resizeOptions: [ {
* name: 'imageResize:original',
* label: 'Original size',
* value: null
* },
* {
* name: 'imageResize:50',
* label: '50%',
* value: '50'
* },
* {
* name: 'imageResize:75',
* label: '75%',
* value: '75'
* } ],
* toolbar: [ 'imageResize', ... ],
Expand All @@ -124,33 +125,76 @@ export default class ImageResize extends Plugin {
* .then( ... )
* .catch( ... );
*
* If you want to have separate buttons for each option, pass their names instead:
* **Resizing images using individual buttons**
*
* If you want to have separate buttons for {@link module:image/imageresize/imageresizeui~ImageResizeOption each option},
* pass their names to the {@link module:image/image~ImageConfig#toolbar `config.image.toolbar`} instead. Please keep in mind
* that this time **you must define the additional
* {@link module:image/imageresize/imageresizeui~ImageResizeOption `icon` property}**:
*
* ClassicEditor
* ClassicEditor
* .create( editorElement, {
* image: {
* resizeUnit: "%",
* resizeOptions: [ {
* name: 'imageResize:original',
* label: 'Original size',
* value: null
* icon: 'original'
* },
* {
* name: 'imageResize:25',
* value: '25'
* icon: 'small'
* },
* {
* name: 'imageResize:50',
* label: '50%',
* value: '50'
* icon: 'medium'
* },
* {
* name: 'imageResize:75',
* label: '75%',
* value: '75'
* icon: 'large'
* } ],
* toolbar: [ 'imageResize:original', 'imageResize:50', 'imageResize:75', ... ],
* toolbar: [ 'imageResize:25', 'imageResize:50', 'imageResize:75', 'imageResize:original', ... ],
* }
* } )
* .then( ... )
* .catch( ... );
*
* **Customizing resize button labels**
*
* You can set your own label for each resize button. To do that, add the `label` property like in the example below.
*
* * When using the **dropdown**, the labels are displayed on the list of all options when you open the dropdown.
* * When using **standalone buttons**, the labels will are displayed as tooltips when a user hovers over the button.
*
* ClassicEditor
* .create( editorElement, {
* image: {
* resizeUnit: "%",
* resizeOptions: [ {
* name: 'imageResize:original',
* value: null,
* label: 'Original size'
* // Note: add the "icon" property if you're configuring a standalone button.
* },
* {
* name: 'imageResize:50',
* value: '50',
* label: 'Medium size'
* // Note: add the "icon" property if you're configuring a standalone button.
* },
* {
* name: 'imageResize:75',
* value: '75',
* label: 'Large size'
* // Note: add the "icon" property if you're configuring a standalone button.
* } ]
* }
* } )
* .then( ... )
* .catch( ... );
*
* @member {Array.<module:image/imageresize/imageresizeui~ImageResizeOption>} module:image/image~ImageConfig#resizeOptions
*/
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/**
* @module image/imageresizeediting
* @module image/imageresize/imageresizeediting
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
Expand Down