UNPKG

2.94 kBTypeScriptView Raw
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/imagestyle/imagestylecommand
7 */
8import type { Element } from 'ckeditor5/src/engine.js';
9import { Command, type Editor } from 'ckeditor5/src/core.js';
10import type { ImageStyleOptionDefinition } from '../imageconfig.js';
11/**
12 * The image style command. It is used to apply {@link module:image/imageconfig~ImageStyleConfig#options image style option}
13 * to a selected image.
14 *
15 * **Note**: Executing this command may change the image model element if the desired style requires an image of a different
16 * type. See {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand#execute} to learn more.
17 */
18export default class ImageStyleCommand extends Command {
19 /**
20 * An object containing names of default style options for the inline and block images.
21 * If there is no default style option for the given image type in the configuration,
22 * the name will be `false`.
23 */
24 private _defaultStyles;
25 /**
26 * The styles handled by this command.
27 */
28 private _styles;
29 /**
30 * Creates an instance of the image style command. When executed, the command applies one of
31 * {@link module:image/imageconfig~ImageStyleConfig#options style options} to the currently selected image.
32 *
33 * @param editor The editor instance.
34 * @param styles The style options that this command supports.
35 */
36 constructor(editor: Editor, styles: Array<ImageStyleOptionDefinition>);
37 /**
38 * @inheritDoc
39 */
40 refresh(): void;
41 /**
42 * Executes the command and applies the style to the currently selected image:
43 *
44 * ```ts
45 * editor.execute( 'imageStyle', { value: 'side' } );
46 * ```
47 *
48 * **Note**: Executing this command may change the image model element if the desired style requires an image
49 * of a different type. Learn more about {@link module:image/imageconfig~ImageStyleOptionDefinition#modelElements model element}
50 * configuration for the style option.
51 *
52 * @param options.value The name of the style (as configured in {@link module:image/imageconfig~ImageStyleConfig#options}).
53 * @param options.setImageSizes Specifies whether the image `width` and `height` attributes should be set automatically.
54 * The default is `true`.
55 * @fires execute
56 */
57 execute(options?: {
58 value?: string;
59 setImageSizes?: boolean;
60 }): void;
61 /**
62 * Returns `true` if requested style change would trigger the image type change.
63 *
64 * @param requestedStyle The name of the style (as configured in {@link module:image/imageconfig~ImageStyleConfig#options}).
65 * @param imageElement The image model element.
66 */
67 shouldConvertImageType(requestedStyle: string, imageElement: Element): boolean;
68}