UNPKG

3.81 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 link/utils
7 */
8import type { DowncastConversionApi, Element, Schema, ViewAttributeElement, ViewNode, ViewDocumentFragment } from 'ckeditor5/src/engine';
9import type { LocaleTranslate } from 'ckeditor5/src/utils';
10import type { LinkDecoratorAutomaticDefinition, LinkDecoratorDefinition, LinkDecoratorManualDefinition } from './linkconfig';
11/**
12 * A keystroke used by the {@link module:link/linkui~LinkUI link UI feature}.
13 */
14export declare const LINK_KEYSTROKE = "Ctrl+K";
15/**
16 * Returns `true` if a given view node is the link element.
17 */
18export declare function isLinkElement(node: ViewNode | ViewDocumentFragment): boolean;
19/**
20 * Creates a link {@link module:engine/view/attributeelement~AttributeElement} with the provided `href` attribute.
21 */
22export declare function createLinkElement(href: string, { writer }: DowncastConversionApi): ViewAttributeElement;
23/**
24 * Returns a safe URL based on a given value.
25 *
26 * A URL is considered safe if it is safe for the user (does not contain any malicious code).
27 *
28 * If a URL is considered unsafe, a simple `"#"` is returned.
29 *
30 * @internal
31 */
32export declare function ensureSafeUrl(url: unknown): string;
33/**
34 * Returns the {@link module:link/linkconfig~LinkConfig#decorators `config.link.decorators`} configuration processed
35 * to respect the locale of the editor, i.e. to display the {@link module:link/linkconfig~LinkDecoratorManualDefinition label}
36 * in the correct language.
37 *
38 * **Note**: Only the few most commonly used labels are translated automatically. Other labels should be manually
39 * translated in the {@link module:link/linkconfig~LinkConfig#decorators `config.link.decorators`} configuration.
40 *
41 * @param t Shorthand for {@link module:utils/locale~Locale#t Locale#t}.
42 * @param decorators The decorator reference where the label values should be localized.
43 */
44export declare function getLocalizedDecorators(t: LocaleTranslate, decorators: Array<NormalizedLinkDecoratorDefinition>): Array<NormalizedLinkDecoratorDefinition>;
45/**
46 * Converts an object with defined decorators to a normalized array of decorators. The `id` key is added for each decorator and
47 * is used as the attribute's name in the model.
48 */
49export declare function normalizeDecorators(decorators?: Record<string, LinkDecoratorDefinition>): Array<NormalizedLinkDecoratorDefinition>;
50/**
51 * Returns `true` if the specified `element` can be linked (the element allows the `linkHref` attribute).
52 */
53export declare function isLinkableElement(element: Element | null, schema: Schema): element is Element;
54/**
55 * Returns `true` if the specified `value` is an email.
56 */
57export declare function isEmail(value: string): boolean;
58/**
59 * Adds the protocol prefix to the specified `link` when:
60 *
61 * * it does not contain it already, and there is a {@link module:link/linkconfig~LinkConfig#defaultProtocol `defaultProtocol` }
62 * configuration value provided,
63 * * or the link is an email address.
64 */
65export declare function addLinkProtocolIfApplicable(link: string, defaultProtocol?: string): string;
66/**
67 * Checks if protocol is already included in the link.
68 */
69export declare function linkHasProtocol(link: string): boolean;
70/**
71 * Opens the link in a new browser tab.
72 */
73export declare function openLink(link: string): void;
74export type NormalizedLinkDecoratorAutomaticDefinition = LinkDecoratorAutomaticDefinition & {
75 id: string;
76};
77export type NormalizedLinkDecoratorManualDefinition = LinkDecoratorManualDefinition & {
78 id: string;
79};
80export type NormalizedLinkDecoratorDefinition = NormalizedLinkDecoratorAutomaticDefinition | NormalizedLinkDecoratorManualDefinition;