UNPKG

2.14 kBJavaScriptView Raw
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/image/imageediting
7 */
8import { Plugin } from 'ckeditor5/src/core';
9import ImageLoadObserver from './imageloadobserver';
10import InsertImageCommand from './insertimagecommand';
11import ReplaceImageSourceCommand from './replaceimagesourcecommand';
12import ImageUtils from '../imageutils';
13/**
14 * The image engine plugin. This module loads common code shared between
15 * {@link module:image/image/imageinlineediting~ImageInlineEditing} and
16 * {@link module:image/image/imageblockediting~ImageBlockEditing} plugins.
17 *
18 * This plugin registers the {@link module:image/image/insertimagecommand~InsertImageCommand 'insertImage'} command.
19 */
20export default class ImageEditing extends Plugin {
21 /**
22 * @inheritDoc
23 */
24 static get requires() {
25 return [ImageUtils];
26 }
27 /**
28 * @inheritDoc
29 */
30 static get pluginName() {
31 return 'ImageEditing';
32 }
33 /**
34 * @inheritDoc
35 */
36 init() {
37 const editor = this.editor;
38 const conversion = editor.conversion;
39 // See https://github.com/ckeditor/ckeditor5-image/issues/142.
40 editor.editing.view.addObserver(ImageLoadObserver);
41 conversion.for('upcast')
42 .attributeToAttribute({
43 view: {
44 name: 'img',
45 key: 'alt'
46 },
47 model: 'alt'
48 })
49 .attributeToAttribute({
50 view: {
51 name: 'img',
52 key: 'srcset'
53 },
54 model: 'srcset'
55 });
56 const insertImageCommand = new InsertImageCommand(editor);
57 const replaceImageSourceCommand = new ReplaceImageSourceCommand(editor);
58 editor.commands.add('insertImage', insertImageCommand);
59 editor.commands.add('replaceImageSource', replaceImageSourceCommand);
60 // `imageInsert` is an alias for backward compatibility.
61 editor.commands.add('imageInsert', insertImageCommand);
62 }
63}