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 | import { Command, type Editor } from 'ckeditor5/src/core.js';
|
6 | import { 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 | */
|
41 | export default class UploadImageCommand extends Command {
|
42 | /**
|
43 | * The command property: `false` if there is no permission on image upload, otherwise `true`.
|
44 | *
|
45 | * @observable
|
46 | * @internal
|
47 | */
|
48 | isAccessAllowed: boolean;
|
49 | /**
|
50 | * Creates an instance of the `imageUlpoad` command. When executed, the command upload one of
|
51 | * the currently selected image from computer.
|
52 | *
|
53 | * @param editor The editor instance.
|
54 | */
|
55 | constructor(editor: Editor);
|
56 | /**
|
57 | * @inheritDoc
|
58 | */
|
59 | refresh(): void;
|
60 | /**
|
61 | * Executes the command.
|
62 | *
|
63 | * @fires execute
|
64 | * @param options Options for the executed command.
|
65 | * @param options.file The image file or an array of image files to upload.
|
66 | */
|
67 | execute(options: {
|
68 | file: ArrayOrItem<File>;
|
69 | }): void;
|
70 | /**
|
71 | * Handles uploading single file.
|
72 | */
|
73 | private _uploadImage;
|
74 | }
|