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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

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

86.67
/projects/igniteui-angular/src/lib/services/overlay/utilities.ts
1
import { AnimationReferenceMetadata } from '@angular/animations';
2
import { ComponentRef, ElementRef, Injector, NgZone } from '@angular/core';
3
import { CancelableBrowserEventArgs, CancelableEventArgs, cloneValue, IBaseEventArgs } from '../../core/utils';
4
import { IgxOverlayOutletDirective } from '../../directives/toggle/toggle.directive';
5
import { AnimationPlayer } from '../animation/animation';
6
import { IPositionStrategy } from './position/IPositionStrategy';
7
import { IScrollStrategy } from './scroll';
8

9
/* blazorAlternateName: GridHorizontalAlignment */
10
export enum HorizontalAlignment {
2✔
11
    Left = -1,
2✔
12
    Center = -0.5,
2✔
13
    Right = 0
2✔
14
}
15

16
/* blazorAlternateName: GridVerticalAlignment */
17
export enum VerticalAlignment {
2✔
18
    Top = -1,
2✔
19
    Middle = -0.5,
2✔
20
    Bottom = 0
2✔
21
}
22

23
/**
24
 * Defines the possible values of the overlays' position strategy.
25
 */
26
export enum RelativePositionStrategy {
2✔
27
    Connected = 'connected',
2✔
28
    Auto = 'auto',
2✔
29
    Elastic = 'elastic'
2✔
30
}
31

32
/**
33
 * Defines the possible positions for the relative overlay settings presets.
34
 */
35
export enum RelativePosition {
2✔
36
    Above = 'above',
2✔
37
    Below = 'below',
2✔
38
    Before = 'before',
2✔
39
    After = 'after',
2✔
40
    Default = 'default'
2✔
41
}
42

43
/**
44
 * Defines the possible positions for the absolute overlay settings presets.
45
 */
46
export enum AbsolutePosition {
2✔
47
    Bottom = 'bottom',
2✔
48
    Top = 'top',
2✔
49
    Center = 'center'
2✔
50
}
51

52
/**
53
 * Determines whether to add or set the offset values.
54
 */
55
export enum OffsetMode {
2✔
56
    Add,
2✔
57
    Set
2✔
58
}
59

60
// TODO: make this interface
61
export class Point {
62
    constructor(public x: number, public y: number) { }
39✔
63
}
64

65
/** @hidden */
66
export interface OutOfViewPort {
67
    /** Out of view port at Top or Left */
68
    back: number;
69
    /** Out of view port at Bottom or Right */
70
    forward: number;
71
}
72

73
export interface PositionSettings {
74
    /** Direction in which the component should show */
75
    horizontalDirection?: HorizontalAlignment;
76
    /** Direction in which the component should show */
77
    verticalDirection?: VerticalAlignment;
78
    /** Target's starting point */
79
    horizontalStartPoint?: HorizontalAlignment;
80
    /** Target's starting point */
81
    verticalStartPoint?: VerticalAlignment;
82
    /* blazorSuppress */
83
    /** Animation applied while overlay opens */
84
    openAnimation?: AnimationReferenceMetadata;
85
    /* blazorSuppress */
86
    /** Animation applied while overlay closes */
87
    closeAnimation?: AnimationReferenceMetadata;
88
    /** The size up to which element may shrink when shown in elastic position strategy */
89
    minSize?: Size;
90
}
91

92
export interface OverlaySettings {
93
    /** Attaching target for the component to show */
94
    target?: Point | HTMLElement;
95
    /** Position strategy to use with these settings */
96
    positionStrategy?: IPositionStrategy;
97
    /** Scroll strategy to use with these settings */
98
    scrollStrategy?: IScrollStrategy;
99
    /** Set if the overlay should be in modal mode */
100
    modal?: boolean;
101
    /** Set if the overlay should close on outside click */
102
    closeOnOutsideClick?: boolean;
103
    /** Set if the overlay should close when `Esc` key is pressed */
104
    closeOnEscape?: boolean;
105
    /* blazorSuppress */
106
    /** Set the outlet container to attach the overlay to */
107
    outlet?: IgxOverlayOutletDirective | ElementRef;
108
    /**
109
     * @hidden @internal
110
     * Elements to be excluded for closeOnOutsideClick.
111
     * Clicking on the elements in this collection will not close the overlay when closeOnOutsideClick = true.
112
     */
113
    excludeFromOutsideClick?: HTMLElement[];
114
}
115

116
export interface OverlayEventArgs extends IBaseEventArgs {
117
    /** Id of the overlay generated with `attach()` method */
118
    id: string;
119
    /** Available when `Type<T>` is provided to the `attach()` method and allows access to the created Component instance */
120
    componentRef?: ComponentRef<any>;
121
    /** Will provide the elementRef of the markup that will be displayed in the overlay */
122
    elementRef?: ElementRef<any>;
123
    /** Will provide the overlay settings which will be used when the component is attached */
124
    settings?: OverlaySettings;
125
    /** Will provide the original keyboard event if closed from ESC or click */
126
    event?: Event;
127
}
128

