All files / roosterjs-content-model-dom/lib/domUtils/hiddenProperties undeletableLink.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 2/2
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 251x     1x               1x 5x                 1x 51x    
import { getHiddenProperty, setHiddenProperty } from './hiddenProperty';
import type { HiddenProperty } from './hiddenProperty';
 
const UndeletableLinkKey: keyof HiddenProperty = 'undeletable';
 
/**
 * Set a hidden property on a link element to indicate whether it is undeletable or not.
 * This is used to prevent the link from being deleted when the user tries to delete it.
 * @param a The link element to set the property on
 * @param undeletable Whether the link is undeletable or not
 */
export function setLinkUndeletable(a: HTMLAnchorElement, undeletable: boolean) {
    setHiddenProperty(a, UndeletableLinkKey, undeletable);
}
 
/**
 * Check if a link element is undeletable or not.
 * This is used to determine if the link can be deleted when the user tries to delete it.
 * @param a The link element to check
 * @returns True if the link is undeletable, false otherwise
 */
export function isLinkUndeletable(a: HTMLAnchorElement): boolean {
    return !!getHiddenProperty(a, UndeletableLinkKey);
}