imagestyle.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module image/imagestyle
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ImageStyleEditing from './imagestyle/imagestyleediting';
  10. import ImageStyleUI from './imagestyle/imagestyleui';
  11. /**
  12. * The image style plugin.
  13. *
  14. * For a detailed overview, check the {@glink features/image#image-styles image styles} documentation.
  15. *
  16. * This is a "glue" plugin which loads the {@link module:image/imagestyle/imagestyleediting~ImageStyleEditing}
  17. * and {@link module:image/imagestyle/imagestyleui~ImageStyleUI} plugins.
  18. *
  19. * @extends module:core/plugin~Plugin
  20. */
  21. export default class ImageStyle extends Plugin {
  22. /**
  23. * @inheritDoc
  24. */
  25. static get requires() {
  26. return [ ImageStyleEditing, ImageStyleUI ];
  27. }
  28. /**
  29. * @inheritDoc
  30. */
  31. static get pluginName() {
  32. return 'ImageStyle';
  33. }
  34. }
  35. /**
  36. * Available image styles.
  37. *
  38. * The default value is:
  39. *
  40. * const imageConfig = {
  41. * styles: [ 'full', 'side' ]
  42. * };
  43. *
  44. * which configures two default styles:
  45. *
  46. * * the "full" style which does not apply any class, e.g. for images styled to span 100% width of the content,
  47. * * the "side" style with the `.image-style-side` CSS class.
  48. *
  49. * See {@link module:image/imagestyle/utils~defaultStyles} to learn more about default
  50. * styles provided by the image feature.
  51. *
  52. * The {@link module:image/imagestyle/utils~defaultStyles default styles} can be customized,
  53. * e.g. to change the icon, title or CSS class of the style. The feature also provides several
  54. * {@link module:image/imagestyle/utils~defaultIcons default icons} to choose from.
  55. *
  56. * import customIcon from 'custom-icon.svg';
  57. *
  58. * // ...
  59. *
  60. * const imageConfig = {
  61. * styles: [
  62. * // This will only customize the icon of the "full" style.
  63. * // Note: 'right' is one of default icons provided by the feature.
  64. * { name: 'full', icon: 'right' },
  65. *
  66. * // This will customize the icon, title and CSS class of the default "side" style.
  67. * { name: 'side', icon: customIcon, title: 'My side style', className: 'custom-side-image' }
  68. * ]
  69. * };
  70. *
  71. * If none of the default styles is good enough, it is possible to define independent custom styles, too:
  72. *
  73. * import fullSizeIcon from '@ckeditor/ckeditor5-core/theme/icons/object-center.svg';
  74. * import sideIcon from '@ckeditor/ckeditor5-core/theme/icons/object-right.svg';
  75. *
  76. * // ...
  77. *
  78. * const imageConfig = {
  79. * styles: [
  80. * // A completely custom full size style with no class, used as a default.
  81. * { name: 'fullSize', title: 'Full size', icon: fullSizeIcon, isDefault: true },
  82. *
  83. * { name: 'side', title: 'To the side', icon: sideIcon, className: 'side-image' }
  84. * ]
  85. * };
  86. *
  87. * Note: Setting `title` to one of {@link module:image/imagestyle/imagestyleui~ImageStyleUI#localizedDefaultStylesTitles}
  88. * will automatically translate it to the language of the editor.
  89. *
  90. * Read more about styling images in the {@glink features/image#image-styles Image styles guide}.
  91. *
  92. * The feature creates commands based on defined styles, so you can change the style of a selected image by executing
  93. * the following command:
  94. *
  95. * editor.execute( 'imageStyle' { value: 'side' } );
  96. *
  97. * The feature also creates buttons that execute the commands. So, assuming that you use the
  98. * default image styles setting, you can {@link module:image/image~ImageConfig#toolbar configure the image toolbar}
  99. * (or any other toolbar) to contain these options:
  100. *
  101. * const imageConfig = {
  102. * toolbar: [ 'imageStyle:full', 'imageStyle:side' ]
  103. * };
  104. *
  105. * @member {Array.<module:image/imagestyle/imagestyleediting~ImageStyleFormat>} module:image/image~ImageConfig#styles
  106. */