UNPKG

@redocly/theme

Version:

Shared UI components lib

26 lines (24 loc) 712 B
import copy from 'copy-to-clipboard'; export class ClipboardService { static copyCustom(text: string): boolean { return copy(text); } static selectElement(element: HTMLDivElement | null): void { if (!element) { return; } let range; let selection; if ((document.body as any).createTextRange) { range = (document.body as any).createTextRange(); range.moveToElementText(element); range.select(); } else if (document.createRange && window.getSelection) { selection = window.getSelection(); range = document.createRange(); range.selectNodeContents(element); selection?.removeAllRanges(); selection?.addRange(range); } } }