@ckeditor/ckeditor5-image 38.0.1 → 38.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/build/image.js +1 -1
  2. package/build/image.js.map +1 -0
  3. package/package.json +3 -42
  4. package/src/augmentation.d.ts +55 -55
  5. package/src/augmentation.js +5 -5
  6. package/src/autoimage.d.ts +52 -52
  7. package/src/autoimage.js +132 -132
  8. package/src/image/converters.d.ts +66 -66
  9. package/src/image/converters.js +242 -242
  10. package/src/image/imageblockediting.d.ts +55 -55
  11. package/src/image/imageblockediting.js +136 -136
  12. package/src/image/imageediting.d.ts +30 -30
  13. package/src/image/imageediting.js +74 -74
  14. package/src/image/imageinlineediting.d.ts +56 -56
  15. package/src/image/imageinlineediting.js +160 -160
  16. package/src/image/imageloadobserver.d.ts +48 -48
  17. package/src/image/imageloadobserver.js +52 -52
  18. package/src/image/imagetypecommand.d.ts +40 -40
  19. package/src/image/imagetypecommand.js +77 -77
  20. package/src/image/insertimagecommand.d.ts +66 -66
  21. package/src/image/insertimagecommand.js +120 -120
  22. package/src/image/replaceimagesourcecommand.d.ts +34 -34
  23. package/src/image/replaceimagesourcecommand.js +44 -44
  24. package/src/image/ui/utils.d.ts +25 -25
  25. package/src/image/ui/utils.js +44 -44
  26. package/src/image/utils.d.ts +52 -52
  27. package/src/image/utils.js +100 -100
  28. package/src/image.d.ts +34 -34
  29. package/src/image.js +38 -38
  30. package/src/imageblock.d.ts +33 -33
  31. package/src/imageblock.js +37 -37
  32. package/src/imagecaption/imagecaptionediting.d.ts +89 -89
  33. package/src/imagecaption/imagecaptionediting.js +225 -225
  34. package/src/imagecaption/imagecaptionui.d.ts +26 -26
  35. package/src/imagecaption/imagecaptionui.js +61 -61
  36. package/src/imagecaption/imagecaptionutils.d.ts +38 -38
  37. package/src/imagecaption/imagecaptionutils.js +62 -62
  38. package/src/imagecaption/toggleimagecaptioncommand.d.ts +66 -66
  39. package/src/imagecaption/toggleimagecaptioncommand.js +138 -138
  40. package/src/imagecaption.d.ts +26 -26
  41. package/src/imagecaption.js +30 -30
  42. package/src/imageconfig.d.ts +713 -713
  43. package/src/imageconfig.js +5 -5
  44. package/src/imageinline.d.ts +33 -33
  45. package/src/imageinline.js +37 -37
  46. package/src/imageinsert/imageinsertui.d.ts +44 -44
  47. package/src/imageinsert/imageinsertui.js +141 -141
  48. package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -61
  49. package/src/imageinsert/ui/imageinsertformrowview.js +54 -54
  50. package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -106
  51. package/src/imageinsert/ui/imageinsertpanelview.js +161 -161
  52. package/src/imageinsert/utils.d.ts +25 -25
  53. package/src/imageinsert/utils.js +58 -58
  54. package/src/imageinsert.d.ts +33 -33
  55. package/src/imageinsert.js +37 -37
  56. package/src/imageinsertviaurl.d.ts +30 -30
  57. package/src/imageinsertviaurl.js +34 -34
  58. package/src/imageresize/imageresizebuttons.d.ts +67 -67
  59. package/src/imageresize/imageresizebuttons.js +217 -217
  60. package/src/imageresize/imageresizeediting.d.ts +37 -37
  61. package/src/imageresize/imageresizeediting.js +114 -114
  62. package/src/imageresize/imageresizehandles.d.ts +30 -30
  63. package/src/imageresize/imageresizehandles.js +107 -107
  64. package/src/imageresize/resizeimagecommand.d.ts +42 -42
  65. package/src/imageresize/resizeimagecommand.js +61 -61
  66. package/src/imageresize.d.ts +27 -27
  67. package/src/imageresize.js +31 -31
  68. package/src/imagestyle/converters.d.ts +24 -24
  69. package/src/imagestyle/converters.js +79 -79
  70. package/src/imagestyle/imagestylecommand.d.ts +65 -65
  71. package/src/imagestyle/imagestylecommand.js +101 -101
  72. package/src/imagestyle/imagestyleediting.d.ts +50 -50
  73. package/src/imagestyle/imagestyleediting.js +108 -108
  74. package/src/imagestyle/imagestyleui.d.ts +56 -56
  75. package/src/imagestyle/imagestyleui.js +192 -192
  76. package/src/imagestyle/utils.d.ts +101 -101
  77. package/src/imagestyle/utils.js +329 -329
  78. package/src/imagestyle.d.ts +32 -32
  79. package/src/imagestyle.js +36 -36
  80. package/src/imagetextalternative/imagetextalternativecommand.d.ts +34 -34
  81. package/src/imagetextalternative/imagetextalternativecommand.js +44 -44
  82. package/src/imagetextalternative/imagetextalternativeediting.d.ts +28 -28
  83. package/src/imagetextalternative/imagetextalternativeediting.js +35 -35
  84. package/src/imagetextalternative/imagetextalternativeui.d.ts +68 -68
  85. package/src/imagetextalternative/imagetextalternativeui.js +173 -173
  86. package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -72
  87. package/src/imagetextalternative/ui/textalternativeformview.js +121 -121
  88. package/src/imagetextalternative.d.ts +29 -29
  89. package/src/imagetextalternative.js +33 -33
  90. package/src/imagetoolbar.d.ts +35 -35
  91. package/src/imagetoolbar.js +57 -57
  92. package/src/imageupload/imageuploadediting.d.ts +111 -111
  93. package/src/imageupload/imageuploadediting.js +335 -335
  94. package/src/imageupload/imageuploadprogress.d.ts +42 -42
  95. package/src/imageupload/imageuploadprogress.js +211 -211
  96. package/src/imageupload/imageuploadui.d.ts +23 -23
  97. package/src/imageupload/imageuploadui.js +57 -57
  98. package/src/imageupload/uploadimagecommand.d.ts +60 -60
  99. package/src/imageupload/uploadimagecommand.js +100 -100
  100. package/src/imageupload/utils.d.ts +33 -33
  101. package/src/imageupload/utils.js +112 -112
  102. package/src/imageupload.d.ts +32 -32
  103. package/src/imageupload.js +36 -36
  104. package/src/imageutils.d.ts +102 -102
  105. package/src/imageutils.js +248 -248
  106. package/src/index.d.ts +47 -47
  107. package/src/index.js +38 -38
  108. package/src/pictureediting.d.ts +88 -88
  109. package/src/pictureediting.js +130 -130
