import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-editor-types'; /** * An editor plugin that show a tooltip for existing link */ export default class HyperLink implements EditorPlugin { private getTooltipCallback; private target?; private onLinkClick?; private originalHref; private trackedLink; private editor; private disposer; /** * Create a new instance of HyperLink class * @param getTooltipCallback A callback function to get tooltip text for an existing hyperlink. * Default value is to return the href itself. If null, there will be no tooltip text. * @param target (Optional) Target window name for hyperlink. If null, will use "_blank" * @param onLinkClick (Optional) Open link callback (return false to use default behavior) */ constructor(getTooltipCallback?: (href: string, a: HTMLAnchorElement) => string, target?: string | undefined, onLinkClick?: ((anchor: HTMLAnchorElement, mouseEvent: MouseEvent) => boolean | void) | undefined); /** * Get a friendly name of this plugin */ getName(): string; /** * Initialize this plugin * @param editor The editor instance */ initialize(editor: IEditor): void; protected onMouse: (e: MouseEvent) => void; protected onBlur: (e: FocusEvent) => void; /** * Dispose this plugin */ dispose(): void; /** * Handle events triggered from editor * @param event PluginEvent object */ onPluginEvent(event: PluginEvent): void; /** * Try get href from an anchor element * The reason this is put in a try-catch is that * it has been seen that accessing href may throw an exception, in particular on IE/Edge */ private tryGetHref; /** * Determines if KeyboardEvent is meant to edit content */ private isContentEditValue; /** * Updates the href of the tracked link if the display text doesn't match href anymore */ private updateLinkHrefIfShouldUpdate; /** * Clears the tracked link and its original href value so that it's back to default state */ private resetLinkTracking; /** * Compares the normalized URL of inner text of element to its href to see if they match. */ private doesLinkDisplayMatchHref; /** * Update href of an element in place to new display text if it's a valid URL */ private updateLinkHref; }