UNPKG

2.79 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 media-embed/utils
7 */
8import type { ViewContainerElement, Element, Model, Selectable, Selection, DowncastWriter, ViewDocumentSelection, ViewElement, DocumentSelection } from 'ckeditor5/src/engine';
9import type MediaRegistry from './mediaregistry';
10/**
11 * Converts a given {@link module:engine/view/element~Element} to a media embed widget:
12 * * Adds a {@link module:engine/view/element~Element#_setCustomProperty custom property} allowing to recognize the media widget element.
13 * * Calls the {@link module:widget/utils~toWidget} function with the proper element's label creator.
14 *
15 * @param writer An instance of the view writer.
16 * @param label The element's label.
17 */
18export declare function toMediaWidget(viewElement: ViewElement, writer: DowncastWriter, label: string): ViewElement;
19/**
20 * Returns a media widget editing view element if one is selected.
21 */
22export declare function getSelectedMediaViewWidget(selection: ViewDocumentSelection): ViewElement | null;
23/**
24 * Checks if a given view element is a media widget.
25 */
26export declare function isMediaWidget(viewElement: ViewElement): boolean;
27/**
28 * Creates a view element representing the media. Either a "semantic" one for the data pipeline:
29 *
30 * ```html
31 * <figure class="media">
32 * <oembed url="foo"></oembed>
33 * </figure>
34 * ```
35 *
36 * or a "non-semantic" (for the editing view pipeline):
37 *
38 * ```html
39 * <figure class="media">
40 * <div data-oembed-url="foo">[ non-semantic media preview for "foo" ]</div>
41 * </figure>
42 * ```
43 */
44export declare function createMediaFigureElement(writer: DowncastWriter, registry: MediaRegistry, url: string, options: MediaOptions): ViewContainerElement;
45/**
46 * Returns a selected media element in the model, if any.
47 */
48export declare function getSelectedMediaModelWidget(selection: Selection | DocumentSelection): Element | null;
49/**
50 * Creates a media element and inserts it into the model.
51 *
52 * **Note**: This method will use {@link module:engine/model/model~Model#insertContent `model.insertContent()`} logic of inserting content
53 * if no `insertPosition` is passed.
54 *
55 * @param url An URL of an embeddable media.
56 * @param findOptimalPosition If true it will try to find optimal position to insert media without breaking content
57 * in which a selection is.
58 */
59export declare function insertMedia(model: Model, url: string, selectable: Selectable, findOptimalPosition: boolean): void;
60/**
61 * Type for commonly grouped function parameters across this package.
62 */
63export type MediaOptions = {
64 elementName: string;
65 renderMediaPreview?: boolean;
66 renderForEditingView?: boolean;
67};