@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,238 +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/imagecaption/imagecaptionediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { ModelElement, enableViewPlaceholder } from 'ckeditor5/src/engine.js';
|
|
10
|
-
import { toWidgetEditable } from 'ckeditor5/src/widget.js';
|
|
11
|
-
import { ToggleImageCaptionCommand } from './toggleimagecaptioncommand.js';
|
|
12
|
-
import { ImageUtils } from '../imageutils.js';
|
|
13
|
-
import { ImageCaptionUtils } from './imagecaptionutils.js';
|
|
14
|
-
/**
|
|
15
|
-
* The image caption engine plugin. It is responsible for:
|
|
16
|
-
*
|
|
17
|
-
* * registering converters for the caption element,
|
|
18
|
-
* * registering converters for the caption model attribute,
|
|
19
|
-
* * registering the {@link module:image/imagecaption/toggleimagecaptioncommand~ToggleImageCaptionCommand `toggleImageCaption`} command.
|
|
20
|
-
*/
|
|
21
|
-
export class ImageCaptionEditing extends Plugin {
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
static get requires() {
|
|
26
|
-
return [ImageUtils, ImageCaptionUtils];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @inheritDoc
|
|
30
|
-
*/
|
|
31
|
-
static get pluginName() {
|
|
32
|
-
return 'ImageCaptionEditing';
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* @inheritDoc
|
|
36
|
-
*/
|
|
37
|
-
static get isOfficialPlugin() {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* A map that keeps saved JSONified image captions and image model elements they are
|
|
42
|
-
* associated with.
|
|
43
|
-
*
|
|
44
|
-
* To learn more about this system, see {@link #_saveCaption}.
|
|
45
|
-
*/
|
|
46
|
-
_savedCaptionsMap;
|
|
47
|
-
/**
|
|
48
|
-
* @inheritDoc
|
|
49
|
-
*/
|
|
50
|
-
constructor(editor) {
|
|
51
|
-
super(editor);
|
|
52
|
-
this._savedCaptionsMap = new WeakMap();
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @inheritDoc
|
|
56
|
-
*/
|
|
57
|
-
init() {
|
|
58
|
-
const editor = this.editor;
|
|
59
|
-
const schema = editor.model.schema;
|
|
60
|
-
// Schema configuration.
|
|
61
|
-
if (!schema.isRegistered('caption')) {
|
|
62
|
-
schema.register('caption', {
|
|
63
|
-
allowIn: 'imageBlock',
|
|
64
|
-
allowContentOf: '$block',
|
|
65
|
-
isLimit: true
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
schema.extend('caption', {
|
|
70
|
-
allowIn: 'imageBlock'
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
editor.commands.add('toggleImageCaption', new ToggleImageCaptionCommand(this.editor));
|
|
74
|
-
this._setupConversion();
|
|
75
|
-
this._setupImageTypeCommandsIntegration();
|
|
76
|
-
this._registerCaptionReconversion();
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Configures conversion pipelines to support upcasting and downcasting
|
|
80
|
-
* image captions.
|
|
81
|
-
*/
|
|
82
|
-
_setupConversion() {
|
|
83
|
-
const editor = this.editor;
|
|
84
|
-
const view = editor.editing.view;
|
|
85
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
86
|
-
const imageCaptionUtils = editor.plugins.get('ImageCaptionUtils');
|
|
87
|
-
const t = editor.t;
|
|
88
|
-
// View -> model converter for the data pipeline.
|
|
89
|
-
editor.conversion.for('upcast').elementToElement({
|
|
90
|
-
view: element => imageCaptionUtils.matchImageCaptionViewElement(element),
|
|
91
|
-
model: 'caption'
|
|
92
|
-
});
|
|
93
|
-
// Model -> view converter for the data pipeline.
|
|
94
|
-
editor.conversion.for('dataDowncast').elementToElement({
|
|
95
|
-
model: 'caption',
|
|
96
|
-
view: (modelElement, { writer }) => {
|
|
97
|
-
if (!imageUtils.isBlockImage(modelElement.parent)) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
return writer.createContainerElement('figcaption');
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
// Model -> view converter for the editing pipeline.
|
|
104
|
-
editor.conversion.for('editingDowncast').elementToElement({
|
|
105
|
-
model: 'caption',
|
|
106
|
-
view: (modelElement, { writer }) => {
|
|
107
|
-
if (!imageUtils.isBlockImage(modelElement.parent)) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
const figcaptionElement = writer.createEditableElement('figcaption');
|
|
111
|
-
writer.setCustomProperty('imageCaption', true, figcaptionElement);
|
|
112
|
-
figcaptionElement.placeholder = t('Enter image caption');
|
|
113
|
-
enableViewPlaceholder({
|
|
114
|
-
view,
|
|
115
|
-
element: figcaptionElement,
|
|
116
|
-
keepOnFocus: true
|
|
117
|
-
});
|
|
118
|
-
const imageAlt = modelElement.parent.getAttribute('alt');
|
|
119
|
-
const label = imageAlt ? t('Caption for image: %0', [imageAlt]) : t('Caption for the image');
|
|
120
|
-
return toWidgetEditable(figcaptionElement, writer, { label });
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Integrates with {@link module:image/image/imagetypecommand~ImageTypeCommand image type commands}
|
|
126
|
-
* to make sure the caption is preserved when the type of an image changes so it can be restored
|
|
127
|
-
* in the future if the user decides they want their caption back.
|
|
128
|
-
*/
|
|
129
|
-
_setupImageTypeCommandsIntegration() {
|
|
130
|
-
const editor = this.editor;
|
|
131
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
132
|
-
const imageCaptionUtils = editor.plugins.get('ImageCaptionUtils');
|
|
133
|
-
const imageTypeInlineCommand = editor.commands.get('imageTypeInline');
|
|
134
|
-
const imageTypeBlockCommand = editor.commands.get('imageTypeBlock');
|
|
135
|
-
const handleImageTypeChange = evt => {
|
|
136
|
-
// The image type command execution can be unsuccessful.
|
|
137
|
-
if (!evt.return) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const { oldElement, newElement } = evt.return;
|
|
141
|
-
/* istanbul ignore if: paranoid check -- @preserve */
|
|
142
|
-
if (!oldElement) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (imageUtils.isBlockImage(oldElement)) {
|
|
146
|
-
const oldCaptionElement = imageCaptionUtils.getCaptionFromImageModelElement(oldElement);
|
|
147
|
-
// If the old element was a captioned block image (the caption was visible),
|
|
148
|
-
// simply save it so it can be restored.
|
|
149
|
-
if (oldCaptionElement) {
|
|
150
|
-
this._saveCaption(newElement, oldCaptionElement);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const savedOldElementCaption = this._getSavedCaption(oldElement);
|
|
155
|
-
// If either:
|
|
156
|
-
//
|
|
157
|
-
// * the block image didn't have a visible caption,
|
|
158
|
-
// * the block image caption was hidden (and already saved),
|
|
159
|
-
// * the inline image was passed
|
|
160
|
-
//
|
|
161
|
-
// just try to "pass" the saved caption from the old image to the new image
|
|
162
|
-
// so it can be retrieved in the future if the user wants it back.
|
|
163
|
-
if (savedOldElementCaption) {
|
|
164
|
-
// Note: Since we're writing to a WeakMap, we don't bother with removing the
|
|
165
|
-
// [ oldElement, savedOldElementCaption ] pair from it.
|
|
166
|
-
this._saveCaption(newElement, savedOldElementCaption);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
// Presence of the commands depends on the Image(Inline|Block)Editing plugins loaded in the editor.
|
|
170
|
-
if (imageTypeInlineCommand) {
|
|
171
|
-
this.listenTo(imageTypeInlineCommand, 'execute', handleImageTypeChange, { priority: 'low' });
|
|
172
|
-
}
|
|
173
|
-
if (imageTypeBlockCommand) {
|
|
174
|
-
this.listenTo(imageTypeBlockCommand, 'execute', handleImageTypeChange, { priority: 'low' });
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Returns the saved {@link module:engine/model/element~ModelElement#toJSON JSONified} caption
|
|
179
|
-
* of an image model element.
|
|
180
|
-
*
|
|
181
|
-
* See {@link #_saveCaption}.
|
|
182
|
-
*
|
|
183
|
-
* @internal
|
|
184
|
-
* @param imageModelElement The model element the caption should be returned for.
|
|
185
|
-
* @returns The model caption element or `null` if there is none.
|
|
186
|
-
*/
|
|
187
|
-
_getSavedCaption(imageModelElement) {
|
|
188
|
-
const jsonObject = this._savedCaptionsMap.get(imageModelElement);
|
|
189
|
-
return jsonObject ? ModelElement.fromJSON(jsonObject) : null;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Saves a {@link module:engine/model/element~ModelElement#toJSON JSONified} caption for
|
|
193
|
-
* an image element to allow restoring it in the future.
|
|
194
|
-
*
|
|
195
|
-
* A caption is saved every time it gets hidden and/or the type of an image changes. The
|
|
196
|
-
* user should be able to restore it on demand.
|
|
197
|
-
*
|
|
198
|
-
* **Note**: The caption cannot be stored in the image model element attribute because,
|
|
199
|
-
* for instance, when the model state propagates to collaborators, the attribute would get
|
|
200
|
-
* lost (mainly because it does not convert to anything when the caption is hidden) and
|
|
201
|
-
* the states of collaborators' models would de-synchronize causing numerous issues.
|
|
202
|
-
*
|
|
203
|
-
* See {@link #_getSavedCaption}.
|
|
204
|
-
*
|
|
205
|
-
* @internal
|
|
206
|
-
* @param imageModelElement The model element the caption is saved for.
|
|
207
|
-
* @param caption The caption model element to be saved.
|
|
208
|
-
*/
|
|
209
|
-
_saveCaption(imageModelElement, caption) {
|
|
210
|
-
this._savedCaptionsMap.set(imageModelElement, caption.toJSON());
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Reconverts image caption when image alt attribute changes.
|
|
214
|
-
* The change of alt attribute is reflected in caption's aria-label attribute.
|
|
215
|
-
*/
|
|
216
|
-
_registerCaptionReconversion() {
|
|
217
|
-
const editor = this.editor;
|
|
218
|
-
const model = editor.model;
|
|
219
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
220
|
-
const imageCaptionUtils = editor.plugins.get('ImageCaptionUtils');
|
|
221
|
-
model.document.on('change:data', () => {
|
|
222
|
-
const changes = model.document.differ.getChanges();
|
|
223
|
-
for (const change of changes) {
|
|
224
|
-
if (change.attributeKey !== 'alt') {
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
const image = change.range.start.nodeAfter;
|
|
228
|
-
if (imageUtils.isBlockImage(image)) {
|
|
229
|
-
const caption = imageCaptionUtils.getCaptionFromImageModelElement(image);
|
|
230
|
-
if (!caption) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
editor.editing.reconvertItem(caption);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
@@ -1,68 +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/imagecaption/imagecaptionui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { ButtonView } from 'ckeditor5/src/ui.js';
|
|
10
|
-
import { IconCaption } from 'ckeditor5/src/icons.js';
|
|
11
|
-
import { ImageCaptionUtils } from './imagecaptionutils.js';
|
|
12
|
-
/**
|
|
13
|
-
* The image caption UI plugin. It introduces the `'toggleImageCaption'` UI button.
|
|
14
|
-
*/
|
|
15
|
-
export class ImageCaptionUI extends Plugin {
|
|
16
|
-
/**
|
|
17
|
-
* @inheritDoc
|
|
18
|
-
*/
|
|
19
|
-
static get requires() {
|
|
20
|
-
return [ImageCaptionUtils];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
static get pluginName() {
|
|
26
|
-
return 'ImageCaptionUI';
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @inheritDoc
|
|
30
|
-
*/
|
|
31
|
-
static get isOfficialPlugin() {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* @inheritDoc
|
|
36
|
-
*/
|
|
37
|
-
init() {
|
|
38
|
-
const editor = this.editor;
|
|
39
|
-
const editingView = editor.editing.view;
|
|
40
|
-
const imageCaptionUtils = editor.plugins.get('ImageCaptionUtils');
|
|
41
|
-
const t = editor.t;
|
|
42
|
-
editor.ui.componentFactory.add('toggleImageCaption', locale => {
|
|
43
|
-
const command = editor.commands.get('toggleImageCaption');
|
|
44
|
-
const view = new ButtonView(locale);
|
|
45
|
-
view.set({
|
|
46
|
-
icon: IconCaption,
|
|
47
|
-
tooltip: true,
|
|
48
|
-
isToggleable: true
|
|
49
|
-
});
|
|
50
|
-
view.bind('isOn', 'isEnabled').to(command, 'value', 'isEnabled');
|
|
51
|
-
view.bind('label').to(command, 'value', value => value ? t('Toggle caption off') : t('Toggle caption on'));
|
|
52
|
-
this.listenTo(view, 'execute', () => {
|
|
53
|
-
editor.execute('toggleImageCaption', { focusCaptionOnShow: true });
|
|
54
|
-
// Scroll to the selection and highlight the caption if the caption showed up.
|
|
55
|
-
const modelCaptionElement = imageCaptionUtils.getCaptionFromModelSelection(editor.model.document.selection);
|
|
56
|
-
if (modelCaptionElement) {
|
|
57
|
-
const figcaptionElement = editor.editing.mapper.toViewElement(modelCaptionElement);
|
|
58
|
-
editingView.scrollToTheSelection();
|
|
59
|
-
editingView.change(writer => {
|
|
60
|
-
writer.addClass('image__caption_highlighted', figcaptionElement);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
editor.editing.view.focus();
|
|
64
|
-
});
|
|
65
|
-
return view;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,68 +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 { Plugin } from 'ckeditor5/src/core.js';
|
|
6
|
-
import { ImageUtils } from '../imageutils.js';
|
|
7
|
-
/**
|
|
8
|
-
* The image caption utilities plugin.
|
|
9
|
-
*/
|
|
10
|
-
export class ImageCaptionUtils extends Plugin {
|
|
11
|
-
/**
|
|
12
|
-
* @inheritDoc
|
|
13
|
-
*/
|
|
14
|
-
static get pluginName() {
|
|
15
|
-
return 'ImageCaptionUtils';
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @inheritDoc
|
|
19
|
-
*/
|
|
20
|
-
static get isOfficialPlugin() {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
static get requires() {
|
|
27
|
-
return [ImageUtils];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Returns the caption model element from a given image element. Returns `null` if no caption is found.
|
|
31
|
-
*/
|
|
32
|
-
getCaptionFromImageModelElement(imageModelElement) {
|
|
33
|
-
for (const node of imageModelElement.getChildren()) {
|
|
34
|
-
if (!!node && node.is('element', 'caption')) {
|
|
35
|
-
return node;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Returns the caption model element for a model selection. Returns `null` if the selection has no caption element ancestor.
|
|
42
|
-
*/
|
|
43
|
-
getCaptionFromModelSelection(selection) {
|
|
44
|
-
const imageUtils = this.editor.plugins.get('ImageUtils');
|
|
45
|
-
const captionElement = selection.getFirstPosition().findAncestor('caption');
|
|
46
|
-
if (!captionElement) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
if (imageUtils.isBlockImage(captionElement.parent)) {
|
|
50
|
-
return captionElement;
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* {@link module:engine/view/matcher~Matcher} pattern. Checks if a given element is a `<figcaption>` element that is placed
|
|
56
|
-
* inside the image `<figure>` element.
|
|
57
|
-
* @returns Returns the object accepted by {@link module:engine/view/matcher~Matcher} or `null` if the element
|
|
58
|
-
* cannot be matched.
|
|
59
|
-
*/
|
|
60
|
-
matchImageCaptionViewElement(element) {
|
|
61
|
-
const imageUtils = this.editor.plugins.get('ImageUtils');
|
|
62
|
-
// Convert only captions for images.
|
|
63
|
-
if (element.name == 'figcaption' && imageUtils.isBlockImageView(element.parent)) {
|
|
64
|
-
return { name: true };
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,138 +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
|
-
import { ImageBlockEditing } from '../image/imageblockediting.js';
|
|
7
|
-
/**
|
|
8
|
-
* The toggle image caption command.
|
|
9
|
-
*
|
|
10
|
-
* This command is registered by {@link module:image/imagecaption/imagecaptionediting~ImageCaptionEditing} as the
|
|
11
|
-
* `'toggleImageCaption'` editor command.
|
|
12
|
-
*
|
|
13
|
-
* Executing this command:
|
|
14
|
-
*
|
|
15
|
-
* * either adds or removes the image caption of a selected image (depending on whether the caption is present or not),
|
|
16
|
-
* * removes the image caption if the selection is anchored in one.
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* // Toggle the presence of the caption.
|
|
20
|
-
* editor.execute( 'toggleImageCaption' );
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* **Note**: Upon executing this command, the selection will be set on the image if previously anchored in the caption element.
|
|
24
|
-
*
|
|
25
|
-
* **Note**: You can move the selection to the caption right away as it shows up upon executing this command by using
|
|
26
|
-
* the `focusCaptionOnShow` option:
|
|
27
|
-
*
|
|
28
|
-
* ```ts
|
|
29
|
-
* editor.execute( 'toggleImageCaption', { focusCaptionOnShow: true } );
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export class ToggleImageCaptionCommand extends Command {
|
|
33
|
-
/**
|
|
34
|
-
* @inheritDoc
|
|
35
|
-
*/
|
|
36
|
-
refresh() {
|
|
37
|
-
const editor = this.editor;
|
|
38
|
-
const imageCaptionUtils = editor.plugins.get('ImageCaptionUtils');
|
|
39
|
-
const imageUtils = editor.plugins.get('ImageUtils');
|
|
40
|
-
// Only block images can get captions.
|
|
41
|
-
if (!editor.plugins.has(ImageBlockEditing)) {
|
|
42
|
-
this.isEnabled = false;
|
|
43
|
-
this.value = false;
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const selection = editor.model.document.selection;
|
|
47
|
-
const selectedElement = selection.getSelectedElement();
|
|
48
|
-
if (!selectedElement) {
|
|
49
|
-
const ancestorCaptionElement = imageCaptionUtils.getCaptionFromModelSelection(selection);
|
|
50
|
-
this.isEnabled = !!ancestorCaptionElement;
|
|
51
|
-
this.value = !!ancestorCaptionElement;
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// Block images support captions by default but the command should also be enabled for inline
|
|
55
|
-
// images because toggling the caption when one is selected should convert it into a block image.
|
|
56
|
-
this.isEnabled = imageUtils.isImage(selectedElement);
|
|
57
|
-
if (!this.isEnabled) {
|
|
58
|
-
this.value = false;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this.value = !!imageCaptionUtils.getCaptionFromImageModelElement(selectedElement);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Executes the command.
|
|
66
|
-
*
|
|
67
|
-
* ```ts
|
|
68
|
-
* editor.execute( 'toggleImageCaption' );
|
|
69
|
-
* ```
|
|
70
|
-
*
|
|
71
|
-
* @param options Options for the executed command.
|
|
72
|
-
* @param options.focusCaptionOnShow When true and the caption shows up, the selection will be moved into it straight away.
|
|
73
|
-
* @fires execute
|
|
74
|
-
*/
|
|
75
|
-
execute(options = {}) {
|
|
76
|
-
const { focusCaptionOnShow } = options;
|
|
77
|
-
this.editor.model.change(writer => {
|
|
78
|
-
if (this.value) {
|
|
79
|
-
this._hideImageCaption(writer);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
this._showImageCaption(writer, focusCaptionOnShow);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Shows the caption of the `<imageBlock>` or `<imageInline>`. Also:
|
|
88
|
-
*
|
|
89
|
-
* * it converts `<imageInline>` to `<imageBlock>` to show the caption,
|
|
90
|
-
* * it attempts to restore the caption content from the `ImageCaptionEditing` caption registry,
|
|
91
|
-
* * it moves the selection to the caption right away, it the `focusCaptionOnShow` option was set.
|
|
92
|
-
*/
|
|
93
|
-
_showImageCaption(writer, focusCaptionOnShow) {
|
|
94
|
-
const model = this.editor.model;
|
|
95
|
-
const selection = model.document.selection;
|
|
96
|
-
const imageCaptionEditing = this.editor.plugins.get('ImageCaptionEditing');
|
|
97
|
-
const imageUtils = this.editor.plugins.get('ImageUtils');
|
|
98
|
-
let selectedImage = selection.getSelectedElement();
|
|
99
|
-
const savedCaption = imageCaptionEditing._getSavedCaption(selectedImage);
|
|
100
|
-
// Convert imageInline -> image first.
|
|
101
|
-
if (imageUtils.isInlineImage(selectedImage)) {
|
|
102
|
-
this.editor.execute('imageTypeBlock');
|
|
103
|
-
// Executing the command created a new model element. Let's pick it again.
|
|
104
|
-
selectedImage = selection.getSelectedElement();
|
|
105
|
-
}
|
|
106
|
-
// Try restoring the caption from the ImageCaptionEditing plugin storage.
|
|
107
|
-
const newCaptionElement = savedCaption || writer.createElement('caption');
|
|
108
|
-
writer.append(newCaptionElement, selectedImage);
|
|
109
|
-
if (focusCaptionOnShow) {
|
|
110
|
-
writer.setSelection(newCaptionElement, 'in');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Hides the caption of a selected image (or an image caption the selection is anchored to).
|
|
115
|
-
*
|
|
116
|
-
* The content of the caption is stored in the `ImageCaptionEditing` caption registry to make this
|
|
117
|
-
* a reversible action.
|
|
118
|
-
*/
|
|
119
|
-
_hideImageCaption(writer) {
|
|
120
|
-
const editor = this.editor;
|
|
121
|
-
const selection = editor.model.document.selection;
|
|
122
|
-
const imageCaptionEditing = editor.plugins.get('ImageCaptionEditing');
|
|
123
|
-
const imageCaptionUtils = editor.plugins.get('ImageCaptionUtils');
|
|
124
|
-
let selectedImage = selection.getSelectedElement();
|
|
125
|
-
let captionElement;
|
|
126
|
-
if (selectedImage) {
|
|
127
|
-
captionElement = imageCaptionUtils.getCaptionFromImageModelElement(selectedImage);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
captionElement = imageCaptionUtils.getCaptionFromModelSelection(selection);
|
|
131
|
-
selectedImage = captionElement.parent;
|
|
132
|
-
}
|
|
133
|
-
// Store the caption content so it can be restored quickly if the user changes their mind even if they toggle image<->imageInline.
|
|
134
|
-
imageCaptionEditing._saveCaption(selectedImage, captionElement);
|
|
135
|
-
writer.setSelection(selectedImage, 'on');
|
|
136
|
-
writer.remove(captionElement);
|
|
137
|
-
}
|
|
138
|
-
}
|
package/src/imagecaption.js
DELETED
|
@@ -1,36 +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/imagecaption
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { ImageCaptionEditing } from './imagecaption/imagecaptionediting.js';
|
|
10
|
-
import { ImageCaptionUI } from './imagecaption/imagecaptionui.js';
|
|
11
|
-
import '../theme/imagecaption.css';
|
|
12
|
-
/**
|
|
13
|
-
* The image caption plugin.
|
|
14
|
-
*
|
|
15
|
-
* For a detailed overview, check the {@glink features/images/images-captions image caption} documentation.
|
|
16
|
-
*/
|
|
17
|
-
export class ImageCaption extends Plugin {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
static get requires() {
|
|
22
|
-
return [ImageCaptionEditing, ImageCaptionUI];
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
static get pluginName() {
|
|
28
|
-
return 'ImageCaption';
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @inheritDoc
|
|
32
|
-
*/
|
|
33
|
-
static get isOfficialPlugin() {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
}
|
package/src/imageconfig.js
DELETED
package/src/imageinline.js
DELETED
|
@@ -1,44 +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/imageinline
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { Widget } from 'ckeditor5/src/widget.js';
|
|
10
|
-
import { ImageTextAlternative } from './imagetextalternative.js';
|
|
11
|
-
import { ImageInlineEditing } from './image/imageinlineediting.js';
|
|
12
|
-
import { ImageInsertUI } from './imageinsert/imageinsertui.js';
|
|
13
|
-
import '../theme/image.css';
|
|
14
|
-
/**
|
|
15
|
-
* The image inline plugin.
|
|
16
|
-
*
|
|
17
|
-
* This is a "glue" plugin which loads the following plugins:
|
|
18
|
-
*
|
|
19
|
-
* * {@link module:image/image/imageinlineediting~ImageInlineEditing},
|
|
20
|
-
* * {@link module:image/imagetextalternative~ImageTextAlternative}.
|
|
21
|
-
*
|
|
22
|
-
* Usually, it is used in conjunction with other plugins from this package. See the {@glink api/image package page}
|
|
23
|
-
* for more information.
|
|
24
|
-
*/
|
|
25
|
-
export class ImageInline extends Plugin {
|
|
26
|
-
/**
|
|
27
|
-
* @inheritDoc
|
|
28
|
-
*/
|
|
29
|
-
static get requires() {
|
|
30
|
-
return [ImageInlineEditing, Widget, ImageTextAlternative, ImageInsertUI];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
static get pluginName() {
|
|
36
|
-
return 'ImageInline';
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @inheritDoc
|
|
40
|
-
*/
|
|
41
|
-
static get isOfficialPlugin() {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
}
|