UNPKG

1.74 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 { Command } from 'ckeditor5/src/core.js';
6import { type ArrayOrItem } from 'ckeditor5/src/utils.js';
7/**
8 * @module image/imageupload/uploadimagecommand
9 */
10/**
11 * The upload image command.
12 *
13 * The command is registered by the {@link module:image/imageupload/imageuploadediting~ImageUploadEditing} plugin as `uploadImage`
14 * and it is also available via aliased `imageUpload` name.
15 *
16 * In order to upload an image at the current selection position
17 * (according to the {@link module:widget/utils~findOptimalInsertionRange} algorithm),
18 * execute the command and pass the native image file instance:
19 *
20 * ```ts
21 * this.listenTo( editor.editing.view.document, 'clipboardInput', ( evt, data ) => {
22 * // Assuming that only images were pasted:
23 * const images = Array.from( data.dataTransfer.files );
24 *
25 * // Upload the first image:
26 * editor.execute( 'uploadImage', { file: images[ 0 ] } );
27 * } );
28 * ```
29 *
30 * It is also possible to insert multiple images at once:
31 *
32 * ```ts
33 * editor.execute( 'uploadImage', {
34 * file: [
35 * file1,
36 * file2
37 * ]
38 * } );
39 * ```
40 */
41export default class UploadImageCommand extends Command {
42 /**
43 * @inheritDoc
44 */
45 refresh(): void;
46 /**
47 * Executes the command.
48 *
49 * @fires execute
50 * @param options Options for the executed command.
51 * @param options.file The image file or an array of image files to upload.
52 */
53 execute(options: {
54 file: ArrayOrItem<File>;
55 }): void;
56 /**
57 * Handles uploading single file.
58 */
59 private _uploadImage;
60}