129
export interface OverlayCancelableEventArgs extends OverlayEventArgs, CancelableEventArgs {
130
}
131

132
export interface OverlayClosingEventArgs extends OverlayEventArgs, CancelableBrowserEventArgs {
133
}
134

135
export interface OverlayAnimationEventArgs extends IBaseEventArgs {
136
    /** Id of the overlay generated with `attach()` method */
137
    id: string;
138
    /** Animation player that will play the animation */
139
    animationPlayer: AnimationPlayer;
140
    /** Type of animation to be played. It should be either 'open' or 'close' */
141
    animationType: 'open' | 'close';
142
}
143

144
export interface Size {
145
    /** Gets or sets the horizontal component of Size */
146
    width: number;
147

148
    /** Gets or sets the vertical component of Size */
149
    height: number;
150
}
151

152
/** @hidden */
153
export interface OverlayInfo {
154
    id?: string;
155
    visible?: boolean;
156
    detached?: boolean;
157
    elementRef?: ElementRef;
158
    componentRef?: ComponentRef<any>;
159
    settings?: OverlaySettings;
160
    initialSize?: Size;
161
    hook?: HTMLElement;
162
    openAnimationPlayer?: AnimationPlayer;
163
    // calling animation.destroy in detach fires animation.done. This should not happen
164
    // this is why we should trace if animation ever started
165
    openAnimationDetaching?: boolean;
166
    closeAnimationPlayer?: AnimationPlayer;
167
    // calling animation.destroy in detach fires animation.done. This should not happen
168
    // this is why we should trace if animation ever started
169
    closeAnimationDetaching?: boolean;
170
    ngZone: NgZone;
171
    transformX?: number;
172
    transformY?: number;
173
    event?: Event;
174
    wrapperElement?: HTMLElement;
175
    size?: string
176
}
177

178
/** @hidden */
179
export interface ConnectedFit {
180
    contentElementRect?: Partial<DOMRect>;
181
    targetRect?: Partial<DOMRect>;
182
    viewPortRect?: Partial<DOMRect>;
183
    fitHorizontal?: OutOfViewPort;
184
    fitVertical?: OutOfViewPort;
185
    left?: number;
186
    right?: number;
187
    top?: number;
188
    bottom?: number;
189
    horizontalOffset?: number;
190
    verticalOffset?: number;
191
}
192

193
export interface OverlayCreateSettings extends OverlaySettings {
194
    /**
195
     * An `Injector` instance to add in the created component ref's injectors tree.
196
     */
197
    injector?: Injector
198
}
199

200
/** @hidden @internal */
201
export class Util {
202
    /**
203
     * Calculates the rectangle of target for provided overlay settings. Defaults to 0,0,0,0,0,0 rectangle
204
     * if no target is provided
205
     *
206
     * @param settings Overlay settings for which to calculate target rectangle
207
     */
208
    public static getTargetRect(target?: Point | HTMLElement): Partial<DOMRect> {
209
        let targetRect: Partial<DOMRect> = {
78✔
210
            bottom: 0,
211
            height: 0,
212
            left: 0,
213
            right: 0,
214
            top: 0,
215
            width: 0
216
        };
217
        if (target instanceof HTMLElement) {
78!
218
            targetRect = (target as HTMLElement).getBoundingClientRect();
78✔
UNCOV
219
        } else if (target instanceof Point) {
×
UNCOV
220
            const targetPoint = target as Point;
×
UNCOV
221
            targetRect = {
×
222
                bottom: targetPoint.y,
223
                height: 0,
224
                left: targetPoint.x,
225
                right: targetPoint.x,
226
                top: targetPoint.y,
227
                width: 0
228
            };
229
        }
230
        return targetRect;
78✔
231
    }
232

233
    public static getViewportRect(document: Document): Partial<DOMRect> {
234
        const width = document.documentElement.clientWidth;
39✔
235
        const height = document.documentElement.clientHeight;
39✔
236
        const scrollPosition = Util.getViewportScrollPosition(document);
39✔
237

238
        return {
39✔
239
            top: scrollPosition.y,
240
            left: scrollPosition.x,
241
            right: scrollPosition.x + width,
242
            bottom: scrollPosition.y + height,
243
            width,
244
            height,
245
        };
246
    }
247

248
    public static getViewportScrollPosition(document: Document): Point {
249
        const documentElement = document.documentElement;
39✔
250
        const documentRect = documentElement.getBoundingClientRect();
39✔
251

252
        const horizontalScrollPosition =
253
            -documentRect.left || document.body.scrollLeft || window.scrollX || documentElement.scrollLeft || 0;
39✔
254
        const verticalScrollPosition = -documentRect.top || document.body.scrollTop || window.scrollY || documentElement.scrollTop || 0;
39✔
255

256
        return new Point(horizontalScrollPosition, verticalScrollPosition);
39✔
257
    }
258

259
    public static cloneInstance(object) {
UNCOV
260
        const clonedObj = Object.assign(Object.create(Object.getPrototypeOf(object)), object);
×
UNCOV
261
        clonedObj.settings = cloneValue(clonedObj.settings);
×
UNCOV
262
        return clonedObj;
×
263
    }
264
}
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