@ckeditor/ckeditor5-image 47.6.1 → 48.0.0-alpha.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.
- package/LICENSE.md +1 -1
- package/ckeditor5-metadata.json +25 -25
- package/{src → dist}/autoimage.d.ts +4 -4
- package/{src → dist}/image/converters.d.ts +1 -1
- package/{src → dist}/image/imageblockediting.d.ts +2 -2
- package/{src → dist}/image/imageediting.d.ts +1 -1
- package/{src → dist}/image/imageinlineediting.d.ts +2 -2
- package/{src → dist}/image/imageloadobserver.d.ts +1 -1
- package/{src → dist}/image/imageplaceholder.d.ts +1 -1
- package/{src → dist}/image/imagetypecommand.d.ts +2 -2
- package/{src → dist}/image/insertimagecommand.d.ts +2 -2
- package/{src → dist}/image/replaceimagesourcecommand.d.ts +2 -2
- package/{src → dist}/image/ui/utils.d.ts +2 -2
- package/{src → dist}/image/utils.d.ts +2 -2
- package/{src → dist}/image.d.ts +1 -1
- package/{src → dist}/imageblock.d.ts +2 -2
- package/{src → dist}/imagecaption/imagecaptionediting.d.ts +2 -2
- package/{src → dist}/imagecaption/imagecaptionui.d.ts +1 -1
- package/{src → dist}/imagecaption/imagecaptionutils.d.ts +2 -2
- package/{src → dist}/imagecaption/toggleimagecaptioncommand.d.ts +1 -1
- package/{src → dist}/imagecaption.d.ts +1 -1
- package/{src → dist}/imageconfig.d.ts +25 -16
- package/{src → dist}/imageinline.d.ts +2 -2
- package/{src → dist}/imageinsert/imageinsertui.d.ts +3 -3
- package/{src → dist}/imageinsert/imageinsertviaurlui.d.ts +2 -2
- package/{src → dist}/imageinsert/ui/imageinsertformview.d.ts +2 -2
- package/{src → dist}/imageinsert/ui/imageinserturlview.d.ts +2 -2
- package/{src → dist}/imageinsert.d.ts +1 -1
- package/{src → dist}/imageinsertviaurl.d.ts +1 -1
- package/{src → dist}/imageresize/imagecustomresizeui.d.ts +2 -2
- package/{src → dist}/imageresize/imageresizebuttons.d.ts +1 -1
- package/{src → dist}/imageresize/imageresizeediting.d.ts +1 -1
- package/{src → dist}/imageresize/imageresizehandles.d.ts +2 -2
- package/{src → dist}/imageresize/resizeimagecommand.d.ts +1 -1
- package/{src → dist}/imageresize/ui/imagecustomresizeformview.d.ts +2 -4
- package/{src → dist}/imageresize/utils/getselectedimageeditornodes.d.ts +2 -2
- package/{src → dist}/imageresize/utils/getselectedimagepossibleresizerange.d.ts +1 -1
- package/{src → dist}/imageresize/utils/getselectedimagewidthinunits.d.ts +1 -1
- package/{src → dist}/imageresize.d.ts +1 -1
- package/{src → dist}/imagesizeattributes.d.ts +1 -1
- package/{src → dist}/imagestyle/converters.d.ts +2 -2
- package/{src → dist}/imagestyle/imagestylecommand.d.ts +2 -2
- package/{src → dist}/imagestyle/imagestyleediting.d.ts +1 -1
- package/{src → dist}/imagestyle/imagestyleui.d.ts +1 -1
- package/{src → dist}/imagestyle/utils.d.ts +1 -1
- package/{src → dist}/imagestyle.d.ts +1 -1
- package/{src → dist}/imagetextalternative/imagetextalternativecommand.d.ts +1 -1
- package/{src → dist}/imagetextalternative/imagetextalternativeediting.d.ts +1 -1
- package/{src → dist}/imagetextalternative/imagetextalternativeui.d.ts +2 -2
- package/{src → dist}/imagetextalternative/ui/textalternativeformview.d.ts +2 -4
- package/{src → dist}/imagetextalternative.d.ts +1 -1
- package/{src → dist}/imagetoolbar.d.ts +2 -2
- package/{src → dist}/imageupload/imageuploadediting.d.ts +5 -5
- package/{src → dist}/imageupload/imageuploadprogress.d.ts +1 -1
- package/{src → dist}/imageupload/imageuploadui.d.ts +1 -1
- package/{src → dist}/imageupload/uploadimagecommand.d.ts +2 -2
- package/{src → dist}/imageupload/utils.d.ts +1 -1
- package/{src → dist}/imageupload.d.ts +1 -1
- package/{src → dist}/imageutils.d.ts +2 -2
- package/dist/index-content.css +97 -100
- package/dist/index-editor.css +313 -190
- package/dist/index.css +388 -458
- package/dist/index.css.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/{src → dist}/pictureediting.d.ts +1 -1
- package/package.json +29 -53
- package/build/image.js +0 -5
- package/build/translations/af.js +0 -1
- package/build/translations/ar.js +0 -1
- package/build/translations/ast.js +0 -1
- package/build/translations/az.js +0 -1
- package/build/translations/be.js +0 -1
- package/build/translations/bg.js +0 -1
- package/build/translations/bn.js +0 -1
- package/build/translations/bs.js +0 -1
- package/build/translations/ca.js +0 -1
- package/build/translations/cs.js +0 -1
- package/build/translations/da.js +0 -1
- package/build/translations/de-ch.js +0 -1
- package/build/translations/de.js +0 -1
- package/build/translations/el.js +0 -1
- package/build/translations/en-au.js +0 -1
- package/build/translations/en-gb.js +0 -1
- package/build/translations/eo.js +0 -1
- package/build/translations/es-co.js +0 -1
- package/build/translations/es.js +0 -1
- package/build/translations/et.js +0 -1
- package/build/translations/eu.js +0 -1
- package/build/translations/fa.js +0 -1
- package/build/translations/fi.js +0 -1
- package/build/translations/fr.js +0 -1
- package/build/translations/gl.js +0 -1
- package/build/translations/gu.js +0 -1
- package/build/translations/he.js +0 -1
- package/build/translations/hi.js +0 -1
- package/build/translations/hr.js +0 -1
- package/build/translations/hu.js +0 -1
- package/build/translations/hy.js +0 -1
- package/build/translations/id.js +0 -1
- package/build/translations/it.js +0 -1
- package/build/translations/ja.js +0 -1
- package/build/translations/jv.js +0 -1
- package/build/translations/kk.js +0 -1
- package/build/translations/km.js +0 -1
- package/build/translations/kn.js +0 -1
- package/build/translations/ko.js +0 -1
- package/build/translations/ku.js +0 -1
- package/build/translations/lt.js +0 -1
- package/build/translations/lv.js +0 -1
- package/build/translations/ms.js +0 -1
- package/build/translations/nb.js +0 -1
- package/build/translations/ne.js +0 -1
- package/build/translations/nl.js +0 -1
- package/build/translations/no.js +0 -1
- package/build/translations/oc.js +0 -1
- package/build/translations/pl.js +0 -1
- package/build/translations/pt-br.js +0 -1
- package/build/translations/pt.js +0 -1
- package/build/translations/ro.js +0 -1
- package/build/translations/ru.js +0 -1
- package/build/translations/si.js +0 -1
- package/build/translations/sk.js +0 -1
- package/build/translations/sl.js +0 -1
- package/build/translations/sq.js +0 -1
- package/build/translations/sr-latn.js +0 -1
- package/build/translations/sr.js +0 -1
- package/build/translations/sv.js +0 -1
- package/build/translations/th.js +0 -1
- package/build/translations/ti.js +0 -1
- package/build/translations/tk.js +0 -1
- package/build/translations/tr.js +0 -1
- package/build/translations/tt.js +0 -1
- package/build/translations/ug.js +0 -1
- package/build/translations/uk.js +0 -1
- package/build/translations/ur.js +0 -1
- package/build/translations/uz.js +0 -1
- package/build/translations/vi.js +0 -1
- package/build/translations/zh-cn.js +0 -1
- package/build/translations/zh.js +0 -1
- package/lang/contexts.json +0 -48
- package/lang/translations/af.po +0 -196
- package/lang/translations/ar.po +0 -196
- package/lang/translations/ast.po +0 -196
- package/lang/translations/az.po +0 -196
- package/lang/translations/be.po +0 -196
- package/lang/translations/bg.po +0 -196
- package/lang/translations/bn.po +0 -196
- package/lang/translations/bs.po +0 -196
- package/lang/translations/ca.po +0 -196
- package/lang/translations/cs.po +0 -196
- package/lang/translations/da.po +0 -196
- package/lang/translations/de-ch.po +0 -196
- package/lang/translations/de.po +0 -196
- package/lang/translations/el.po +0 -196
- package/lang/translations/en-au.po +0 -196
- package/lang/translations/en-gb.po +0 -196
- package/lang/translations/en.po +0 -196
- package/lang/translations/eo.po +0 -196
- package/lang/translations/es-co.po +0 -196
- package/lang/translations/es.po +0 -196
- package/lang/translations/et.po +0 -196
- package/lang/translations/eu.po +0 -196
- package/lang/translations/fa.po +0 -196
- package/lang/translations/fi.po +0 -196
- package/lang/translations/fr.po +0 -196
- package/lang/translations/gl.po +0 -196
- package/lang/translations/gu.po +0 -196
- package/lang/translations/he.po +0 -196
- package/lang/translations/hi.po +0 -196
- package/lang/translations/hr.po +0 -196
- package/lang/translations/hu.po +0 -196
- package/lang/translations/hy.po +0 -196
- package/lang/translations/id.po +0 -196
- package/lang/translations/it.po +0 -196
- package/lang/translations/ja.po +0 -196
- package/lang/translations/jv.po +0 -196
- package/lang/translations/kk.po +0 -196
- package/lang/translations/km.po +0 -196
- package/lang/translations/kn.po +0 -196
- package/lang/translations/ko.po +0 -196
- package/lang/translations/ku.po +0 -196
- package/lang/translations/lt.po +0 -196
- package/lang/translations/lv.po +0 -196
- package/lang/translations/ms.po +0 -196
- package/lang/translations/nb.po +0 -196
- package/lang/translations/ne.po +0 -196
- package/lang/translations/nl.po +0 -196
- package/lang/translations/no.po +0 -196
- package/lang/translations/oc.po +0 -196
- package/lang/translations/pl.po +0 -196
- package/lang/translations/pt-br.po +0 -196
- package/lang/translations/pt.po +0 -196
- package/lang/translations/ro.po +0 -196
- package/lang/translations/ru.po +0 -196
- package/lang/translations/si.po +0 -196
- package/lang/translations/sk.po +0 -196
- package/lang/translations/sl.po +0 -196
- package/lang/translations/sq.po +0 -196
- package/lang/translations/sr-latn.po +0 -196
- package/lang/translations/sr.po +0 -196
- package/lang/translations/sv.po +0 -196
- package/lang/translations/th.po +0 -196
- package/lang/translations/ti.po +0 -196
- package/lang/translations/tk.po +0 -196
- package/lang/translations/tr.po +0 -196
- package/lang/translations/tt.po +0 -196
- package/lang/translations/ug.po +0 -196
- package/lang/translations/uk.po +0 -196
- package/lang/translations/ur.po +0 -196
- package/lang/translations/uz.po +0 -196
- package/lang/translations/vi.po +0 -196
- package/lang/translations/zh-cn.po +0 -196
- package/lang/translations/zh.po +0 -196
- package/src/augmentation.js +0 -5
- package/src/autoimage.js +0 -148
- package/src/image/converters.js +0 -236
- package/src/image/imageblockediting.js +0 -159
- package/src/image/imageediting.js +0 -69
- package/src/image/imageinlineediting.js +0 -178
- package/src/image/imageloadobserver.js +0 -52
- package/src/image/imageplaceholder.js +0 -119
- package/src/image/imagetypecommand.js +0 -84
- package/src/image/insertimagecommand.js +0 -125
- package/src/image/replaceimagesourcecommand.js +0 -75
- package/src/image/ui/utils.js +0 -46
- package/src/image/utils.js +0 -125
- package/src/image.js +0 -44
- package/src/imageblock.js +0 -44
- package/src/imagecaption/imagecaptionediting.js +0 -238
- package/src/imagecaption/imagecaptionui.js +0 -68
- package/src/imagecaption/imagecaptionutils.js +0 -68
- package/src/imagecaption/toggleimagecaptioncommand.js +0 -138
- package/src/imagecaption.js +0 -36
- package/src/imageconfig.js +0 -5
- package/src/imageinline.js +0 -44
- package/src/imageinsert/imageinsertui.js +0 -216
- package/src/imageinsert/imageinsertviaurlui.js +0 -175
- package/src/imageinsert/ui/imageinsertformview.js +0 -117
- package/src/imageinsert/ui/imageinserturlview.js +0 -102
- package/src/imageinsert.js +0 -43
- package/src/imageinsertviaurl.js +0 -41
- package/src/imageresize/imagecustomresizeui.js +0 -177
- package/src/imageresize/imageresizebuttons.js +0 -303
- package/src/imageresize/imageresizeediting.js +0 -206
- package/src/imageresize/imageresizehandles.js +0 -118
- package/src/imageresize/resizeimagecommand.js +0 -63
- package/src/imageresize/ui/imagecustomresizeformview.js +0 -264
- package/src/imageresize/utils/getselectedimageeditornodes.js +0 -25
- package/src/imageresize/utils/getselectedimagepossibleresizerange.js +0 -33
- package/src/imageresize/utils/getselectedimagewidthinunits.js +0 -42
- package/src/imageresize/utils/tryparsedimensionwithunit.js +0 -58
- package/src/imageresize.js +0 -38
- package/src/imagesizeattributes.js +0 -163
- package/src/imagestyle/converters.js +0 -118
- package/src/imagestyle/imagestylecommand.js +0 -117
- package/src/imagestyle/imagestyleediting.js +0 -127
- package/src/imagestyle/imagestyleui.js +0 -198
- package/src/imagestyle/utils.js +0 -333
- package/src/imagestyle.js +0 -42
- package/src/imagetextalternative/imagetextalternativecommand.js +0 -44
- package/src/imagetextalternative/imagetextalternativeediting.js +0 -41
- package/src/imagetextalternative/imagetextalternativeui.js +0 -183
- package/src/imagetextalternative/ui/textalternativeformview.js +0 -193
- package/src/imagetextalternative.js +0 -39
- package/src/imagetoolbar.js +0 -63
- package/src/imageupload/imageuploadediting.js +0 -482
- package/src/imageupload/imageuploadprogress.js +0 -222
- package/src/imageupload/imageuploadui.js +0 -135
- package/src/imageupload/uploadimagecommand.js +0 -110
- package/src/imageupload/utils.js +0 -114
- package/src/imageupload.js +0 -42
- package/src/imageutils.js +0 -309
- package/src/index.js +0 -67
- package/src/pictureediting.js +0 -136
- package/theme/image.css +0 -143
- package/theme/imagecaption.css +0 -53
- package/theme/imagecustomresizeform.css +0 -4
- package/theme/imageinsert.css +0 -14
- package/theme/imageplaceholder.css +0 -10
- package/theme/imageresize.css +0 -53
- package/theme/imagestyle.css +0 -120
- package/theme/imageuploadicon.css +0 -23
- package/theme/imageuploadloader.css +0 -18
- package/theme/imageuploadprogress.css +0 -19
- package/theme/textalternativeform.css +0 -4
- /package/{src → dist}/augmentation.d.ts +0 -0
- /package/{src → dist}/imageresize/utils/tryparsedimensionwithunit.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module image/imagesizeattributes
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { ImageUtils } from './imageutils.js';
|
|
10
|
-
import { widthAndHeightStylesAreBothSet, getSizeValueIfInPx } from './image/utils.js';
|
|
11
|
-
/**
|
|
12
|
-
* This plugin enables `width` and `height` attributes in inline and block image elements.
|
|
13
|
-
*/
|
|
14
|
-
export class ImageSizeAttributes extends Plugin {
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
18
|
-
static get requires() {
|
|
19
|
-
return [ImageUtils];
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @inheritDoc
|
|
23
|
-
*/
|
|
24
|
-
static get pluginName() {
|
|
25
|
-
return 'ImageSizeAttributes';
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @inheritDoc
|
|
29
|
-
*/
|
|
30
|
-
static get isOfficialPlugin() {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* @inheritDoc
|
|
35
|
-
*/
|
|
36
|
-
afterInit() {
|
|
37
|
-
this._registerSchema();
|
|
38
|
-
this._registerConverters('imageBlock');
|
|
39
|
-
this._registerConverters('imageInline');
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Registers the `width` and `height` attributes for inline and block images.
|
|
43
|
-
*/
|
|
44
|
-
_registerSchema() {
|
|
45
|
-
const schema = this.editor.model.schema;
|
|
46
|
-
if (this.editor.plugins.has('ImageBlockEditing')) {
|
|
47
|
-
schema.extend('imageBlock', { allowAttributes: ['width', 'height'] });
|
|
48
|
-
}
|
|
49
|
-
if (this.editor.plugins.has('ImageInlineEditing')) {
|
|
50
|
-
schema.extend('imageInline', { allowAttributes: ['width', 'height'] });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Registers converters for `width` and `height` attributes.
|
|
55
|
-
*/
|
|
56
|
-
_registerConverters(imageType) {
|
|
57
|
-
const editor = this.editor;
|
|
58
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
59
|
-
const viewElementName = imageType === 'imageBlock' ? 'figure' : 'img';
|
|
60
|
-
editor.conversion.for('upcast')
|
|
61
|
-
.attributeToAttribute({
|
|
62
|
-
view: {
|
|
63
|
-
name: viewElementName,
|
|
64
|
-
styles: {
|
|
65
|
-
width: /.+/
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
model: {
|
|
69
|
-
key: 'width',
|
|
70
|
-
value: (viewElement) => {
|
|
71
|
-
if (widthAndHeightStylesAreBothSet(viewElement)) {
|
|
72
|
-
return getSizeValueIfInPx(viewElement.getStyle('width'));
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
.attributeToAttribute({
|
|
79
|
-
view: {
|
|
80
|
-
name: viewElementName,
|
|
81
|
-
key: 'width'
|
|
82
|
-
},
|
|
83
|
-
model: 'width'
|
|
84
|
-
})
|
|
85
|
-
.attributeToAttribute({
|
|
86
|
-
view: {
|
|
87
|
-
name: viewElementName,
|
|
88
|
-
styles: {
|
|
89
|
-
height: /.+/
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
model: {
|
|
93
|
-
key: 'height',
|
|
94
|
-
value: (viewElement) => {
|
|
95
|
-
if (widthAndHeightStylesAreBothSet(viewElement)) {
|
|
96
|
-
return getSizeValueIfInPx(viewElement.getStyle('height'));
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
})
|
|
102
|
-
.attributeToAttribute({
|
|
103
|
-
view: {
|
|
104
|
-
name: viewElementName,
|
|
105
|
-
key: 'height'
|
|
106
|
-
},
|
|
107
|
-
model: 'height'
|
|
108
|
-
});
|
|
109
|
-
// Dedicated converters to propagate attributes to the <img> element.
|
|
110
|
-
editor.conversion.for('editingDowncast').add(dispatcher => {
|
|
111
|
-
attachDowncastConverter(dispatcher, 'width', 'width', true, true);
|
|
112
|
-
attachDowncastConverter(dispatcher, 'height', 'height', true, true);
|
|
113
|
-
});
|
|
114
|
-
editor.conversion.for('dataDowncast').add(dispatcher => {
|
|
115
|
-
attachDowncastConverter(dispatcher, 'width', 'width', false);
|
|
116
|
-
attachDowncastConverter(dispatcher, 'height', 'height', false);
|
|
117
|
-
});
|
|
118
|
-
// Consume `aspect-ratio` style if `width` and `height` attributes are set on the image.
|
|
119
|
-
editor.conversion.for('upcast').add(dispatcher => {
|
|
120
|
-
dispatcher.on('element:img', (evt, data, conversionApi) => {
|
|
121
|
-
const width = data.viewItem.getAttribute('width');
|
|
122
|
-
const height = data.viewItem.getAttribute('height');
|
|
123
|
-
if (width && height) {
|
|
124
|
-
conversionApi.consumable.consume(data.viewItem, { styles: ['aspect-ratio'] });
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
function attachDowncastConverter(dispatcher, modelAttributeName, viewAttributeName, setRatioForInlineImage, isEditingDowncast = false) {
|
|
129
|
-
dispatcher.on(`attribute:${modelAttributeName}:${imageType}`, (evt, data, conversionApi) => {
|
|
130
|
-
if (!conversionApi.consumable.consume(data.item, evt.name)) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const viewWriter = conversionApi.writer;
|
|
134
|
-
const viewElement = conversionApi.mapper.toViewElement(data.item);
|
|
135
|
-
const img = imageUtils.findViewImgElement(viewElement);
|
|
136
|
-
if (data.attributeNewValue !== null) {
|
|
137
|
-
viewWriter.setAttribute(viewAttributeName, data.attributeNewValue, img);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
viewWriter.removeAttribute(viewAttributeName, img);
|
|
141
|
-
}
|
|
142
|
-
const width = data.item.getAttribute('width');
|
|
143
|
-
const height = data.item.getAttribute('height');
|
|
144
|
-
const hasSizes = width && height;
|
|
145
|
-
if (hasSizes && isEditingDowncast) {
|
|
146
|
-
viewWriter.setAttribute('loading', 'lazy', img);
|
|
147
|
-
}
|
|
148
|
-
// Do not set aspect-ratio for pictures. See https://github.com/ckeditor/ckeditor5/issues/14579.
|
|
149
|
-
if (data.item.hasAttribute('sources')) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
const isResized = data.item.hasAttribute('resizedWidth');
|
|
153
|
-
// Do not set aspect ratio for inline images which are not resized (data pipeline).
|
|
154
|
-
if (imageType === 'imageInline' && !isResized && !setRatioForInlineImage) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (hasSizes) {
|
|
158
|
-
viewWriter.setStyle('aspect-ratio', `${width}/${height}`, img);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
import isEqual from 'es-toolkit/compat/isEqual';
|
|
6
|
-
import { first } from 'ckeditor5/src/utils.js';
|
|
7
|
-
import { DEFAULT_OPTIONS } from './utils.js';
|
|
8
|
-
/**
|
|
9
|
-
* @module image/imagestyle/converters
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Returns a converter for the `imageStyle` attribute. It can be used for adding, changing and removing the attribute.
|
|
13
|
-
*
|
|
14
|
-
* @param styles An array containing available image style options.
|
|
15
|
-
* @returns A model-to-view attribute converter.
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
export function modelToViewStyleAttribute(styles) {
|
|
19
|
-
return (evt, data, conversionApi) => {
|
|
20
|
-
if (!conversionApi.consumable.consume(data.item, evt.name)) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
// Check if there is class name associated with given value.
|
|
24
|
-
const newStyle = getStyleDefinitionByName(data.attributeNewValue, styles);
|
|
25
|
-
const oldStyle = getStyleDefinitionByName(data.attributeOldValue, styles);
|
|
26
|
-
const viewElement = conversionApi.mapper.toViewElement(data.item);
|
|
27
|
-
const viewWriter = conversionApi.writer;
|
|
28
|
-
if (oldStyle) {
|
|
29
|
-
viewWriter.removeClass(oldStyle.className, viewElement);
|
|
30
|
-
}
|
|
31
|
-
if (newStyle) {
|
|
32
|
-
viewWriter.addClass(newStyle.className, viewElement);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Returns a view-to-model converter converting image CSS classes to a proper value in the model.
|
|
38
|
-
*
|
|
39
|
-
* @param styles Image style options for which the converter is created.
|
|
40
|
-
* @returns A view-to-model converter.
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
export function viewToModelStyleAttribute(styles) {
|
|
44
|
-
// Convert only non–default styles.
|
|
45
|
-
const nonDefaultStyles = {
|
|
46
|
-
imageInline: styles.filter(style => !style.isDefault && style.modelElements.includes('imageInline')),
|
|
47
|
-
imageBlock: styles.filter(style => !style.isDefault && style.modelElements.includes('imageBlock'))
|
|
48
|
-
};
|
|
49
|
-
return (evt, data, conversionApi) => {
|
|
50
|
-
if (!data.modelRange) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const viewElement = data.viewItem;
|
|
54
|
-
const modelImageElement = first(data.modelRange.getItems());
|
|
55
|
-
// Run this converter only if an image has been found in the model.
|
|
56
|
-
// In some cases it may not be found (for example if we run this on a figure with different type than image).
|
|
57
|
-
if (!modelImageElement) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
// ...and the `imageStyle` attribute is allowed for that element, otherwise stop conversion early.
|
|
61
|
-
if (!conversionApi.schema.checkAttribute(modelImageElement, 'imageStyle')) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
// Convert styles one by one.
|
|
65
|
-
for (const style of nonDefaultStyles[modelImageElement.name]) {
|
|
66
|
-
// Try to consume class corresponding with the style.
|
|
67
|
-
if (conversionApi.consumable.consume(viewElement, { classes: style.className })) {
|
|
68
|
-
// And convert this style to model attribute.
|
|
69
|
-
conversionApi.writer.setAttribute('imageStyle', style.name, modelImageElement);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// Normalize float styles (alignLeft, alignRight).
|
|
73
|
-
normalizeFloatToDefinitionStyle(conversionApi, viewElement, modelImageElement, styles);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* A helper function that attempts to convert the `float` CSS style into a corresponding `imageStyle` attribute.
|
|
78
|
-
*
|
|
79
|
-
* It maps `float: left` and `float: right` to standard alignment styles (e.g. `'alignLeft'`, `'alignRight'`),
|
|
80
|
-
* but only if the target style definition matches one of the {@link module:image/image/utils~DEFAULT_OPTIONS default options}.
|
|
81
|
-
*/
|
|
82
|
-
function normalizeFloatToDefinitionStyle(conversionApi, viewElement, modelElement, styles) {
|
|
83
|
-
if (!conversionApi.consumable.test(viewElement, { styles: ['float'] })) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
let floatStyleName = null;
|
|
87
|
-
switch (viewElement.getStyle('float')) {
|
|
88
|
-
case 'left':
|
|
89
|
-
floatStyleName = 'alignLeft';
|
|
90
|
-
break;
|
|
91
|
-
case 'right':
|
|
92
|
-
floatStyleName = 'alignRight';
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (!floatStyleName) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const definition = getStyleDefinitionByName(floatStyleName, styles);
|
|
99
|
-
if (!definition) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const builtinDefinition = DEFAULT_OPTIONS[definition.name];
|
|
103
|
-
if (!isEqual(definition, builtinDefinition)) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
conversionApi.writer.setAttribute('imageStyle', floatStyleName, modelElement);
|
|
107
|
-
conversionApi.consumable.consume(viewElement, { styles: ['float'] });
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Returns the style with a given `name` from an array of styles.
|
|
111
|
-
*/
|
|
112
|
-
function getStyleDefinitionByName(name, styles) {
|
|
113
|
-
for (const style of styles) {
|
|
114
|
-
if (style.name === name) {
|
|
115
|
-
return style;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
import { Command } from 'ckeditor5/src/core.js';
|
|
6
|
-
/**
|
|
7
|
-
* The image style command. It is used to apply {@link module:image/imageconfig~ImageStyleConfig#options image style option}
|
|
8
|
-
* to a selected image.
|
|
9
|
-
*
|
|
10
|
-
* **Note**: Executing this command may change the image model element if the desired style requires an image of a different
|
|
11
|
-
* type. See {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand#execute} to learn more.
|
|
12
|
-
*/
|
|
13
|
-
export class ImageStyleCommand extends Command {
|
|
14
|
-
/**
|
|
15
|
-
* An object containing names of default style options for the inline and block images.
|
|
16
|
-
* If there is no default style option for the given image type in the configuration,
|
|
17
|
-
* the name will be `false`.
|
|
18
|
-
*/
|
|
19
|
-
_defaultStyles;
|
|
20
|
-
/**
|
|
21
|
-
* The styles handled by this command.
|
|
22
|
-
*/
|
|
23
|
-
_styles;
|
|
24
|
-
/**
|
|
25
|
-
* Creates an instance of the image style command. When executed, the command applies one of
|
|
26
|
-
* {@link module:image/imageconfig~ImageStyleConfig#options style options} to the currently selected image.
|
|
27
|
-
*
|
|
28
|
-
* @param editor The editor instance.
|
|
29
|
-
* @param styles The style options that this command supports.
|
|
30
|
-
*/
|
|
31
|
-
constructor(editor, styles) {
|
|
32
|
-
super(editor);
|
|
33
|
-
this._defaultStyles = {
|
|
34
|
-
imageBlock: false,
|
|
35
|
-
imageInline: false
|
|
36
|
-
};
|
|
37
|
-
this._styles = new Map(styles.map(style => {
|
|
38
|
-
if (style.isDefault) {
|
|
39
|
-
for (const modelElementName of style.modelElements) {
|
|
40
|
-
this._defaultStyles[modelElementName] = style.name;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return [style.name, style];
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @inheritDoc
|
|
48
|
-
*/
|
|
49
|
-
refresh() {
|
|
50
|
-
const editor = this.editor;
|
|
51
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
52
|
-
const element = imageUtils.getClosestSelectedImageElement(this.editor.model.document.selection);
|
|
53
|
-
this.isEnabled = !!element;
|
|
54
|
-
if (!this.isEnabled) {
|
|
55
|
-
this.value = false;
|
|
56
|
-
}
|
|
57
|
-
else if (element.hasAttribute('imageStyle')) {
|
|
58
|
-
this.value = element.getAttribute('imageStyle');
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this.value = this._defaultStyles[element.name];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Executes the command and applies the style to the currently selected image:
|
|
66
|
-
*
|
|
67
|
-
* ```ts
|
|
68
|
-
* editor.execute( 'imageStyle', { value: 'side' } );
|
|
69
|
-
* ```
|
|
70
|
-
*
|
|
71
|
-
* **Note**: Executing this command may change the image model element if the desired style requires an image
|
|
72
|
-
* of a different type. Learn more about {@link module:image/imageconfig~ImageStyleOptionDefinition#modelElements model element}
|
|
73
|
-
* configuration for the style option.
|
|
74
|
-
*
|
|
75
|
-
* @param options.value The name of the style (as configured in {@link module:image/imageconfig~ImageStyleConfig#options}).
|
|
76
|
-
* @param options.setImageSizes Specifies whether the image `width` and `height` attributes should be set automatically.
|
|
77
|
-
* The default is `true`.
|
|
78
|
-
* @fires execute
|
|
79
|
-
*/
|
|
80
|
-
execute(options = {}) {
|
|
81
|
-
const editor = this.editor;
|
|
82
|
-
const model = editor.model;
|
|
83
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
84
|
-
model.change(writer => {
|
|
85
|
-
const requestedStyle = options.value;
|
|
86
|
-
const { setImageSizes = true } = options;
|
|
87
|
-
let imageElement = imageUtils.getClosestSelectedImageElement(model.document.selection);
|
|
88
|
-
// Change the image type if a style requires it.
|
|
89
|
-
if (requestedStyle && this.shouldConvertImageType(requestedStyle, imageElement)) {
|
|
90
|
-
this.editor.execute(imageUtils.isBlockImage(imageElement) ? 'imageTypeInline' : 'imageTypeBlock', { setImageSizes });
|
|
91
|
-
// Update the imageElement to the newly created image.
|
|
92
|
-
imageElement = imageUtils.getClosestSelectedImageElement(model.document.selection);
|
|
93
|
-
}
|
|
94
|
-
// Default style means that there is no `imageStyle` attribute in the model.
|
|
95
|
-
// https://github.com/ckeditor/ckeditor5-image/issues/147
|
|
96
|
-
if (!requestedStyle || this._styles.get(requestedStyle).isDefault) {
|
|
97
|
-
writer.removeAttribute('imageStyle', imageElement);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
writer.setAttribute('imageStyle', requestedStyle, imageElement);
|
|
101
|
-
}
|
|
102
|
-
if (setImageSizes) {
|
|
103
|
-
imageUtils.setImageNaturalSizeAttributes(imageElement);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Returns `true` if requested style change would trigger the image type change.
|
|
109
|
-
*
|
|
110
|
-
* @param requestedStyle The name of the style (as configured in {@link module:image/imageconfig~ImageStyleConfig#options}).
|
|
111
|
-
* @param imageElement The image model element.
|
|
112
|
-
*/
|
|
113
|
-
shouldConvertImageType(requestedStyle, imageElement) {
|
|
114
|
-
const supportedTypes = this._styles.get(requestedStyle).modelElements;
|
|
115
|
-
return !supportedTypes.includes(imageElement.name);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module image/imagestyle/imagestyleediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { ImageStyleCommand } from './imagestylecommand.js';
|
|
10
|
-
import { ImageUtils } from '../imageutils.js';
|
|
11
|
-
import { utils } from './utils.js';
|
|
12
|
-
import { viewToModelStyleAttribute, modelToViewStyleAttribute } from './converters.js';
|
|
13
|
-
/**
|
|
14
|
-
* The image style engine plugin. It sets the default configuration, creates converters and registers
|
|
15
|
-
* {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand ImageStyleCommand}.
|
|
16
|
-
*/
|
|
17
|
-
export class ImageStyleEditing extends Plugin {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
static get pluginName() {
|
|
22
|
-
return 'ImageStyleEditing';
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
static get isOfficialPlugin() {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @inheritDoc
|
|
32
|
-
*/
|
|
33
|
-
static get requires() {
|
|
34
|
-
return [ImageUtils];
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* It contains a list of the normalized and validated style options.
|
|
38
|
-
*
|
|
39
|
-
* * Each option contains a complete icon markup.
|
|
40
|
-
* * The style options not supported by any of the loaded image editing plugins (
|
|
41
|
-
* {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} or
|
|
42
|
-
* {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`}) are filtered out.
|
|
43
|
-
*
|
|
44
|
-
* @internal
|
|
45
|
-
* @readonly
|
|
46
|
-
*/
|
|
47
|
-
normalizedStyles;
|
|
48
|
-
/**
|
|
49
|
-
* @inheritDoc
|
|
50
|
-
*/
|
|
51
|
-
init() {
|
|
52
|
-
const editor = this.editor;
|
|
53
|
-
const isBlockPluginLoaded = editor.plugins.has('ImageBlockEditing');
|
|
54
|
-
const isInlinePluginLoaded = editor.plugins.has('ImageInlineEditing');
|
|
55
|
-
editor.config.define('image.styles', utils.getDefaultStylesConfiguration(isBlockPluginLoaded, isInlinePluginLoaded));
|
|
56
|
-
this.normalizedStyles = utils.normalizeStyles({
|
|
57
|
-
configuredStyles: editor.config.get('image.styles'),
|
|
58
|
-
isBlockPluginLoaded,
|
|
59
|
-
isInlinePluginLoaded
|
|
60
|
-
});
|
|
61
|
-
this._setupConversion(isBlockPluginLoaded, isInlinePluginLoaded);
|
|
62
|
-
this._setupPostFixer();
|
|
63
|
-
// Register imageStyle command.
|
|
64
|
-
editor.commands.add('imageStyle', new ImageStyleCommand(editor, this.normalizedStyles));
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Sets the editor conversion taking the presence of
|
|
68
|
-
* {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`}
|
|
69
|
-
* and {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} plugins into consideration.
|
|
70
|
-
*/
|
|
71
|
-
_setupConversion(isBlockPluginLoaded, isInlinePluginLoaded) {
|
|
72
|
-
const editor = this.editor;
|
|
73
|
-
const schema = editor.model.schema;
|
|
74
|
-
const modelToViewConverter = modelToViewStyleAttribute(this.normalizedStyles);
|
|
75
|
-
const viewToModelConverter = viewToModelStyleAttribute(this.normalizedStyles);
|
|
76
|
-
editor.editing.downcastDispatcher.on('attribute:imageStyle', modelToViewConverter);
|
|
77
|
-
editor.data.downcastDispatcher.on('attribute:imageStyle', modelToViewConverter);
|
|
78
|
-
// Allow imageStyle attribute in image and imageInline.
|
|
79
|
-
// We could call it 'style' but https://github.com/ckeditor/ckeditor5-engine/issues/559.
|
|
80
|
-
if (isBlockPluginLoaded) {
|
|
81
|
-
schema.extend('imageBlock', { allowAttributes: 'imageStyle' });
|
|
82
|
-
schema.setAttributeProperties('imageStyle', { isFormatting: true });
|
|
83
|
-
// Converter for figure element from view to model.
|
|
84
|
-
editor.data.upcastDispatcher.on('element:figure', viewToModelConverter, { priority: 'low' });
|
|
85
|
-
}
|
|
86
|
-
if (isInlinePluginLoaded) {
|
|
87
|
-
schema.extend('imageInline', { allowAttributes: 'imageStyle' });
|
|
88
|
-
schema.setAttributeProperties('imageStyle', { isFormatting: true });
|
|
89
|
-
// Converter for the img element from view to model.
|
|
90
|
-
editor.data.upcastDispatcher.on('element:img', viewToModelConverter, { priority: 'low' });
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Registers a post-fixer that will make sure that the style attribute value is correct for a specific image type (block vs inline).
|
|
95
|
-
*/
|
|
96
|
-
_setupPostFixer() {
|
|
97
|
-
const editor = this.editor;
|
|
98
|
-
const document = editor.model.document;
|
|
99
|
-
const imageUtils = editor.plugins.get(ImageUtils);
|
|
100
|
-
const stylesMap = new Map(this.normalizedStyles.map(style => [style.name, style]));
|
|
101
|
-
// Make sure that style attribute is valid for the image type.
|
|
102
|
-
document.registerPostFixer(writer => {
|
|
103
|
-
let changed = false;
|
|
104
|
-
for (const change of document.differ.getChanges()) {
|
|
105
|
-
if (change.type == 'insert' || change.type == 'attribute' && change.attributeKey == 'imageStyle') {
|
|
106
|
-
let element = change.type == 'insert' ? change.position.nodeAfter : change.range.start.nodeAfter;
|
|
107
|
-
if (element && element.is('element', 'paragraph') && element.childCount > 0) {
|
|
108
|
-
element = element.getChild(0);
|
|
109
|
-
}
|
|
110
|
-
if (!imageUtils.isImage(element)) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
const imageStyle = element.getAttribute('imageStyle');
|
|
114
|
-
if (!imageStyle) {
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
const imageStyleDefinition = stylesMap.get(imageStyle);
|
|
118
|
-
if (!imageStyleDefinition || !imageStyleDefinition.modelElements.includes(element.name)) {
|
|
119
|
-
writer.removeAttribute('imageStyle', element);
|
|
120
|
-
changed = true;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return changed;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|