UNPKG

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