UNPKG

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