1 | import { Plugin } from '@ckeditor/ckeditor5-core';
|
2 | import { DocumentSelection, DowncastWriter, Element } from '@ckeditor/ckeditor5-engine';
|
3 | import DocumentFragment from '@ckeditor/ckeditor5-engine/src/model/documentfragment';
|
4 | import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element';
|
5 | import Selection, { Selectable } from '@ckeditor/ckeditor5-engine/src/model/selection';
|
6 | import ViewDocumentSelection from '@ckeditor/ckeditor5-engine/src/view/documentselection';
|
7 | import ViewElement from '@ckeditor/ckeditor5-engine/src/view/element';
|
8 | import ViewSelection from '@ckeditor/ckeditor5-engine/src/view/selection';
|
9 |
|
10 | export default class ImageUtils extends Plugin {
|
11 | static readonly pluginName: 'ImageUtils';
|
12 | /**
|
13 | * Checks if the provided model element is an `image` or `imageInline`.
|
14 | */
|
15 | isImage(modelElement: ModelElement): boolean;
|
16 |
|
17 | /**
|
18 | * Checks if the provided view element represents an inline image.
|
19 | *
|
20 | * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
|
21 | */
|
22 | isInlineImageView(element: ViewElement): boolean;
|
23 |
|
24 | /**
|
25 | * Checks if the provided view element represents a block image.
|
26 | *
|
27 | * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
|
28 | */
|
29 | isBlockImageView(element: ViewElement): boolean;
|
30 |
|
31 | /**
|
32 | * Handles inserting single file. This method unifies image insertion using {@link module:widget/utils~findOptimalInsertionRange}
|
33 | * method.
|
34 | *
|
35 | * editor.plugins.get( 'ImageUtils' );
|
36 | *
|
37 | * imageUtils.insertImage( { src: 'path/to/image.jpg' } );
|
38 | */
|
39 | insertImage(
|
40 | attributes?: Record<string, unknown>,
|
41 | selectable?: Selectable,
|
42 | imageType?: 'imageBlock' | 'imageInline',
|
43 | ): ViewElement | null;
|
44 |
|
45 | /**
|
46 | * Returns an image widget editing view element if one is selected or is among the selection's ancestors.
|
47 | */
|
48 | getClosestSelectedImageWidget(selection: ViewSelection | ViewDocumentSelection): ViewElement | null;
|
49 |
|
50 | /**
|
51 | * Returns a image model element if one is selected or is among the selection's ancestors.
|
52 | */
|
53 | getClosestSelectedImageElement(selection: Selection | DocumentSelection): Element | null;
|
54 |
|
55 | /**
|
56 | * Checks if image can be inserted at current model selection.
|
57 | */
|
58 | isImageAllowed(): boolean;
|
59 |
|
60 | /**
|
61 | * Converts a given {@link module:engine/view/element~Element} to an image widget:
|
62 | * * Adds a {@link module:engine/view/element~Element#_setCustomProperty custom property} allowing to recognize the image widget
|
63 | * element.
|
64 | * * Calls the {@link module:widget/utils~toWidget} function with the proper element's label creator.
|
65 | */
|
66 | toImageWidget(viewElement: ViewElement, writer: DowncastWriter, label: string): ViewElement;
|
67 |
|
68 | /**
|
69 | * Checks if a given view element is an image widget.
|
70 | */
|
71 | isImageWidget(viewElement: ViewElement): boolean;
|
72 |
|
73 | /**
|
74 | * Checks if the provided model element is an `image`.
|
75 | */
|
76 | isBlockImage(modelElement?: ModelElement | DocumentFragment | null): boolean;
|
77 |
|
78 | /**
|
79 | * Checks if the provided model element is an `imageInline`.
|
80 | */
|
81 | isInlineImage(modelElement?: ModelElement | null): boolean;
|
82 |
|
83 | /**
|
84 | * Get the view `<img>` from another view element, e.g. a widget (`<figure class="image">`), a link (`<a>`).
|
85 | *
|
86 | * The `<img>` can be located deep in other elements, so this helper performs a deep tree search.
|
87 | */
|
88 | findViewImgElement(figureView: ViewElement): ViewElement;
|
89 | }
|
90 |
|
91 | declare module '@ckeditor/ckeditor5-core/src/plugincollection' {
|
92 | interface Plugins {
|
93 | ImageUtils: ImageUtils;
|
94 | }
|
95 | }
|