UNPKG

1.58 kBTypeScriptView 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 */
5import { Command, type Editor } from 'ckeditor5/src/core';
6import type { Writer, Element } from 'ckeditor5/src/engine';
7/**
8 * @module image/image/replaceimagesourcecommand
9 */
10/**
11 * Replace image source command.
12 *
13 * Changes image source to the one provided. Can be executed as follows:
14 *
15 * ```ts
16 * editor.execute( 'replaceImageSource', { source: 'http://url.to.the/image' } );
17 * ```
18 */
19export default class ReplaceImageSourceCommand extends Command {
20 value: string | null;
21 constructor(editor: Editor);
22 /**
23 * @inheritDoc
24 */
25 refresh(): void;
26 /**
27 * Executes the command.
28 *
29 * @fires execute
30 * @param options Options for the executed command.
31 * @param options.source The image source to replace.
32 */
33 execute(options: {
34 source: string;
35 }): void;
36 /**
37 * Cleanup image attributes that are not relevant to the new source.
38 *
39 * Removed attributes are: 'srcset', 'sizes', 'sources', 'width', 'height', 'alt'.
40 *
41 * This method is decorated, to allow custom cleanup logic.
42 * For example, to remove 'myImageId' attribute after 'src' has changed:
43 *
44 * ```ts
45 * replaceImageSourceCommand.on( 'cleanupImage', ( eventInfo, [ writer, image ] ) => {
46 * writer.removeAttribute( 'myImageId', image );
47 * } );
48 * ```
49 */
50 cleanupImage(writer: Writer, image: Element): void;
51}