UNPKG

2.18 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 */
5/**
6 * @module image/imageresize/imageresizebuttons
7 */
8import { Plugin, type Editor } from 'ckeditor5/src/core';
9import ImageResizeEditing from './imageresizeediting';
10/**
11 * The image resize buttons plugin.
12 *
13 * It adds a possibility to resize images using the toolbar dropdown or individual buttons, depending on the plugin configuration.
14 */
15export default class ImageResizeButtons extends Plugin {
16 /**
17 * @inheritDoc
18 */
19 static get requires(): readonly [typeof ImageResizeEditing];
20 /**
21 * @inheritDoc
22 */
23 static get pluginName(): "ImageResizeButtons";
24 /**
25 * The resize unit.
26 * @default '%'
27 */
28 private readonly _resizeUnit;
29 /**
30 * @inheritDoc
31 */
32 constructor(editor: Editor);
33 /**
34 * @inheritDoc
35 */
36 init(): void;
37 /**
38 * A helper function that creates a standalone button component for the plugin.
39 *
40 * @param resizeOption A model of the resize option.
41 */
42 private _registerImageResizeButton;
43 /**
44 * A helper function that creates a dropdown component for the plugin containing all the resize options defined in
45 * the editor configuration.
46 *
47 * @param options An array of configured options.
48 */
49 private _registerImageResizeDropdown;
50 /**
51 * A helper function for creating an option label value string.
52 *
53 * @param option A resize option object.
54 * @param forTooltip An optional flag for creating a tooltip label.
55 * @returns A user-defined label combined from the numeric value and the resize unit or the default label
56 * for reset options (`Original`).
57 */
58 private _getOptionLabelValue;
59 /**
60 * A helper function that parses the resize options and returns list item definitions ready for use in the dropdown.
61 *
62 * @param options The resize options.
63 * @param command The resize image command.
64 * @returns Dropdown item definitions.
65 */
66 private _getResizeDropdownListItemDefinitions;
67}