• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

worktile / slate-angular / 32069b32-d7ed-429e-b45b-877770d4e8e1

04 Sep 2025 07:26AM UTC coverage: 47.486%. Remained the same
32069b32-d7ed-429e-b45b-877770d4e8e1

push

circleci

pubuzhixing8
build: release 19.1.2

360 of 938 branches covered (38.38%)

Branch coverage included in aggregate %.

934 of 1787 relevant lines covered (52.27%)

44.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.35
/packages/src/utils/clipboard/navigator-clipboard.ts
1
import { Element } from 'slate';
2
import { getClipboardFromHTMLText } from './clipboard';
3
import { blobAsString, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, stripHtml } from './common';
4
import { ClipboardData } from '../../types/clipboard';
5

6
export const setNavigatorClipboard = async (htmlText: string, data: Element[], text: string = '') => {
1!
7
    let textClipboard = text;
×
8
    if (isClipboardWriteSupported()) {
×
9
        await navigator.clipboard.write([
×
10
            new ClipboardItem({
11
                'text/html': new Blob([htmlText], {
12
                    type: 'text/html'
13
                }),
14
                'text/plain': new Blob([textClipboard ?? JSON.stringify(data)], { type: 'text/plain' })
×
15
            })
16
        ]);
17
    }
18
};
19

20
export const getNavigatorClipboard = async () => {
1✔
21
    if (!isClipboardReadSupported()) {
×
22
        return null;
×
23
    }
24
    const clipboardItems = await navigator.clipboard.read();
×
25
    let clipboardData: ClipboardData = {};
×
26

27
    if (Array.isArray(clipboardItems) && clipboardItems[0] instanceof ClipboardItem) {
×
28
        for (const item of clipboardItems) {
×
29
            if (isClipboardFile(item)) {
×
30
                const clipboardFiles = item.types.filter(type => type.match(/^image\//));
×
31
                const fileBlobs = await Promise.all(clipboardFiles.map(type => item.getType(type)!));
×
32
                const urls = (fileBlobs.filter(Boolean) as (File | Blob)[]).map(blob => URL.createObjectURL(blob));
×
33
                const files = await Promise.all(
×
34
                    urls.map(async url => {
35
                        const blob = await (await fetch(url)).blob();
×
36
                        return new File([blob], 'file', { type: blob.type });
×
37
                    })
38
                );
39
                clipboardData = {
×
40
                    ...clipboardData,
41
                    files
42
                };
43
            }
44
            if (item.types.includes('text/html')) {
×
45
                const htmlContent = await blobAsString(await item.getType('text/html'));
×
46
                const htmlClipboardData = getClipboardFromHTMLText(htmlContent);
×
47
                if (htmlClipboardData) {
×
48
                    clipboardData = { ...clipboardData, ...htmlClipboardData };
×
49
                    return clipboardData;
×
50
                }
51
                if (htmlContent && htmlContent.trim()) {
×
52
                    clipboardData = { ...clipboardData, html: htmlContent };
×
53
                }
54
            }
55
            if (item.types.includes('text/plain')) {
×
56
                const textContent = await blobAsString(await item.getType('text/plain'));
×
57
                clipboardData = {
×
58
                    ...clipboardData,
59
                    text: stripHtml(textContent)
60
                };
61
            }
62
        }
63
    }
64
    return clipboardData;
×
65
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc