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

atinc / ngx-tethys / 68ef226c-f83e-44c1-b8ed-e420a83c5d84

28 May 2025 10:31AM UTC coverage: 10.352% (-80.0%) from 90.316%
68ef226c-f83e-44c1-b8ed-e420a83c5d84

Pull #3460

circleci

pubuzhixing8
chore: xxx
Pull Request #3460: refactor(icon): migrate signal input #TINFR-1476

132 of 6823 branches covered (1.93%)

Branch coverage included in aggregate %.

10 of 14 new or added lines in 1 file covered. (71.43%)

11648 existing lines in 344 files now uncovered.

2078 of 14525 relevant lines covered (14.31%)

6.69 hits per line

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

6.38
/src/copy/copy.directive.ts
1
import { Directive, ElementRef, HostListener, OnDestroy, OnInit, Signal, inject, input, output } from '@angular/core';
2
import { DOCUMENT } from '@angular/common';
3
import { coerceElement } from '@angular/cdk/coercion';
4
import { ThyNotifyService } from 'ngx-tethys/notify';
5
import { ThyTooltipDirective } from 'ngx-tethys/tooltip';
6
import { coerceBooleanProperty } from 'ngx-tethys/util';
7
import { injectLocale, ThyCopyLocale } from 'ngx-tethys/i18n';
8

9
export interface ThyCopyEvent {
10
    isSuccess: boolean;
11
    event: Event;
12
}
13

1✔
14
/**
UNCOV
15
 * @name thyCopy
×
UNCOV
16
 */
×
UNCOV
17
@Directive({
×
UNCOV
18
    selector: '[thyCopy]',
×
UNCOV
19
    hostDirectives: [ThyTooltipDirective]
×
UNCOV
20
})
×
UNCOV
21
export class ThyCopyDirective implements OnInit, OnDestroy {
×
UNCOV
22
    private document = inject(DOCUMENT);
×
UNCOV
23
    tooltipDirective = inject(ThyTooltipDirective);
×
UNCOV
24
    private notifyService = inject(ThyNotifyService);
×
25
    private locale: Signal<ThyCopyLocale> = injectLocale('copy');
26

UNCOV
27
    /**
×
UNCOV
28
     * 默认为点击标签,可传复制目标标签
×
UNCOV
29
     */
×
30
    readonly thyCopy = output<ThyCopyEvent>();
31

UNCOV
32
    /**
×
UNCOV
33
     * 复制成功时的文案
×
UNCOV
34
     */
×
35
    readonly thyCopySuccessText = input<string>(this.locale().success);
36

37
    /**
×
38
     * 提示文案
×
39
     */
40
    readonly thyCopyTips = input<string>(this.locale().tips);
41

UNCOV
42
    /**
×
UNCOV
43
     * 偏移量
×
UNCOV
44
     */
×
UNCOV
45
    readonly thyCopyTipsOffset = input<number>(undefined);
×
UNCOV
46

×
UNCOV
47
    /**
×
UNCOV
48
     * 当为 string 时,复制的是传入的内容;当为 ElementRef | HTMLElement 时,复制的是 dom 节点的 value 或者 textContent
×
UNCOV
49
     */
×
UNCOV
50
    readonly thyCopyContent = input<string | ElementRef | HTMLElement>(undefined);
×
51

52
    /**
53
     * 是否展示通知
54
     */
×
55
    readonly thyShowNotify = input(true, { transform: coerceBooleanProperty });
×
56

×
57
    ngOnInit() {
58
        const thyCopyTips = this.thyCopyTips();
59
        this.tooltipDirective.content = thyCopyTips ? thyCopyTips : this.locale().tips;
UNCOV
60
        this.tooltipDirective.tooltipOffset = this.thyCopyTipsOffset();
×
61
    }
62

63
    private getContent(event: Event) {
UNCOV
64
        const thyCopyContent = this.thyCopyContent();
×
65
        if (typeof thyCopyContent === 'string') {
66
            return thyCopyContent;
1✔
67
        } else {
68
            const target = thyCopyContent ? coerceElement(thyCopyContent) : event.target;
69
            return target.value || target.textContent;
70
        }
71
    }
72

73
    @HostListener('click', ['$event'])
74
    public onClick(event: Event) {
75
        const textarea = this.document.createElement('textarea');
76
        this.document.body.appendChild(textarea);
1✔
77
        textarea.value = this.getContent(event);
78
        textarea.select();
79
        try {
80
            document.execCommand('copy', false, null);
81
            this.thyCopy.emit({ isSuccess: true, event });
82
            if (this.thyShowNotify()) {
83
                this.notifyService.success(this.thyCopySuccessText());
84
            }
85
        } catch (err) {
86
            this.thyCopy.emit({ isSuccess: false, event });
87
            if (this.thyShowNotify()) {
88
                this.notifyService.error(this.locale().error);
89
            }
90
        } finally {
91
            textarea.remove();
92
        }
93
    }
94

95
    ngOnDestroy() {
96
        this.tooltipDirective.hide();
97
    }
98
}
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