UNPKG

2.56 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/mediaregistry
7 */
8import type { DowncastWriter, ViewElement } from 'ckeditor5/src/engine';
9import { type Locale } from 'ckeditor5/src/utils';
10import type { MediaEmbedConfig, MediaEmbedProvider } from './mediaembedconfig';
11import type { MediaOptions } from './utils';
12/**
13 * A bridge between the raw media content provider definitions and the editor view content.
14 *
15 * It helps translating media URLs to corresponding {@link module:engine/view/element~Element view elements}.
16 *
17 * Mostly used by the {@link module:media-embed/mediaembedediting~MediaEmbedEditing} plugin.
18 */
19export default class MediaRegistry {
20 /**
21 * The {@link module:utils/locale~Locale} instance.
22 */
23 locale: Locale;
24 /**
25 * The media provider definitions available for the registry. Usually corresponding with the
26 * {@link module:media-embed/mediaembedconfig~MediaEmbedConfig media configuration}.
27 */
28 providerDefinitions: Array<MediaEmbedProvider>;
29 /**
30 * Creates an instance of the {@link module:media-embed/mediaregistry~MediaRegistry} class.
31 *
32 * @param locale The localization services instance.
33 * @param config The configuration of the media embed feature.
34 */
35 constructor(locale: Locale, config: MediaEmbedConfig);
36 /**
37 * Checks whether the passed URL is representing a certain media type allowed in the editor.
38 *
39 * @param url The URL to be checked
40 */
41 hasMedia(url: string): boolean;
42 /**
43 * For the given media URL string and options, it returns the {@link module:engine/view/element~Element view element}
44 * representing that media.
45 *
46 * **Note:** If no URL is specified, an empty view element is returned.
47 *
48 * @param writer The view writer used to produce a view element.
49 * @param url The URL to be translated into a view element.
50 */
51 getMediaViewElement(writer: DowncastWriter, url: string, options: MediaOptions): ViewElement;
52 /**
53 * Returns a `Media` instance for the given URL.
54 *
55 * @param url The URL of the media.
56 * @returns The `Media` instance or `null` when there is none.
57 */
58 private _getMedia;
59 /**
60 * Tries to match `url` to `pattern`.
61 *
62 * @param url The URL of the media.
63 * @param pattern The pattern that should accept the media URL.
64 */
65 private _getUrlMatches;
66}