UNPKG

1.72 kBTypeScriptView Raw
1/**
2 * @license Copyright (c) 2003-2023, 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/**
6 * @module image/autoimage
7 */
8import { Plugin, type Editor } from 'ckeditor5/src/core';
9import { Clipboard } from 'ckeditor5/src/clipboard';
10import { Undo } from 'ckeditor5/src/undo';
11import { Delete } from 'ckeditor5/src/typing';
12import ImageUtils from './imageutils';
13/**
14 * The auto-image plugin. It recognizes image links in the pasted content and embeds
15 * them shortly after they are injected into the document.
16 */
17export default class AutoImage extends Plugin {
18 /**
19 * @inheritDoc
20 */
21 static get requires(): readonly [typeof Clipboard, typeof ImageUtils, typeof Undo, typeof Delete];
22 /**
23 * @inheritDoc
24 */
25 static get pluginName(): "AutoImage";
26 /**
27 * The paste–to–embed `setTimeout` ID. Stored as a property to allow
28 * cleaning of the timeout.
29 */
30 private _timeoutId;
31 /**
32 * The position where the `<imageBlock>` element will be inserted after the timeout,
33 * determined each time a new content is pasted into the document.
34 */
35 private _positionToInsert;
36 /**
37 * @inheritDoc
38 */
39 constructor(editor: Editor);
40 /**
41 * @inheritDoc
42 */
43 init(): void;
44 /**
45 * Analyzes the part of the document between provided positions in search for a URL representing an image.
46 * When the URL is found, it is automatically converted into an image.
47 *
48 * @param leftPosition Left position of the selection.
49 * @param rightPosition Right position of the selection.
50 */
51 private _embedImageBetweenPositions;
52}