1 | /**
|
2 | * @license Copyright (c) 2003-2024, 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/insertimagecommand
|
7 | */
|
8 | import { Command, type Editor } from 'ckeditor5/src/core.js';
|
9 | import { type ArrayOrItem } from 'ckeditor5/src/utils.js';
|
10 | /**
|
11 | * Insert image command.
|
12 | *
|
13 | * The command is registered by the {@link module:image/image/imageediting~ImageEditing} plugin as `insertImage`
|
14 | * and it is also available via aliased `imageInsert` name.
|
15 | *
|
16 | * In order to insert an image at the current selection position
|
17 | * (according to the {@link module:widget/utils~findOptimalInsertionRange} algorithm),
|
18 | * execute the command and specify the image source:
|
19 | *
|
20 | * ```ts
|
21 | * editor.execute( 'insertImage', { source: 'http://url.to.the/image' } );
|
22 | * ```
|
23 | *
|
24 | * It is also possible to insert multiple images at once:
|
25 | *
|
26 | * ```ts
|
27 | * editor.execute( 'insertImage', {
|
28 | * source: [
|
29 | * 'path/to/image.jpg',
|
30 | * 'path/to/other-image.jpg'
|
31 | * ]
|
32 | * } );
|
33 | * ```
|
34 | *
|
35 | * If you want to take the full control over the process, you can specify individual model attributes:
|
36 | *
|
37 | * ```ts
|
38 | * editor.execute( 'insertImage', {
|
39 | * source: [
|
40 | * { src: 'path/to/image.jpg', alt: 'First alt text' },
|
41 | * { src: 'path/to/other-image.jpg', alt: 'Second alt text', customAttribute: 'My attribute value' }
|
42 | * ]
|
43 | * } );
|
44 | * ```
|
45 | */
|
46 | export default class InsertImageCommand extends Command {
|
47 | /**
|
48 | * @inheritDoc
|
49 | */
|
50 | constructor(editor: Editor);
|
51 | /**
|
52 | * @inheritDoc
|
53 | */
|
54 | refresh(): void;
|
55 | /**
|
56 | * Executes the command.
|
57 | *
|
58 | * @fires execute
|
59 | * @param options Options for the executed command.
|
60 | * @param options.source The image source or an array of image sources to insert.
|
61 | * See the documentation of the command to learn more about accepted formats.
|
62 | */
|
63 | execute(options: {
|
64 | source: ArrayOrItem<string | Record<string, unknown>>;
|
65 | }): void;
|
66 | }
|