1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { Plugin, type Editor } from 'ckeditor5/src/core.js';
|
9 | import { type Element, type Writer, type DataTransfer } from 'ckeditor5/src/engine.js';
|
10 | import { Notification } from 'ckeditor5/src/ui.js';
|
11 | import { ClipboardPipeline } from 'ckeditor5/src/clipboard.js';
|
12 | import { FileRepository, type UploadResponse, type FileLoader } from 'ckeditor5/src/upload.js';
|
13 | import ImageUtils from '../imageutils.js';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export default class ImageUploadEditing extends Plugin {
|
22 | |
23 |
|
24 |
|
25 | static get requires(): readonly [typeof FileRepository, typeof Notification, typeof ClipboardPipeline, typeof ImageUtils];
|
26 | static get pluginName(): "ImageUploadEditing";
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | private readonly _uploadImageElements;
|
37 | |
38 |
|
39 |
|
40 | constructor(editor: Editor);
|
41 | /**
|
42 | * @inheritDoc
|
43 | */
|
44 | init(): void;
|
45 | /**
|
46 | * @inheritDoc
|
47 | */
|
48 | afterInit(): void;
|
49 | /**
|
50 | * Reads and uploads an image.
|
51 | *
|
52 | * The image is read from the disk and as a Base64-encoded string it is set temporarily to
|
53 | * `image[src]`. When the image is successfully uploaded, the temporary data is replaced with the target
|
54 | * image's URL (the URL to the uploaded image on the server).
|
55 | */
|
56 | protected _readAndUpload(loader: FileLoader): Promise<void>;
|
57 | /**
|
58 | * Creates the `srcset` attribute based on a given file upload response and sets it as an attribute to a specific image element.
|
59 | *
|
60 | * @param data Data object from which `srcset` will be created.
|
61 | * @param image The image element on which the `srcset` attribute will be set.
|
62 | */
|
63 | protected _parseAndSetSrcsetAttributeOnImage(data: Record<string, unknown>, image: Element, writer: Writer): void;
|
64 | }
|
65 | /**
|
66 | * Returns `true` if non-empty `text/html` is included in the data transfer.
|
67 | */
|
68 | export declare function isHtmlIncluded(dataTransfer: DataTransfer): boolean;
|
69 | /**
|
70 | * An event fired when an image is uploaded. You can hook into this event to provide
|
71 | * custom attributes to the {@link module:engine/model/element~Element image element} based on the data from
|
72 | * the server.
|
73 | *
|
74 | * ```ts
|
75 | * const imageUploadEditing = editor.plugins.get( 'ImageUploadEditing' );
|
76 | *
|
77 | * imageUploadEditing.on( 'uploadComplete', ( evt, { data, imageElement } ) => {
|
78 | * editor.model.change( writer => {
|
79 | * writer.setAttribute( 'someAttribute', 'foo', imageElement );
|
80 | * } );
|
81 | * } );
|
82 | * ```
|
83 | *
|
84 | * You can also stop the default handler that sets the `src` and `srcset` attributes
|
85 | * if you want to provide custom values for these attributes.
|
86 | *
|
87 | * ```ts
|
88 | * imageUploadEditing.on( 'uploadComplete', ( evt, { data, imageElement } ) => {
|
89 | * evt.stop();
|
90 | * } );
|
91 | * ```
|
92 | *
|
93 | * **Note**: This event is fired by the {@link module:image/imageupload/imageuploadediting~ImageUploadEditing} plugin.
|
94 | *
|
95 | * @eventName ~ImageUploadEditing#uploadComplete
|
96 | * @param data The `uploadComplete` event data.
|
97 | */
|
98 | export type ImageUploadCompleteEvent = {
|
99 | name: 'uploadComplete';
|
100 | args: [data: ImageUploadCompleteData];
|
101 | };
|
102 | export type ImageUploadCompleteData = {
|
103 | /**
|
104 | * The data coming from the upload adapter.
|
105 | */
|
106 | data: UploadResponse;
|
107 | /**
|
108 | * The model {@link module:engine/model/element~Element image element} that can be customized.
|
109 | */
|
110 | imageElement: Element;
|
111 | };
|
112 |
|
\ | No newline at end of file |