@@ -1,114 +1,114 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import { Plugin } from 'ckeditor5/src/core';
6
- import ImageUtils from '../imageutils';
7
- import ResizeImageCommand from './resizeimagecommand';
8
- /**
9
- * The image resize editing feature.
10
- *
11
- * It adds the ability to resize each image using handles or manually by
12
- * {@link module:image/imageresize/imageresizebuttons~ImageResizeButtons} buttons.
13
- */
14
- export default class ImageResizeEditing extends Plugin {
15
- /**
16
- * @inheritDoc
17
- */
18
- static get requires() {
19
- return [ImageUtils];
20
- }
21
- /**
22
- * @inheritDoc
23
- */
24
- static get pluginName() {
25
- return 'ImageResizeEditing';
26
- }
27
- /**
28
- * @inheritDoc
29
- */
30
- constructor(editor) {
31
- super(editor);
32
- editor.config.define('image', {
33
- resizeUnit: '%',
34
- resizeOptions: [{
35
- name: 'resizeImage:original',
36
- value: null,
37
- icon: 'original'
38
- },
39
- {
40
- name: 'resizeImage:25',
41
- value: '25',
42
- icon: 'small'
43
- },
44
- {
45
- name: 'resizeImage:50',
46
- value: '50',
47
- icon: 'medium'
48
- },
49
- {
50
- name: 'resizeImage:75',
51
- value: '75',
52
- icon: 'large'
53
- }]
54
- });
55
- }
56
- /**
57
- * @inheritDoc
58
- */
59
- init() {
60
- const editor = this.editor;
61
- const resizeImageCommand = new ResizeImageCommand(editor);
62
- this._registerSchema();
63
- this._registerConverters('imageBlock');
64
- this._registerConverters('imageInline');
65
- // Register `resizeImage` command and add `imageResize` command as an alias for backward compatibility.
66
- editor.commands.add('resizeImage', resizeImageCommand);
67
- editor.commands.add('imageResize', resizeImageCommand);
68
- }
69
- _registerSchema() {
70
- if (this.editor.plugins.has('ImageBlockEditing')) {
71
- this.editor.model.schema.extend('imageBlock', { allowAttributes: 'width' });
72
- }
73
- if (this.editor.plugins.has('ImageInlineEditing')) {
74
- this.editor.model.schema.extend('imageInline', { allowAttributes: 'width' });
75
- }
76
- }
77
- /**
78
- * Registers image resize converters.
79
- *
80
- * @param imageType The type of the image.
81
- */
82
- _registerConverters(imageType) {
83
- const editor = this.editor;
84
- // Dedicated converter to propagate image's attribute to the img tag.
85
- editor.conversion.for('downcast').add(dispatcher => dispatcher.on(`attribute:width:${imageType}`, (evt, data, conversionApi) => {
86
- if (!conversionApi.consumable.consume(data.item, evt.name)) {
87
- return;
88
- }
89
- const viewWriter = conversionApi.writer;
90
- const figure = conversionApi.mapper.toViewElement(data.item);
91
- if (data.attributeNewValue !== null) {
92
- viewWriter.setStyle('width', data.attributeNewValue, figure);
93
- viewWriter.addClass('image_resized', figure);
94
- }
95
- else {
96
- viewWriter.removeStyle('width', figure);
97
- viewWriter.removeClass('image_resized', figure);
98
- }
99
- }));
100
- editor.conversion.for('upcast')
101
- .attributeToAttribute({
102
- view: {
103
- name: imageType === 'imageBlock' ? 'figure' : 'img',
104
- styles: {
105
- width: /.+/
106
- }
107
- },
108
- model: {
109
- key: 'width',
110
- value: (viewElement) => viewElement.getStyle('width')
111
- }
112
- });
113
- }
114
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import { Plugin } from 'ckeditor5/src/core';
6
+ import ImageUtils from '../imageutils';
7
+ import ResizeImageCommand from './resizeimagecommand';
8
+ /**
9
+ * The image resize editing feature.
10
+ *
11
+ * It adds the ability to resize each image using handles or manually by
12
+ * {@link module:image/imageresize/imageresizebuttons~ImageResizeButtons} buttons.
13
+ */
14
+ export default class ImageResizeEditing extends Plugin {
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ static get requires() {
19
+ return [ImageUtils];
20
+ }
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get pluginName() {
25
+ return 'ImageResizeEditing';
26
+ }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ constructor(editor) {
31
+ super(editor);
32
+ editor.config.define('image', {
33
+ resizeUnit: '%',
34
+ resizeOptions: [{
35
+ name: 'resizeImage:original',
36
+ value: null,
37
+ icon: 'original'
38
+ },
39
+ {
40
+ name: 'resizeImage:25',
41
+ value: '25',
42
+ icon: 'small'
43
+ },
44
+ {
45
+ name: 'resizeImage:50',
46
+ value: '50',
47
+ icon: 'medium'
48
+ },
49
+ {
50
+ name: 'resizeImage:75',
51
+ value: '75',
52
+ icon: 'large'
53
+ }]
54
+ });
55
+ }
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ init() {
60
+ const editor = this.editor;
61
+ const resizeImageCommand = new ResizeImageCommand(editor);
62
+ this._registerSchema();
63
+ this._registerConverters('imageBlock');
64
+ this._registerConverters('imageInline');
65
+ // Register `resizeImage` command and add `imageResize` command as an alias for backward compatibility.
66
+ editor.commands.add('resizeImage', resizeImageCommand);
67
+ editor.commands.add('imageResize', resizeImageCommand);
68
+ }
69
+ _registerSchema() {
70
+ if (this.editor.plugins.has('ImageBlockEditing')) {
71
+ this.editor.model.schema.extend('imageBlock', { allowAttributes: 'width' });
72
+ }
73
+ if (this.editor.plugins.has('ImageInlineEditing')) {
74
+ this.editor.model.schema.extend('imageInline', { allowAttributes: 'width' });
75
+ }
76
+ }
77
+ /**
78
+ * Registers image resize converters.
79
+ *
80
+ * @param imageType The type of the image.
81
+ */
82
+ _registerConverters(imageType) {
83
+ const editor = this.editor;
84
+ // Dedicated converter to propagate image's attribute to the img tag.
85
+ editor.conversion.for('downcast').add(dispatcher => dispatcher.on(`attribute:width:${imageType}`, (evt, data, conversionApi) => {
86
+ if (!conversionApi.consumable.consume(data.item, evt.name)) {
87
+ return;
88
+ }
89
+ const viewWriter = conversionApi.writer;
90
+ const figure = conversionApi.mapper.toViewElement(data.item);
91
+ if (data.attributeNewValue !== null) {
92
+ viewWriter.setStyle('width', data.attributeNewValue, figure);
93
+ viewWriter.addClass('image_resized', figure);
94
+ }
95
+ else {
96
+ viewWriter.removeStyle('width', figure);
97
+ viewWriter.removeClass('image_resized', figure);
98
+ }
99
+ }));
100
+ editor.conversion.for('upcast')
101
+ .attributeToAttribute({
102
+ view: {
103
+ name: imageType === 'imageBlock' ? 'figure' : 'img',
104
+ styles: {
105
+ width: /.+/
106
+ }
107
+ },
108
+ model: {
109
+ key: 'width',
110
+ value: (viewElement) => viewElement.getStyle('width')
111
+ }
112
+ });
113
+ }
114
+ }
@@ -1,30 +1,30 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import { Plugin } from 'ckeditor5/src/core';
6
- import { WidgetResize } from 'ckeditor5/src/widget';
7
- /**
8
- * The image resize by handles feature.
9
- *
10
- * It adds the ability to resize each image using handles or manually by
11
- * {@link module:image/imageresize/imageresizebuttons~ImageResizeButtons} buttons.
12
- */
13
- export default class ImageResizeHandles extends Plugin {
14
- /**
15
- * @inheritDoc
16
- */
17
- static get requires(): readonly [typeof WidgetResize];
18
- /**
19
- * @inheritDoc
20
- */
21
- static get pluginName(): 'ImageResizeHandles';
22
- /**
23
- * @inheritDoc
24
- */
25
- init(): void;
26
- /**
27
- * Attaches the listeners responsible for creating a resizer for each image, except for images inside the HTML embed preview.
28
- */
29
- private _setupResizerCreator;
30
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import { Plugin } from 'ckeditor5/src/core';
6
+ import { WidgetResize } from 'ckeditor5/src/widget';
7
+ /**
8
+ * The image resize by handles feature.
9
+ *
10
+ * It adds the ability to resize each image using handles or manually by
11
+ * {@link module:image/imageresize/imageresizebuttons~ImageResizeButtons} buttons.
12
+ */
13
+ export default class ImageResizeHandles extends Plugin {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get requires(): readonly [typeof WidgetResize];
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get pluginName(): "ImageResizeHandles";
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ init(): void;
26
+ /**
27
+ * Attaches the listeners responsible for creating a resizer for each image, except for images inside the HTML embed preview.
28
+ */
29
+ private _setupResizerCreator;
30
+ }
@@ -1,107 +1,107 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import { Plugin } from 'ckeditor5/src/core';
6
- import { WidgetResize } from 'ckeditor5/src/widget';
7
- import ImageLoadObserver from '../image/imageloadobserver';
8
- const RESIZABLE_IMAGES_CSS_SELECTOR = 'figure.image.ck-widget > img,' +
9
- 'figure.image.ck-widget > picture > img,' +
10
- 'figure.image.ck-widget > a > img,' +
11
- 'figure.image.ck-widget > a > picture > img,' +
12
- 'span.image-inline.ck-widget > img,' +
13
- 'span.image-inline.ck-widget > picture > img';
14
- const IMAGE_WIDGETS_CLASSES_MATCH_REGEXP = /(image|image-inline)/;
15
- const RESIZED_IMAGE_CLASS = 'image_resized';
16
- /**
17
- * The image resize by handles feature.
18
- *
19
- * It adds the ability to resize each image using handles or manually by
20
- * {@link module:image/imageresize/imageresizebuttons~ImageResizeButtons} buttons.
21
- */
22
- export default class ImageResizeHandles extends Plugin {
23
- /**
24
- * @inheritDoc
25
- */
26
- static get requires() {
27
- return [WidgetResize];
28
- }
29
- /**
30
- * @inheritDoc
31
- */
32
- static get pluginName() {
33
- return 'ImageResizeHandles';
34
- }
35
- /**
36
- * @inheritDoc
37
- */
38
- init() {
39
- const command = this.editor.commands.get('resizeImage');
40
- this.bind('isEnabled').to(command);
41
- this._setupResizerCreator();
42
- }
43
- /**
44
- * Attaches the listeners responsible for creating a resizer for each image, except for images inside the HTML embed preview.
45
- */
46
- _setupResizerCreator() {
47
- const editor = this.editor;
48
- const editingView = editor.editing.view;
49
- editingView.addObserver(ImageLoadObserver);
50
- this.listenTo(editingView.document, 'imageLoaded', (evt, domEvent) => {
51
- // The resizer must be attached only to images loaded by the `ImageInsert`, `ImageUpload` or `LinkImage` plugins.
52
- if (!domEvent.target.matches(RESIZABLE_IMAGES_CSS_SELECTOR)) {
53
- return;
54
- }
55
- const domConverter = editor.editing.view.domConverter;
56
- const imageView = domConverter.domToView(domEvent.target);
57
- const widgetView = imageView.findAncestor({ classes: IMAGE_WIDGETS_CLASSES_MATCH_REGEXP });
58
- let resizer = this.editor.plugins.get(WidgetResize).getResizerByViewElement(widgetView);
59
- if (resizer) {
60
- // There are rare cases when the image will be triggered multiple times for the same widget, e.g. when
61
- // the image's source was changed after upload (https://github.com/ckeditor/ckeditor5/pull/8108#issuecomment-708302992).
62
- resizer.redraw();
63
- return;
64
- }
65
- const mapper = editor.editing.mapper;
66
- const imageModel = mapper.toModelElement(widgetView);
67
- resizer = editor.plugins
68
- .get(WidgetResize)
69
- .attachTo({
70
- unit: editor.config.get('image.resizeUnit'),
71
- modelElement: imageModel,
72
- viewElement: widgetView,
73
- editor,
74
- getHandleHost(domWidgetElement) {
75
- return domWidgetElement.querySelector('img');
76
- },
77
- getResizeHost() {
78
- // Return the model image element parent to avoid setting an inline element (<a>/<span>) as a resize host.
79
- return domConverter.mapViewToDom(mapper.toViewElement(imageModel.parent));
80
- },
81
- // TODO consider other positions.
82
- isCentered() {
83
- const imageStyle = imageModel.getAttribute('imageStyle');
84
- return !imageStyle || imageStyle == 'block' || imageStyle == 'alignCenter';
85
- },
86
- onCommit(newValue) {
87
- // Get rid of the CSS class in case the command execution that follows is unsuccessful
88
- // (e.g. Track Changes can override it and the new dimensions will not apply). Otherwise,
89
- // the presence of the class and the absence of the width style will cause it to take 100%
90
- // of the horizontal space.
91
- editingView.change(writer => {
92
- writer.removeClass(RESIZED_IMAGE_CLASS, widgetView);
93
- });
94
- editor.execute('resizeImage', { width: newValue });
95
- }
96
- });
97
- resizer.on('updateSize', () => {
98
- if (!widgetView.hasClass(RESIZED_IMAGE_CLASS)) {
99
- editingView.change(writer => {
100
- writer.addClass(RESIZED_IMAGE_CLASS, widgetView);
101
- });
102
- }
103
- });
104
- resizer.bind('isEnabled').to(this);
105
- });
106
- }
107
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import { Plugin } from 'ckeditor5/src/core';
6
+ import { WidgetResize } from 'ckeditor5/src/widget';
7
+ import ImageLoadObserver from '../image/imageloadobserver';
8
+ const RESIZABLE_IMAGES_CSS_SELECTOR = 'figure.image.ck-widget > img,' +
9
+ 'figure.image.ck-widget > picture > img,' +
10
+ 'figure.image.ck-widget > a > img,' +
11
+ 'figure.image.ck-widget > a > picture > img,' +
12
+ 'span.image-inline.ck-widget > img,' +
13
+ 'span.image-inline.ck-widget > picture > img';
14
+ const IMAGE_WIDGETS_CLASSES_MATCH_REGEXP = /(image|image-inline)/;
15
+ const RESIZED_IMAGE_CLASS = 'image_resized';
16
+ /**
17
+ * The image resize by handles feature.
18
+ *
19
+ * It adds the ability to resize each image using handles or manually by
20
+ * {@link module:image/imageresize/imageresizebuttons~ImageResizeButtons} buttons.
21
+ */
22
+ export default class ImageResizeHandles extends Plugin {
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get requires() {
27
+ return [WidgetResize];
28
+ }
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get pluginName() {
33
+ return 'ImageResizeHandles';
34
+ }
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ init() {
39
+ const command = this.editor.commands.get('resizeImage');
40
+ this.bind('isEnabled').to(command);
41
+ this._setupResizerCreator();
42
+ }
43
+ /**
44
+ * Attaches the listeners responsible for creating a resizer for each image, except for images inside the HTML embed preview.
45
+ */
46
+ _setupResizerCreator() {
47
+ const editor = this.editor;
48
+ const editingView = editor.editing.view;
49
+ editingView.addObserver(ImageLoadObserver);
50
+ this.listenTo(editingView.document, 'imageLoaded', (evt, domEvent) => {
51
+ // The resizer must be attached only to images loaded by the `ImageInsert`, `ImageUpload` or `LinkImage` plugins.
52
+ if (!domEvent.target.matches(RESIZABLE_IMAGES_CSS_SELECTOR)) {
53
+ return;
54
+ }
55
+ const domConverter = editor.editing.view.domConverter;
56
+ const imageView = domConverter.domToView(domEvent.target);
57
+ const widgetView = imageView.findAncestor({ classes: IMAGE_WIDGETS_CLASSES_MATCH_REGEXP });
58
+ let resizer = this.editor.plugins.get(WidgetResize).getResizerByViewElement(widgetView);
59
+ if (resizer) {
60
+ // There are rare cases when the image will be triggered multiple times for the same widget, e.g. when
61
+ // the image's source was changed after upload (https://github.com/ckeditor/ckeditor5/pull/8108#issuecomment-708302992).
62
+ resizer.redraw();
63
+ return;
64
+ }
65
+ const mapper = editor.editing.mapper;
66
+ const imageModel = mapper.toModelElement(widgetView);
67
+ resizer = editor.plugins
68
+ .get(WidgetResize)
69
+ .attachTo({
70
+ unit: editor.config.get('image.resizeUnit'),
71
+ modelElement: imageModel,
72
+ viewElement: widgetView,
73
+ editor,
74
+ getHandleHost(domWidgetElement) {
75
+ return domWidgetElement.querySelector('img');
76
+ },
77
+ getResizeHost() {
78
+ // Return the model image element parent to avoid setting an inline element (<a>/<span>) as a resize host.
79
+ return domConverter.mapViewToDom(mapper.toViewElement(imageModel.parent));
80
+ },
81
+ // TODO consider other positions.
82
+ isCentered() {
83
+ const imageStyle = imageModel.getAttribute('imageStyle');
84
+ return !imageStyle || imageStyle == 'block' || imageStyle == 'alignCenter';
85
+ },
86
+ onCommit(newValue) {
87
+ // Get rid of the CSS class in case the command execution that follows is unsuccessful
88
+ // (e.g. Track Changes can override it and the new dimensions will not apply). Otherwise,
89
+ // the presence of the class and the absence of the width style will cause it to take 100%
90
+ // of the horizontal space.
91
+ editingView.change(writer => {
92
+ writer.removeClass(RESIZED_IMAGE_CLASS, widgetView);
93
+ });
94
+ editor.execute('resizeImage', { width: newValue });
95
+ }
96
+ });
97
+ resizer.on('updateSize', () => {
98
+ if (!widgetView.hasClass(RESIZED_IMAGE_CLASS)) {
99
+ editingView.change(writer => {
100
+ writer.addClass(RESIZED_IMAGE_CLASS, widgetView);
101
+ });
102
+ }
103
+ });
104
+ resizer.bind('isEnabled').to(this);
105
+ });
106
+ }
107
+ }
@@ -1,42 +1,42 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module image/imageresize/resizeimagecommand
7
- */
8
- import { Command } from 'ckeditor5/src/core';
9
- /**
10
- * The resize image command. Currently, it only supports the width attribute.
11
- */
12
- export default class ResizeImageCommand extends Command {
13
- /**
14
- * Desired image width and height.
15
- */
16
- value: null | {
17
- width: string | null;
18
- height: string | null;
19
- };
20
- /**
21
- * @inheritDoc
22
- */
23
- refresh(): void;
24
- /**
25
- * Executes the command.
26
- *
27
- * ```ts
28
- * // Sets the width to 50%:
29
- * editor.execute( 'resizeImage', { width: '50%' } );
30
- *
31
- * // Removes the width attribute:
32
- * editor.execute( 'resizeImage', { width: null } );
33
- * ```
34
- *
35
- * @param options
36
- * @param options.width The new width of the image.
37
- * @fires execute
38
- */
39
- execute(options: {
40
- width: string | null;
41
- }): void;
42
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module image/imageresize/resizeimagecommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ /**
10
+ * The resize image command. Currently, it only supports the width attribute.
11
+ */
12
+ export default class ResizeImageCommand extends Command {
13
+ /**
14
+ * Desired image width and height.
15
+ */
16
+ value: null | {
17
+ width: string | null;
18
+ height: string | null;
19
+ };
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ refresh(): void;
24
+ /**
25
+ * Executes the command.
26
+ *
27
+ * ```ts
28
+ * // Sets the width to 50%:
29
+ * editor.execute( 'resizeImage', { width: '50%' } );
30
+ *
31
+ * // Removes the width attribute:
32
+ * editor.execute( 'resizeImage', { width: null } );
33
+ * ```
34
+ *
35
+ * @param options
36
+ * @param options.width The new width of the image.
37
+ * @fires execute
38
+ */
39
+ execute(options: {
40
+ width: string | null;
41
+ }): void;
42
+ }