1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { Plugin } from 'ckeditor5/src/core';
|
9 | import ImageLoadObserver from './imageloadobserver';
|
10 | import InsertImageCommand from './insertimagecommand';
|
11 | import ReplaceImageSourceCommand from './replaceimagesourcecommand';
|
12 | import ImageUtils from '../imageutils';
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export default class ImageEditing extends Plugin {
|
21 | |
22 |
|
23 |
|
24 | static get requires() {
|
25 | return [ImageUtils];
|
26 | }
|
27 | |
28 |
|
29 |
|
30 | static get pluginName() {
|
31 | return 'ImageEditing';
|
32 | }
|
33 | |
34 |
|
35 |
|
36 | init() {
|
37 | const editor = this.editor;
|
38 | const conversion = editor.conversion;
|
39 |
|
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 |
|
61 | editor.commands.add('imageInsert', insertImageCommand);
|
62 | }
|
63 | }
|